From 166fea27db972f6a154fee9f617aa221f575e6b0 Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Sun, 12 Jan 2025 15:09:18 +0900 Subject: [PATCH] fix: update response objects Signed-off-by: namkyu1999 --- chaoscenter/authentication/DOC_SETUP.md | 2 +- chaoscenter/authentication/api/docs/docs.go | 388 +++- .../authentication/api/docs/swagger.json | 1903 +++++++++++++++++ .../authentication/api/docs/swagger.yaml | 1255 +++++++++++ .../authentication/api/handlers/doc.go | 55 +- .../api/handlers/rest/misc_handlers.go | 21 +- .../api/handlers/rest/project_handler.go | 105 +- .../api/handlers/rest/user_handlers.go | 29 +- .../authentication/pkg/entities/user.go | 5 - 9 files changed, 3642 insertions(+), 121 deletions(-) create mode 100644 chaoscenter/authentication/api/docs/swagger.json create mode 100644 chaoscenter/authentication/api/docs/swagger.yaml diff --git a/chaoscenter/authentication/DOC_SETUP.md b/chaoscenter/authentication/DOC_SETUP.md index e1b0b495859..81b383e63bc 100644 --- a/chaoscenter/authentication/DOC_SETUP.md +++ b/chaoscenter/authentication/DOC_SETUP.md @@ -97,7 +97,7 @@ type ErrServerError struct { After annotating your API and defining your responses, run the following command in your project root to generate the `swagger.yaml` file: ```bash -swag init +swag init --parseDependency true ``` This command scans your project and creates a Swagger specification from your annotations. diff --git a/chaoscenter/authentication/api/docs/docs.go b/chaoscenter/authentication/api/docs/docs.go index 122a3efb1f4..0662e349166 100644 --- a/chaoscenter/authentication/api/docs/docs.go +++ b/chaoscenter/authentication/api/docs/docs.go @@ -32,7 +32,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -102,7 +102,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Project" } }, "500": { @@ -205,7 +205,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -245,7 +245,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -336,7 +336,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Projects" } }, "400": { @@ -386,7 +386,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Project" } }, "401": { @@ -430,7 +430,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Members" } }, "500": { @@ -468,7 +468,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Members" } }, "500": { @@ -506,7 +506,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.ProjectRole" } }, "400": { @@ -541,7 +541,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.ProjectStats" } }, "500": { @@ -607,7 +607,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.UserWithProject" } }, "400": { @@ -682,7 +682,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -732,7 +732,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.ListInvitationResponse" } }, "500": { @@ -761,7 +761,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.ListProjectResponse" } }, "500": { @@ -863,7 +863,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.ReadinessAPIStatus" } }, "500": { @@ -892,7 +892,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -1007,7 +1007,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.Member" } }, "400": { @@ -1047,7 +1047,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.APIStatus" } }, "500": { @@ -1143,7 +1143,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.MessageResponse" + "$ref": "#/definitions/response.ProjectIDWithMessage" } }, "400": { @@ -1212,7 +1212,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -1253,7 +1253,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/response.Response" + "$ref": "#/definitions/response.MessageResponse" } }, "400": { @@ -1313,6 +1313,246 @@ const docTemplate = `{ } }, "definitions": { + "entities.Invitation": { + "type": "string", + "enum": [ + "Pending", + "Accepted", + "Declined", + "Exited" + ], + "x-enum-varnames": [ + "PendingInvitation", + "AcceptedInvitation", + "DeclinedInvitation", + "ExitedProject" + ] + }, + "entities.ListInvitationResponse": { + "type": "object", + "properties": { + "invitationRole": { + "$ref": "#/definitions/entities.MemberRole" + }, + "projectID": { + "type": "string" + }, + "projectName": { + "type": "string" + }, + "projectOwner": { + "$ref": "#/definitions/entities.Member" + } + } + }, + "entities.ListProjectResponse": { + "type": "object", + "properties": { + "projects": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + }, + "totalNumberOfProjects": { + "type": "integer" + } + } + }, + "entities.Member": { + "type": "object", + "properties": { + "deactivatedAt": { + "type": "integer" + }, + "email": { + "type": "string" + }, + "invitation": { + "$ref": "#/definitions/entities.Invitation" + }, + "joinedAt": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "role": { + "$ref": "#/definitions/entities.MemberRole" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.MemberRole": { + "type": "string", + "enum": [ + "Owner", + "Executor", + "Viewer" + ], + "x-enum-varnames": [ + "RoleOwner", + "RoleExecutor", + "RoleViewer" + ] + }, + "entities.MemberStat": { + "type": "object", + "properties": { + "owner": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Owner" + } + }, + "total": { + "type": "integer" + } + } + }, + "entities.Owner": { + "type": "object", + "properties": { + "deactivatedAt": { + "type": "integer" + }, + "invitation": { + "$ref": "#/definitions/entities.Invitation" + }, + "joinedAt": { + "type": "integer" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.Project": { + "type": "object", + "properties": { + "createdAt": { + "type": "integer" + }, + "createdBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "description": { + "type": "string" + }, + "isRemoved": { + "type": "boolean" + }, + "members": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Member" + } + }, + "name": { + "type": "string" + }, + "projectID": { + "type": "string" + }, + "state": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "updatedAt": { + "type": "integer" + }, + "updatedBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + } + } + }, + "entities.ProjectStats": { + "type": "object", + "properties": { + "members": { + "$ref": "#/definitions/entities.MemberStat" + }, + "name": { + "type": "string" + }, + "projectID": { + "type": "string" + } + } + }, + "entities.UserDetailResponse": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.UserWithProject": { + "type": "object", + "properties": { + "createdAt": { + "type": "integer" + }, + "createdBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "email": { + "type": "string" + }, + "id": { + "type": "string" + }, + "isRemoved": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "projects": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + }, + "updatedAt": { + "type": "integer" + }, + "updatedBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "username": { + "type": "string" + } + } + }, + "response.APIStatus": { + "type": "object", + "properties": { + "status": { + "type": "string" + } + } + }, "response.ApiTokenResponse": { "type": "object", "properties": { @@ -1515,9 +1755,47 @@ const docTemplate = `{ } } }, + "response.ListInvitationResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.ListInvitationResponse" + } + } + } + }, + "response.ListProjectResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.ListProjectResponse" + } + } + }, "response.LoginResponse": { "type": "object" }, + "response.Member": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.Member" + } + } + }, + "response.Members": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Member" + } + } + } + }, "response.MessageResponse": { "type": "object", "properties": { @@ -1529,6 +1807,66 @@ const docTemplate = `{ "response.NewApiToken": { "type": "object" }, + "response.Project": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.Project" + } + } + }, + "response.ProjectIDWithMessage": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "projectID": { + "type": "string" + } + } + }, + "response.ProjectRole": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + }, + "response.ProjectStats": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.ProjectStats" + } + } + } + }, + "response.Projects": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + } + } + }, + "response.ReadinessAPIStatus": { + "type": "object", + "properties": { + "collections": { + "type": "string" + }, + "database": { + "type": "string" + } + } + }, "response.Response": { "type": "object", "properties": { @@ -1562,6 +1900,14 @@ const docTemplate = `{ "type": "string" } } + }, + "response.UserWithProject": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.UserWithProject" + } + } } } }` diff --git a/chaoscenter/authentication/api/docs/swagger.json b/chaoscenter/authentication/api/docs/swagger.json new file mode 100644 index 00000000000..63889c67e2c --- /dev/null +++ b/chaoscenter/authentication/api/docs/swagger.json @@ -0,0 +1,1903 @@ +{ + "swagger": "2.0", + "info": { + "title": "Chaoscenter API documentation", + "contact": {} + }, + "paths": { + "/accept_invitation": { + "post": { + "description": "Accept invitation to a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Accept invitation.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/capabilities": { + "get": { + "description": "Returns capabilities that can be leveraged by frontend services to toggle certain features.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "CapabilitiesRouter" + ], + "summary": "Get capabilities of Auth Server.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.CapabilitiesResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/create_project": { + "post": { + "description": "Create a new project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Create project.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Project" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/create_token": { + "post": { + "description": "Creates a new api token for the user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.NewApiToken" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrUserNotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/create_user": { + "post": { + "description": "Create new user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidEmail" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUserExists" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/decline_invitation": { + "post": { + "description": "Decline invitation to a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Decline invitation.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/delete_project/:project_id": { + "post": { + "description": "Delete a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrProjectNotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/dex/callback": { + "get": { + "description": "DexRouter creates all the required routes for OAuth purposes. .", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DexRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/dex/login": { + "get": { + "description": "DexRouter creates all the required routes for OAuth purposes. .", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DexRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_owner_projects": { + "get": { + "description": "Return owner of projects.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get projects owner.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Projects" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_project/:project_id": { + "get": { + "description": "Return a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get user with project.", + "parameters": [ + { + "type": "string", + "description": "Project ID", + "name": "project_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Project" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_project_members/:project_id/:state": { + "get": { + "description": "Return list of active project members.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get active project members.", + "parameters": [ + { + "type": "string", + "description": "State", + "name": "state", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Members" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_project_owners/:project_id/:state": { + "get": { + "description": "Return list of active project owners.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get active project Owners.", + "parameters": [ + { + "type": "string", + "description": "State", + "name": "state", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Members" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_project_role/:project_id": { + "get": { + "description": "Return role of a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get project Role.", + "parameters": [ + { + "type": "integer", + "description": "Project ID", + "name": "project_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ProjectRole" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrProjectNotFound" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_projects_stats": { + "get": { + "description": "Return stats of a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get stats of a project.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ProjectStats" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/get_user/:uid": { + "get": { + "description": "Get user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrUserNotFound" + } + } + } + } + }, + "/get_user_with_project/:username": { + "get": { + "description": "Return users who have a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get user with project.", + "parameters": [ + { + "type": "string", + "description": "Username", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.UserWithProject" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrUserNotFound" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/invite_users/:project_id": { + "get": { + "description": "Invite users.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.UserResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/leave_project": { + "post": { + "description": "Leave project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Leave project.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/list_invitations_with_filters/:invitation_state": { + "get": { + "description": "Return list of invitations.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "List invitations.", + "parameters": [ + { + "type": "string", + "description": "Invitation State", + "name": "invitation_state", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ListInvitationResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/list_projects": { + "get": { + "description": "Return stats of a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Get stats of a project.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ListProjectResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/login": { + "post": { + "description": "User Login.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.LoginResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrUserDeactivated" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrInvalidCredentials" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/logout": { + "post": { + "description": "Revokes the token passed in the Authorization header.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/readiness": { + "get": { + "description": "Return list of tags.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MiscRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ReadinessAPIStatus" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/remove_invitation": { + "post": { + "description": "Remove invitation of a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Remove invitation.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/remove_token": { + "post": { + "description": "Delete api token for the user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/reset/password": { + "post": { + "description": "Reset user password.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrStrictPasswordPolicyViolation" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/send_invitation": { + "post": { + "description": "Send invitation to a project.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Send invitation.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Member" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrUserNotFound" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/status": { + "get": { + "description": "Status will request users list and return, if successful, a http code 200.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "MiscRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.APIStatus" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/token/:uid": { + "post": { + "description": "Returns all the api tokens for the user.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ApiTokenResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/update/details": { + "post": { + "description": "Update users details.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrStrictUsernamePolicyViolation" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/update/password": { + "post": { + "description": "Update user password.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.ProjectIDWithMessage" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrOldPassword" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrInvalidCredentials" + } + } + } + } + }, + "/update/state": { + "post": { + "description": "Updates the user state.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + } + } + } + }, + "/update_member_role": { + "post": { + "description": "Return updated member role.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Update member role.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/update_project_name": { + "post": { + "description": "Return updated project name.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ProjectRouter" + ], + "summary": "Update project name.", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.MessageResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/response.ErrInvalidRequest" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + }, + "/users": { + "get": { + "description": "Fetch users.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "UserRouter" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.UserResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/response.ErrUnauthorized" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.ErrServerError" + } + } + } + } + } + }, + "definitions": { + "entities.Invitation": { + "type": "string", + "enum": [ + "Pending", + "Accepted", + "Declined", + "Exited" + ], + "x-enum-varnames": [ + "PendingInvitation", + "AcceptedInvitation", + "DeclinedInvitation", + "ExitedProject" + ] + }, + "entities.ListInvitationResponse": { + "type": "object", + "properties": { + "invitationRole": { + "$ref": "#/definitions/entities.MemberRole" + }, + "projectID": { + "type": "string" + }, + "projectName": { + "type": "string" + }, + "projectOwner": { + "$ref": "#/definitions/entities.Member" + } + } + }, + "entities.ListProjectResponse": { + "type": "object", + "properties": { + "projects": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + }, + "totalNumberOfProjects": { + "type": "integer" + } + } + }, + "entities.Member": { + "type": "object", + "properties": { + "deactivatedAt": { + "type": "integer" + }, + "email": { + "type": "string" + }, + "invitation": { + "$ref": "#/definitions/entities.Invitation" + }, + "joinedAt": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "role": { + "$ref": "#/definitions/entities.MemberRole" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.MemberRole": { + "type": "string", + "enum": [ + "Owner", + "Executor", + "Viewer" + ], + "x-enum-varnames": [ + "RoleOwner", + "RoleExecutor", + "RoleViewer" + ] + }, + "entities.MemberStat": { + "type": "object", + "properties": { + "owner": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Owner" + } + }, + "total": { + "type": "integer" + } + } + }, + "entities.Owner": { + "type": "object", + "properties": { + "deactivatedAt": { + "type": "integer" + }, + "invitation": { + "$ref": "#/definitions/entities.Invitation" + }, + "joinedAt": { + "type": "integer" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.Project": { + "type": "object", + "properties": { + "createdAt": { + "type": "integer" + }, + "createdBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "description": { + "type": "string" + }, + "isRemoved": { + "type": "boolean" + }, + "members": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Member" + } + }, + "name": { + "type": "string" + }, + "projectID": { + "type": "string" + }, + "state": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "updatedAt": { + "type": "integer" + }, + "updatedBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + } + } + }, + "entities.ProjectStats": { + "type": "object", + "properties": { + "members": { + "$ref": "#/definitions/entities.MemberStat" + }, + "name": { + "type": "string" + }, + "projectID": { + "type": "string" + } + } + }, + "entities.UserDetailResponse": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "entities.UserWithProject": { + "type": "object", + "properties": { + "createdAt": { + "type": "integer" + }, + "createdBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "email": { + "type": "string" + }, + "id": { + "type": "string" + }, + "isRemoved": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "projects": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + }, + "updatedAt": { + "type": "integer" + }, + "updatedBy": { + "$ref": "#/definitions/entities.UserDetailResponse" + }, + "username": { + "type": "string" + } + } + }, + "response.APIStatus": { + "type": "object", + "properties": { + "status": { + "type": "string" + } + } + }, + "response.ApiTokenResponse": { + "type": "object", + "properties": { + "createdAt": { + "type": "integer" + }, + "expiresAt": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "token": { + "type": "string" + }, + "userID": { + "type": "string" + } + } + }, + "response.CapabilitiesResponse": { + "type": "object", + "properties": { + "dex": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + } + } + } + } + }, + "response.ErrInvalidCredentials": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 401 + }, + "message": { + "type": "string", + "example": "Invalid Credentials" + } + } + }, + "response.ErrInvalidEmail": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "Email address is invalid" + } + } + }, + "response.ErrInvalidRequest": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed" + } + } + }, + "response.ErrInvalidRole": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "Role is invalid" + } + } + }, + "response.ErrOldPassword": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "The old and new passwords can't be same" + } + } + }, + "response.ErrProjectNotFound": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "This project does not exist" + } + } + }, + "response.ErrServerError": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 500 + }, + "message": { + "type": "string", + "example": "The authorization server encountered an unexpected condition that prevented it from fulfilling the request" + } + } + }, + "response.ErrStrictPasswordPolicyViolation": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 401 + }, + "message": { + "type": "string", + "example": "Please ensure the password is atleast 8 characters and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character" + } + } + }, + "response.ErrStrictUsernamePolicyViolation": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 401 + }, + "message": { + "type": "string", + "example": "The username should be atleast 3 characters long and atmost 16 characters long." + } + } + }, + "response.ErrUnauthorized": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 401 + }, + "message": { + "type": "string", + "example": "The user does not have requested authorization to access this resource" + } + } + }, + "response.ErrUserDeactivated": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "your account has been deactivated" + } + } + }, + "response.ErrUserExists": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 401 + }, + "message": { + "type": "string", + "example": "This username is already assigned to another user" + } + } + }, + "response.ErrUserNotFound": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "user does not exist" + } + } + }, + "response.ListInvitationResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.ListInvitationResponse" + } + } + } + }, + "response.ListProjectResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.ListProjectResponse" + } + } + }, + "response.LoginResponse": { + "type": "object" + }, + "response.Member": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.Member" + } + } + }, + "response.Members": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Member" + } + } + } + }, + "response.MessageResponse": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + }, + "response.NewApiToken": { + "type": "object" + }, + "response.Project": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.Project" + } + } + }, + "response.ProjectIDWithMessage": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "projectID": { + "type": "string" + } + } + }, + "response.ProjectRole": { + "type": "object", + "properties": { + "role": { + "type": "string" + } + } + }, + "response.ProjectStats": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.ProjectStats" + } + } + } + }, + "response.Projects": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/entities.Project" + } + } + } + }, + "response.ReadinessAPIStatus": { + "type": "object", + "properties": { + "collections": { + "type": "string" + }, + "database": { + "type": "string" + } + } + }, + "response.Response": { + "type": "object", + "properties": { + "response": { + "type": "string" + } + } + }, + "response.UserResponse": { + "type": "object", + "properties": { + "deactivatedAt": { + "type": "integer" + }, + "email": { + "type": "string" + }, + "name": { + "type": "string" + }, + "password": { + "type": "string" + }, + "role": { + "type": "string" + }, + "userID": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "response.UserWithProject": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/entities.UserWithProject" + } + } + } + } +} \ No newline at end of file diff --git a/chaoscenter/authentication/api/docs/swagger.yaml b/chaoscenter/authentication/api/docs/swagger.yaml new file mode 100644 index 00000000000..eea09683a51 --- /dev/null +++ b/chaoscenter/authentication/api/docs/swagger.yaml @@ -0,0 +1,1255 @@ +definitions: + entities.Invitation: + enum: + - Pending + - Accepted + - Declined + - Exited + type: string + x-enum-varnames: + - PendingInvitation + - AcceptedInvitation + - DeclinedInvitation + - ExitedProject + entities.ListInvitationResponse: + properties: + invitationRole: + $ref: '#/definitions/entities.MemberRole' + projectID: + type: string + projectName: + type: string + projectOwner: + $ref: '#/definitions/entities.Member' + type: object + entities.ListProjectResponse: + properties: + projects: + items: + $ref: '#/definitions/entities.Project' + type: array + totalNumberOfProjects: + type: integer + type: object + entities.Member: + properties: + deactivatedAt: + type: integer + email: + type: string + invitation: + $ref: '#/definitions/entities.Invitation' + joinedAt: + type: integer + name: + type: string + role: + $ref: '#/definitions/entities.MemberRole' + userID: + type: string + username: + type: string + type: object + entities.MemberRole: + enum: + - Owner + - Executor + - Viewer + type: string + x-enum-varnames: + - RoleOwner + - RoleExecutor + - RoleViewer + entities.MemberStat: + properties: + owner: + items: + $ref: '#/definitions/entities.Owner' + type: array + total: + type: integer + type: object + entities.Owner: + properties: + deactivatedAt: + type: integer + invitation: + $ref: '#/definitions/entities.Invitation' + joinedAt: + type: integer + userID: + type: string + username: + type: string + type: object + entities.Project: + properties: + createdAt: + type: integer + createdBy: + $ref: '#/definitions/entities.UserDetailResponse' + description: + type: string + isRemoved: + type: boolean + members: + items: + $ref: '#/definitions/entities.Member' + type: array + name: + type: string + projectID: + type: string + state: + type: string + tags: + items: + type: string + type: array + updatedAt: + type: integer + updatedBy: + $ref: '#/definitions/entities.UserDetailResponse' + type: object + entities.ProjectStats: + properties: + members: + $ref: '#/definitions/entities.MemberStat' + name: + type: string + projectID: + type: string + type: object + entities.UserDetailResponse: + properties: + email: + type: string + userID: + type: string + username: + type: string + type: object + entities.UserWithProject: + properties: + createdAt: + type: integer + createdBy: + $ref: '#/definitions/entities.UserDetailResponse' + email: + type: string + id: + type: string + isRemoved: + type: boolean + name: + type: string + projects: + items: + $ref: '#/definitions/entities.Project' + type: array + updatedAt: + type: integer + updatedBy: + $ref: '#/definitions/entities.UserDetailResponse' + username: + type: string + type: object + response.APIStatus: + properties: + status: + type: string + type: object + response.ApiTokenResponse: + properties: + createdAt: + type: integer + expiresAt: + type: integer + name: + type: string + token: + type: string + userID: + type: string + type: object + response.CapabilitiesResponse: + properties: + dex: + properties: + enabled: + type: boolean + type: object + type: object + response.ErrInvalidCredentials: + properties: + code: + example: 401 + type: integer + message: + example: Invalid Credentials + type: string + type: object + response.ErrInvalidEmail: + properties: + code: + example: 400 + type: integer + message: + example: Email address is invalid + type: string + type: object + response.ErrInvalidRequest: + properties: + code: + example: 400 + type: integer + message: + example: The request is missing a required parameter, includes an invalid + parameter value, includes a parameter more than once, or is otherwise malformed + type: string + type: object + response.ErrInvalidRole: + properties: + code: + example: 400 + type: integer + message: + example: Role is invalid + type: string + type: object + response.ErrOldPassword: + properties: + code: + example: 400 + type: integer + message: + example: The old and new passwords can't be same + type: string + type: object + response.ErrProjectNotFound: + properties: + code: + example: 400 + type: integer + message: + example: This project does not exist + type: string + type: object + response.ErrServerError: + properties: + code: + example: 500 + type: integer + message: + example: The authorization server encountered an unexpected condition that + prevented it from fulfilling the request + type: string + type: object + response.ErrStrictPasswordPolicyViolation: + properties: + code: + example: 401 + type: integer + message: + example: Please ensure the password is atleast 8 characters and atmost 16 + characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase + alphabet and 1 special character + type: string + type: object + response.ErrStrictUsernamePolicyViolation: + properties: + code: + example: 401 + type: integer + message: + example: The username should be atleast 3 characters long and atmost 16 characters + long. + type: string + type: object + response.ErrUnauthorized: + properties: + code: + example: 401 + type: integer + message: + example: The user does not have requested authorization to access this resource + type: string + type: object + response.ErrUserDeactivated: + properties: + code: + example: 400 + type: integer + message: + example: your account has been deactivated + type: string + type: object + response.ErrUserExists: + properties: + code: + example: 401 + type: integer + message: + example: This username is already assigned to another user + type: string + type: object + response.ErrUserNotFound: + properties: + code: + example: 400 + type: integer + message: + example: user does not exist + type: string + type: object + response.ListInvitationResponse: + properties: + data: + items: + $ref: '#/definitions/entities.ListInvitationResponse' + type: array + type: object + response.ListProjectResponse: + properties: + data: + $ref: '#/definitions/entities.ListProjectResponse' + type: object + response.LoginResponse: + type: object + response.Member: + properties: + data: + $ref: '#/definitions/entities.Member' + type: object + response.Members: + properties: + data: + items: + $ref: '#/definitions/entities.Member' + type: array + type: object + response.MessageResponse: + properties: + message: + type: string + type: object + response.NewApiToken: + type: object + response.Project: + properties: + data: + $ref: '#/definitions/entities.Project' + type: object + response.ProjectIDWithMessage: + properties: + message: + type: string + projectID: + type: string + type: object + response.ProjectRole: + properties: + role: + type: string + type: object + response.ProjectStats: + properties: + data: + items: + $ref: '#/definitions/entities.ProjectStats' + type: array + type: object + response.Projects: + properties: + data: + items: + $ref: '#/definitions/entities.Project' + type: array + type: object + response.ReadinessAPIStatus: + properties: + collections: + type: string + database: + type: string + type: object + response.Response: + properties: + response: + type: string + type: object + response.UserResponse: + properties: + deactivatedAt: + type: integer + email: + type: string + name: + type: string + password: + type: string + role: + type: string + userID: + type: string + username: + type: string + type: object + response.UserWithProject: + properties: + data: + $ref: '#/definitions/entities.UserWithProject' + type: object +info: + contact: {} + title: Chaoscenter API documentation +paths: + /accept_invitation: + post: + consumes: + - application/json + description: Accept invitation to a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Accept invitation. + tags: + - ProjectRouter + /capabilities: + get: + consumes: + - application/json + description: Returns capabilities that can be leveraged by frontend services + to toggle certain features. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.CapabilitiesResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get capabilities of Auth Server. + tags: + - CapabilitiesRouter + /create_project: + post: + consumes: + - application/json + description: Create a new project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Project' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Create project. + tags: + - ProjectRouter + /create_token: + post: + consumes: + - application/json + description: Creates a new api token for the user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.NewApiToken' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrUserNotFound' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /create_user: + post: + consumes: + - application/json + description: Create new user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.UserResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidEmail' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUserExists' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /decline_invitation: + post: + consumes: + - application/json + description: Decline invitation to a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Decline invitation. + tags: + - ProjectRouter + /delete_project/:project_id: + post: + consumes: + - application/json + description: Delete a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrProjectNotFound' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - ProjectRouter + /dex/callback: + get: + consumes: + - application/json + description: DexRouter creates all the required routes for OAuth purposes. . + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - DexRouter + /dex/login: + get: + consumes: + - application/json + description: DexRouter creates all the required routes for OAuth purposes. . + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - DexRouter + /get_owner_projects: + get: + consumes: + - application/json + description: Return owner of projects. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Projects' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get projects owner. + tags: + - ProjectRouter + /get_project/:project_id: + get: + consumes: + - application/json + description: Return a project. + parameters: + - description: Project ID + in: path + name: project_id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Project' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get user with project. + tags: + - ProjectRouter + /get_project_members/:project_id/:state: + get: + consumes: + - application/json + description: Return list of active project members. + parameters: + - description: State + in: path + name: state + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Members' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get active project members. + tags: + - ProjectRouter + /get_project_owners/:project_id/:state: + get: + consumes: + - application/json + description: Return list of active project owners. + parameters: + - description: State + in: path + name: state + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Members' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get active project Owners. + tags: + - ProjectRouter + /get_project_role/:project_id: + get: + consumes: + - application/json + description: Return role of a project. + parameters: + - description: Project ID + in: path + name: project_id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ProjectRole' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrProjectNotFound' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get project Role. + tags: + - ProjectRouter + /get_projects_stats: + get: + consumes: + - application/json + description: Return stats of a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ProjectStats' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get stats of a project. + tags: + - ProjectRouter + /get_user/:uid: + get: + consumes: + - application/json + description: Get user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.UserResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrUserNotFound' + tags: + - UserRouter + /get_user_with_project/:username: + get: + consumes: + - application/json + description: Return users who have a project. + parameters: + - description: Username + in: path + name: username + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.UserWithProject' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrUserNotFound' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get user with project. + tags: + - ProjectRouter + /invite_users/:project_id: + get: + consumes: + - application/json + description: Invite users. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.UserResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /leave_project: + post: + consumes: + - application/json + description: Leave project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Leave project. + tags: + - ProjectRouter + /list_invitations_with_filters/:invitation_state: + get: + consumes: + - application/json + description: Return list of invitations. + parameters: + - description: Invitation State + in: path + name: invitation_state + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ListInvitationResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: List invitations. + tags: + - ProjectRouter + /list_projects: + get: + consumes: + - application/json + description: Return stats of a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ListProjectResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Get stats of a project. + tags: + - ProjectRouter + /login: + post: + consumes: + - application/json + description: User Login. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.LoginResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrUserDeactivated' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrInvalidCredentials' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /logout: + post: + consumes: + - application/json + description: Revokes the token passed in the Authorization header. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /readiness: + get: + consumes: + - application/json + description: Return list of tags. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ReadinessAPIStatus' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - MiscRouter + /remove_invitation: + post: + consumes: + - application/json + description: Remove invitation of a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Remove invitation. + tags: + - ProjectRouter + /remove_token: + post: + consumes: + - application/json + description: Delete api token for the user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /reset/password: + post: + consumes: + - application/json + description: Reset user password. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrStrictPasswordPolicyViolation' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /send_invitation: + post: + consumes: + - application/json + description: Send invitation to a project. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Member' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrUserNotFound' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Send invitation. + tags: + - ProjectRouter + /status: + get: + consumes: + - application/json + description: Status will request users list and return, if successful, a http + code 200. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.APIStatus' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - MiscRouter + /token/:uid: + post: + consumes: + - application/json + description: Returns all the api tokens for the user. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ApiTokenResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /update/details: + post: + consumes: + - application/json + description: Update users details. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrStrictUsernamePolicyViolation' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter + /update/password: + post: + consumes: + - application/json + description: Update user password. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.ProjectIDWithMessage' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrOldPassword' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrInvalidCredentials' + tags: + - UserRouter + /update/state: + post: + consumes: + - application/json + description: Updates the user state. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + tags: + - UserRouter + /update_member_role: + post: + consumes: + - application/json + description: Return updated member role. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Update member role. + tags: + - ProjectRouter + /update_project_name: + post: + consumes: + - application/json + description: Return updated project name. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.MessageResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.ErrInvalidRequest' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + summary: Update project name. + tags: + - ProjectRouter + /users: + get: + consumes: + - application/json + description: Fetch users. + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.UserResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/response.ErrUnauthorized' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.ErrServerError' + tags: + - UserRouter +swagger: "2.0" diff --git a/chaoscenter/authentication/api/handlers/doc.go b/chaoscenter/authentication/api/handlers/doc.go index 81574f08513..33cd47fe190 100644 --- a/chaoscenter/authentication/api/handlers/doc.go +++ b/chaoscenter/authentication/api/handlers/doc.go @@ -1,6 +1,9 @@ package response -import "github.com/gin-gonic/gin" +import ( + "github.com/gin-gonic/gin" + "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities" +) type Response struct { Response string @@ -134,3 +137,53 @@ type ErrProjectNotFoundstruct struct { Code int `json:"code" example:"400"` Message string `json:"message" example:"project does not exist"` } + +type ReadinessAPIStatus struct { + DataBase string `json:"database"` + Collections string `json:"collections"` +} + +type APIStatus struct { + Status string `json:"status"` +} + +type UserWithProject struct { + Data entities.UserWithProject `json:"data"` +} + +type Project struct { + Data entities.Project `json:"data"` +} + +type Projects struct { + Data []*entities.Project `json:"data"` +} + +type ListProjectResponse struct { + Data entities.ListProjectResponse `json:"data"` +} + +type ProjectStats struct { + Data []*entities.ProjectStats `json:"data"` +} + +type Members struct { + Data []*entities.Member `json:"data"` +} + +type Member struct { + Data entities.Member `json:"data"` +} + +type ListInvitationResponse struct { + Data []entities.ListInvitationResponse `json:"data"` +} + +type ProjectRole struct { + Role string `json:"role"` +} + +type ProjectIDWithMessage struct { + ProjectID string `json:"projectID"` + Message string `json:"message"` +} diff --git a/chaoscenter/authentication/api/handlers/rest/misc_handlers.go b/chaoscenter/authentication/api/handlers/rest/misc_handlers.go index 2dae36710e7..7c5d60e8718 100644 --- a/chaoscenter/authentication/api/handlers/rest/misc_handlers.go +++ b/chaoscenter/authentication/api/handlers/rest/misc_handlers.go @@ -3,7 +3,7 @@ package rest import ( "net/http" - "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities" + response "github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/services" "github.com/gin-gonic/gin" @@ -20,11 +20,6 @@ func contains(s []string, str string) bool { return false } -type ReadinessAPIStatus struct { - DataBase string `json:"database"` - Collections string `json:"collections"` -} - // Status godoc // // @Description Status will request users list and return, if successful, a http code 200. @@ -32,7 +27,7 @@ type ReadinessAPIStatus struct { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.APIStatus{} // @Router /status [get] // // Status will request users list and return, if successful, a http code 200 @@ -41,10 +36,10 @@ func Status(service services.ApplicationService) gin.HandlerFunc { _, err := service.GetUsers() if err != nil { log.Error(err) - c.JSON(http.StatusInternalServerError, entities.APIStatus{Status: "down"}) + c.JSON(http.StatusInternalServerError, response.APIStatus{Status: "down"}) return } - c.JSON(http.StatusOK, entities.APIStatus{Status: "up"}) + c.JSON(http.StatusOK, response.APIStatus{Status: "up"}) } } @@ -55,7 +50,7 @@ func Status(service services.ApplicationService) gin.HandlerFunc { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.ReadinessAPIStatus{} // @Router /readiness [get] // // Readiness will return the status of the database and collections @@ -73,7 +68,7 @@ func Readiness(service services.ApplicationService) gin.HandlerFunc { if err != nil { log.Error(err) - c.JSON(http.StatusInternalServerError, ReadinessAPIStatus{"down", "unknown"}) + c.JSON(http.StatusInternalServerError, response.ReadinessAPIStatus{DataBase: "down", Collections: "unknown"}) return } @@ -84,10 +79,10 @@ func Readiness(service services.ApplicationService) gin.HandlerFunc { if err != nil { log.Error(err) - c.JSON(http.StatusInternalServerError, ReadinessAPIStatus{dbFlag, "down"}) + c.JSON(http.StatusInternalServerError, response.ReadinessAPIStatus{DataBase: dbFlag, Collections: "down"}) return } - c.JSON(http.StatusOK, ReadinessAPIStatus{dbFlag, colFlag}) + c.JSON(http.StatusOK, response.ReadinessAPIStatus{DataBase: dbFlag, Collections: colFlag}) } } diff --git a/chaoscenter/authentication/api/handlers/rest/project_handler.go b/chaoscenter/authentication/api/handlers/rest/project_handler.go index 374af12b273..92c0caae7aa 100644 --- a/chaoscenter/authentication/api/handlers/rest/project_handler.go +++ b/chaoscenter/authentication/api/handlers/rest/project_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "time" + response "github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers" "github.com/litmuschaos/litmus/chaoscenter/authentication/api/presenter" "github.com/litmuschaos/litmus/chaoscenter/authentication/api/types" projectUtils "github.com/litmuschaos/litmus/chaoscenter/authentication/api/utils" @@ -31,7 +32,7 @@ import ( // @Failure 401 {object} response.ErrUnauthorized // @Failure 400 {object} response.ErrUserNotFound // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.UserWithProject{} // @Router /get_user_with_project/:username [get] // // GetUserWithProject returns user and project details based on username @@ -60,22 +61,22 @@ func GetUserWithProject(service services.ApplicationService) gin.HandlerFunc { request := projectUtils.GetProjectFilters(c) request.UserID = user.ID - response, err := service.GetProjectsByUserID(request) + res, err := service.GetProjectsByUserID(request) if err != nil { log.Error(err) c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - outputUser := &entities.UserWithProject{ + outputUser := entities.UserWithProject{ Username: user.Username, ID: user.ID, Email: user.Email, Name: user.Name, - Projects: response.Projects, + Projects: res.Projects, } - c.JSON(http.StatusOK, gin.H{"data": outputUser}) + c.JSON(http.StatusOK, response.UserWithProject{Data: outputUser}) } } @@ -89,7 +90,7 @@ func GetUserWithProject(service services.ApplicationService) gin.HandlerFunc { // @Produce json // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Project{} // @Router /get_project/:project_id [get] // // GetProject queries the project with a given projectID from the database @@ -116,7 +117,7 @@ func GetProject(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{"data": project}) + c.JSON(http.StatusOK, response.Project{Data: *project}) } } @@ -128,7 +129,7 @@ func GetProject(service services.ApplicationService) gin.HandlerFunc { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.ListProjectResponse{} // @Router /list_projects [get] // // GetProjectsByUserID queries the project with a given userID from the database and returns it in the appropriate format @@ -136,8 +137,8 @@ func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { request := projectUtils.GetProjectFilters(c) - response, err := service.GetProjectsByUserID(request) - if response == nil || (response.TotalNumberOfProjects != nil && *response.TotalNumberOfProjects == 0) { + res, err := service.GetProjectsByUserID(request) + if res == nil || (res.TotalNumberOfProjects != nil && *res.TotalNumberOfProjects == 0) { c.JSON(http.StatusOK, gin.H{ "message": "No projects found", }) @@ -148,7 +149,7 @@ func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{"data": response}) + c.JSON(http.StatusOK, response.ListProjectResponse{Data: *res}) } } @@ -160,7 +161,7 @@ func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.ProjectStats{} // @Router /get_projects_stats [get] // // GetProjectStats is used to retrieve stats related to projects in the DB @@ -183,7 +184,7 @@ func GetProjectStats(service services.ApplicationService) gin.HandlerFunc { c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{"data": project}) + c.JSON(http.StatusOK, response.ProjectStats{Data: project}) } } @@ -196,7 +197,7 @@ func GetProjectStats(service services.ApplicationService) gin.HandlerFunc { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Members{} // @Router /get_project_members/:project_id/:state [get] // // GetActiveProjectMembers returns the list of active project members @@ -221,7 +222,7 @@ func GetActiveProjectMembers(service services.ApplicationService) gin.HandlerFun c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{"data": members}) + c.JSON(http.StatusOK, response.Members{Data: members}) } } @@ -234,7 +235,7 @@ func GetActiveProjectMembers(service services.ApplicationService) gin.HandlerFun // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Members{} // @Router /get_project_owners/:project_id/:state [get] // // GetActiveProjectOwners returns the list of active project owners @@ -246,7 +247,7 @@ func GetActiveProjectOwners(service services.ApplicationService) gin.HandlerFunc c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{"data": owners}) + c.JSON(http.StatusOK, response.Members{Data: owners}) } } @@ -274,7 +275,7 @@ func getInvitation(service services.ApplicationService, member entities.MemberIn // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.ListInvitationResponse{} // @Router /list_invitations_with_filters/:invitation_state [get] // // ListInvitations returns the Invitation status @@ -282,7 +283,7 @@ func ListInvitations(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { uID := c.MustGet("uid").(string) invitationState := c.Param("invitation_state") - var response []entities.ListInvitationResponse + var res []entities.ListInvitationResponse projects, err := service.ListInvitations(uID, entities.Invitation(invitationState)) if err != nil { log.Errorf("Error while fetching invitations: %v", err) @@ -301,9 +302,9 @@ func ListInvitations(service services.ApplicationService) gin.HandlerFunc { inviteRes.InvitationRole = member.Role } } - response = append(response, inviteRes) + res = append(res, inviteRes) } - c.JSON(http.StatusOK, gin.H{"data": response}) + c.JSON(http.StatusOK, response.ListInvitationResponse{Data: res}) } } @@ -315,7 +316,7 @@ func ListInvitations(service services.ApplicationService) gin.HandlerFunc { // @Accept json // @Produce json // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Project{} // @Router /create_project [post] // // CreateProject is used to create a new project @@ -423,7 +424,7 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{"data": newProject.GetProjectOutput()}) + c.JSON(http.StatusOK, response.Project{Data: *newProject.GetProjectOutput()}) } @@ -441,7 +442,7 @@ func CreateProject(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRole // @Failure 400 {object} response.ErrUserNotFound // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Member{} // @Router /send_invitation [post] // // SendInvitation sends an invitation to a new user and returns an error if the member is already part of the project @@ -534,7 +535,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{"data": entities.Member{ + c.JSON(http.StatusOK, response.Member{Data: entities.Member{ UserID: user.ID, Username: user.Username, Name: user.Name, @@ -556,7 +557,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /accept_invitation [post] // // AcceptInvitation is used to accept an invitation @@ -600,9 +601,7 @@ func AcceptInvitation(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "Successful"}) } } @@ -616,7 +615,7 @@ func AcceptInvitation(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /decline_invitation [post] // // DeclineInvitation is used to decline an invitation @@ -660,9 +659,7 @@ func DeclineInvitation(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -676,7 +673,7 @@ func DeclineInvitation(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /leave_project [post] // // LeaveProject is used to leave a project @@ -734,9 +731,7 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -750,7 +745,7 @@ func LeaveProject(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /remove_invitation [post] // // RemoveInvitation removes member or cancels invitation @@ -822,9 +817,7 @@ func RemoveInvitation(service services.ApplicationService) gin.HandlerFunc { } } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -838,7 +831,7 @@ func RemoveInvitation(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /update_project_name [post] // // UpdateProjectName is used to update a project's name @@ -897,9 +890,7 @@ func UpdateProjectName(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -913,7 +904,7 @@ func UpdateProjectName(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /update_member_role [post] // // UpdateMemberRole is used to update a member role in the project @@ -958,9 +949,7 @@ func UpdateMemberRole(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successfully updated Role", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -974,7 +963,7 @@ func UpdateMemberRole(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Failure 401 {object} response.ErrUnauthorized // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.Projects{} // @Router /get_owner_projects [get] // // GetOwnerProjects returns an array of projects in which user is an owner @@ -988,9 +977,7 @@ func GetOwnerProjects(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "data": res, - }) + c.JSON(http.StatusOK, response.Projects{Data: res}) } } @@ -1005,7 +992,7 @@ func GetOwnerProjects(service services.ApplicationService) gin.HandlerFunc { // @Produce json // @Failure 400 {object} response.ErrProjectNotFound // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.ProjectRole{} // @Router /get_project_role/:project_id [get] // // GetProjectRole returns the role of a user in the project @@ -1028,9 +1015,7 @@ func GetProjectRole(service services.ApplicationService) gin.HandlerFunc { if res != nil { role = string(*res) } - c.JSON(http.StatusOK, gin.H{ - "role": role, - }) + c.JSON(http.StatusOK, response.ProjectRole{Role: role}) } } @@ -1043,7 +1028,7 @@ func GetProjectRole(service services.ApplicationService) gin.HandlerFunc { // @Produce json // @Failure 400 {object} response.ErrProjectNotFound // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /delete_project/:project_id [post] // // DeleteProject is used to delete a project. @@ -1070,8 +1055,6 @@ func DeleteProject(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successfully deleted project.", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "Successfully deleted project."}) } } diff --git a/chaoscenter/authentication/api/handlers/rest/user_handlers.go b/chaoscenter/authentication/api/handlers/rest/user_handlers.go index ef2728b9740..5bd787e239e 100644 --- a/chaoscenter/authentication/api/handlers/rest/user_handlers.go +++ b/chaoscenter/authentication/api/handlers/rest/user_handlers.go @@ -6,6 +6,7 @@ import ( "strings" "time" + response "github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers" "github.com/litmuschaos/litmus/chaoscenter/authentication/api/presenter" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/services" @@ -154,7 +155,7 @@ func UpdateUser(service services.ApplicationService) gin.HandlerFunc { c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{"message": "User details updated successfully"}) + c.JSON(http.StatusOK, response.MessageResponse{Message: "User details updated successfully"}) } } @@ -418,9 +419,7 @@ func LogoutUser(service services.ApplicationService) gin.HandlerFunc { c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{ - "message": "successfully logged out", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successfully logged out"}) } } @@ -434,7 +433,7 @@ func LogoutUser(service services.ApplicationService) gin.HandlerFunc { // @Failure 401 {object} response.ErrStrictPasswordPolicyViolation // @Failure 400 {object} response.ErrOldPassword // @Failure 401 {object} response.ErrInvalidCredentials -// @Success 200 {object} response.MessageResponse{} +// @Success 200 {object} response.ProjectIDWithMessage{} // @Router /update/password [post] // // UpdatePassword updates the user password @@ -528,10 +527,8 @@ func UpdatePassword(service services.ApplicationService) gin.HandlerFunc { } defaultProject = newProject.ID } - c.JSON(http.StatusOK, gin.H{ - "message": "password has been updated successfully", - "projectID": defaultProject, - }) + c.JSON(http.StatusOK, response.ProjectIDWithMessage{Message: "password has been updated successfully", ProjectID: defaultProject}) + } } @@ -606,9 +603,7 @@ func ResetPassword(service services.ApplicationService) gin.HandlerFunc { c.AbortWithStatusJSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return } - c.JSON(http.StatusOK, gin.H{ - "message": "password has been reset successfully", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "password has been reset successfully"}) } } @@ -677,9 +672,7 @@ func UpdateUserState(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "user's state updated successfully", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "user's state updated successfully"}) } } @@ -838,10 +831,8 @@ func DeleteApiToken(service services.ApplicationService) gin.HandlerFunc { log.Error(err) c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) return - } else { - c.JSON(http.StatusOK, gin.H{ - "message": "api token deleted successfully", - }) } + + c.JSON(http.StatusOK, response.MessageResponse{Message: "api token deleted successfully"}) } } diff --git a/chaoscenter/authentication/pkg/entities/user.go b/chaoscenter/authentication/pkg/entities/user.go index fb65c112e2c..0070ce6edeb 100644 --- a/chaoscenter/authentication/pkg/entities/user.go +++ b/chaoscenter/authentication/pkg/entities/user.go @@ -49,11 +49,6 @@ type UpdateUserState struct { IsDeactivate *bool `json:"isDeactivate"` } -// APIStatus defines structure for APIroute status -type APIStatus struct { - Status string `json:"status"` -} - type UserWithProject struct { Audit `bson:",inline"` ID string `bson:"_id" json:"id"`