diff --git a/chaoscenter/authentication/DOC_SETUP.md b/chaoscenter/authentication/DOC_SETUP.md index e1b0b4958..81b383e63 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 deleted file mode 100644 index 73c8be438..000000000 --- a/chaoscenter/authentication/api/docs/docs.go +++ /dev/null @@ -1,1372 +0,0 @@ -// Package docs Code generated by swaggo/swag. DO NOT EDIT -package docs - -import "github.com/swaggo/swag" - -const docTemplate = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": {}, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/accept_invitation": { - "post": { - "description": "Accept inviation to a project.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ProjectRouter" - ], - "summary": "Accept invitaion.", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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.Response" - } - }, - "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": "Deecline invitation to a project.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ProjectRouter" - ], - "summary": "Decline invitation.", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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" - } - } - } - } - }, - "/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.Response" - } - }, - "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_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.Response" - } - }, - "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.Response" - } - }, - "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.Response" - } - }, - "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" - } - } - } - } - }, - "/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.Response" - } - }, - "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.Response" - } - }, - "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.Response" - } - }, - "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.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.Response" - } - }, - "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": { - "type": "obejct" - } - }, - "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.Response" - } - }, - "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, an http code 200.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "MiscRouter" - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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.MessageResponse" - } - }, - "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_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.Response" - } - }, - "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": { - "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.LoginResponse": { - "type": "object" - }, - "response.MessageResponse": { - "type": "object", - "properties": { - "message": { - "type": "string" - } - } - }, - "response.NewApiToken": { - "type": "object" - }, - "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" - } - } - } - } -}` - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = &swag.Spec{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "Chaoscenter API documentation", - Description: "", - InfoInstanceName: "swagger", - SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", -} - -func init() { - swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} diff --git a/chaoscenter/authentication/api/docs/swagger.json b/chaoscenter/authentication/api/docs/swagger.json deleted file mode 100644 index 189ff56e1..000000000 --- a/chaoscenter/authentication/api/docs/swagger.json +++ /dev/null @@ -1,1344 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "title": "Chaoscenter API documentation", - "contact": {} - }, - "paths": { - "/accept_invitation": { - "post": { - "description": "Accept inviation to a project.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ProjectRouter" - ], - "summary": "Accept invitaion.", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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.Response" - } - }, - "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": "Deecline invitation to a project.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ProjectRouter" - ], - "summary": "Decline invitation.", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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" - } - } - } - } - }, - "/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.Response" - } - }, - "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_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.Response" - } - }, - "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.Response" - } - }, - "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.Response" - } - }, - "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" - } - } - } - } - }, - "/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.Response" - } - }, - "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.Response" - } - }, - "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.Response" - } - }, - "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.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.Response" - } - }, - "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": { - "type": "obejct" - } - }, - "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.Response" - } - }, - "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, an http code 200.", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "MiscRouter" - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/response.Response" - } - }, - "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.MessageResponse" - } - }, - "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_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.Response" - } - }, - "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": { - "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.LoginResponse": { - "type": "object" - }, - "response.MessageResponse": { - "type": "object", - "properties": { - "message": { - "type": "string" - } - } - }, - "response.NewApiToken": { - "type": "object" - }, - "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" - } - } - } - } -} \ No newline at end of file diff --git a/chaoscenter/authentication/api/handlers/doc.go b/chaoscenter/authentication/api/handlers/doc.go index 81574f085..7336517f7 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 @@ -32,7 +35,7 @@ type CapabilitiesResponse struct { } type MessageResponse struct { - Message string + Message string `json:"message"` } type NewApiToken struct { @@ -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 { + Message string `json:"message"` + ProjectID string `json:"projectID"` +} diff --git a/chaoscenter/authentication/api/handlers/rest/capabilities_handler.go b/chaoscenter/authentication/api/handlers/rest/capabilities_handler.go index 9fea792b8..f9eca4bfa 100644 --- a/chaoscenter/authentication/api/handlers/rest/capabilities_handler.go +++ b/chaoscenter/authentication/api/handlers/rest/capabilities_handler.go @@ -16,6 +16,8 @@ import ( // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.CapabilitiesResponse{} // @Router /capabilities [get] +// +// GetCapabilities returns the capabilities of the Auth Server. func GetCapabilities() gin.HandlerFunc { return func(c *gin.Context) { capabilities := new(response.CapabilitiesResponse) diff --git a/chaoscenter/authentication/api/handlers/rest/misc_handlers.go b/chaoscenter/authentication/api/handlers/rest/misc_handlers.go index fb9e73bb1..7c5d60e87 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,32 +20,26 @@ 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, an http code 200. +// @Description Status will request users list and return, if successful, a http code 200. // @Tags MiscRouter // @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, -// an http code 200 +// Status will request users list and return, if successful, a http code 200 func Status(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { _, 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"}) } } @@ -56,37 +50,39 @@ 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 func Readiness(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var ( - db_flag = "up" - col_flag = "up" + dbFlag = "up" + colFlag = "up" ) dbs, err := service.ListDataBase() if !contains(dbs, "auth") { - db_flag = "down" + dbFlag = "down" } if err != nil { log.Error(err) - c.JSON(http.StatusInternalServerError, ReadinessAPIStatus{"down", "unknown"}) + c.JSON(http.StatusInternalServerError, response.ReadinessAPIStatus{DataBase: "down", Collections: "unknown"}) return } cols, err := service.ListCollection() if !contains(cols, "project") || !contains(cols, "users") { - col_flag = "down" + colFlag = "down" } if err != nil { log.Error(err) - c.JSON(http.StatusInternalServerError, ReadinessAPIStatus{db_flag, "down"}) + c.JSON(http.StatusInternalServerError, response.ReadinessAPIStatus{DataBase: dbFlag, Collections: "down"}) return } - c.JSON(http.StatusOK, ReadinessAPIStatus{db_flag, col_flag}) + 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 8838ba9a7..d3736f503 100644 --- a/chaoscenter/authentication/api/handlers/rest/project_handler.go +++ b/chaoscenter/authentication/api/handlers/rest/project_handler.go @@ -1,12 +1,14 @@ package rest import ( + "errors" "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" - project_utils "github.com/litmuschaos/litmus/chaoscenter/authentication/api/utils" + projectUtils "github.com/litmuschaos/litmus/chaoscenter/authentication/api/utils" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/services" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/utils" @@ -20,8 +22,9 @@ import ( ) // GetUserWithProject godoc +// // @Summary Get user with project. -// @Description Return users who has a project. +// @Description Return users who have a project. // @Tags ProjectRouter // @Param username path string true "Username" // @Accept json @@ -29,16 +32,16 @@ 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 func GetUserWithProject(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { username := c.Param("username") - // Validating logged in user - // Must be either requesting info from the logged in user + // Validating logged-in user + // Must be either requesting info from the logged-in user // or any user if it has the admin role role := c.MustGet("role").(string) if c.MustGet("username").(string) != username && role != string(entities.RoleAdmin) { @@ -55,29 +58,30 @@ func GetUserWithProject(service services.ApplicationService) gin.HandlerFunc { return } - request := project_utils.GetProjectFilters(c) + 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}) } } // GetProject godoc +// // @Summary Get user with project. // @Description Return a project. // @Tags ProjectRouter @@ -86,9 +90,9 @@ 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 func GetProject(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { @@ -113,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}) } } @@ -125,16 +129,16 @@ 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 func GetProjectsByUserID(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { - request := project_utils.GetProjectFilters(c) + 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", }) @@ -146,7 +150,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}) } } @@ -158,10 +162,10 @@ 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 retrive stats related to projects in the DB +// GetProjectStats is used to retrieve stats related to projects in the DB func GetProjectStats(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { role := c.MustGet("role").(string) @@ -181,7 +185,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}) } } @@ -194,8 +198,10 @@ 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 func GetActiveProjectMembers(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { projectID := c.Param("project_id") @@ -217,7 +223,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}) } } @@ -230,8 +236,10 @@ 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 func GetActiveProjectOwners(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { projectID := c.Param("project_id") @@ -240,7 +248,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}) } } @@ -268,7 +276,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 @@ -276,7 +284,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) @@ -295,9 +303,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}) } } @@ -309,8 +317,10 @@ 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 func CreateProject(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var userRequest entities.CreateProjectInput @@ -415,7 +425,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()}) } @@ -433,11 +443,10 @@ 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 +// SendInvitation sends an invitation to a new user and returns an error if the member is already part of the project func SendInvitation(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var member entities.MemberInput @@ -477,7 +486,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { user, err := service.GetUser(member.UserID) - if err == mongo.ErrNoDocuments { + if errors.Is(err, mongo.ErrNoDocuments) { c.JSON(utils.ErrorStatusCodes[utils.ErrUserNotFound], presenter.CreateErrorResponse(utils.ErrUserNotFound)) return } else if err != nil { @@ -487,7 +496,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { } invitation, err := getInvitation(service, member) - if err == mongo.ErrNoDocuments { + if errors.Is(err, mongo.ErrNoDocuments) { c.JSON(utils.ErrorStatusCodes[utils.ErrProjectNotFound], presenter.CreateErrorResponse(utils.ErrProjectNotFound)) return } else if err != nil { @@ -527,7 +536,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, @@ -541,15 +550,15 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc { // AcceptInvitation godoc // -// @Summary Accept invitaion. -// @Description Accept inviation to a project. +// @Summary Accept invitation. +// @Description Accept invitation to a project. // @Tags ProjectRouter // @Accept json // @Produce json // @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 @@ -593,23 +602,21 @@ func AcceptInvitation(service services.ApplicationService) gin.HandlerFunc { return } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "Successful"}) } } // DeclineInvitation godoc // // @Summary Decline invitation. -// @Description Deecline invitation to a project. +// @Description Decline invitation to a project. // @Tags ProjectRouter // @Accept json // @Produce json // @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 @@ -653,9 +660,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"}) } } @@ -669,7 +674,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 @@ -727,9 +732,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"}) } } @@ -743,7 +746,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 {obejct} response.Response{} +// @Success 200 {object} response.MessageResponse{} // @Router /remove_invitation [post] // // RemoveInvitation removes member or cancels invitation @@ -815,9 +818,7 @@ func RemoveInvitation(service services.ApplicationService) gin.HandlerFunc { } } - c.JSON(http.StatusOK, gin.H{ - "message": "Successful", - }) + c.JSON(http.StatusOK, response.MessageResponse{Message: "successful"}) } } @@ -831,7 +832,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 @@ -890,9 +891,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"}) } } @@ -906,7 +905,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 @@ -951,9 +950,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"}) } } @@ -967,7 +964,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 @@ -981,9 +978,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}) } } @@ -998,7 +993,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 @@ -1010,7 +1005,7 @@ func GetProjectRole(service services.ApplicationService) gin.HandlerFunc { res, err := service.GetProjectRole(projectID, uid) if err != nil { log.Error(err) - if err == mongo.ErrNoDocuments { + if errors.Is(err, mongo.ErrNoDocuments) { c.JSON(utils.ErrorStatusCodes[utils.ErrProjectNotFound], presenter.CreateErrorResponse(utils.ErrProjectNotFound)) return } @@ -1021,9 +1016,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}) } } @@ -1036,8 +1029,8 @@ func GetProjectRole(service services.ApplicationService) gin.HandlerFunc { // @Produce json // @Failure 400 {object} response.ErrProjectNotFound // @Failure 500 {object} response.ErrServerError -// @Success 200 {object} response.Response{} -// @Router /delete_project/{project_id} [post] +// @Success 200 {object} response.MessageResponse{} +// @Router /delete_project/:project_id [post] // // DeleteProject is used to delete a project. func DeleteProject(service services.ApplicationService) gin.HandlerFunc { @@ -1063,8 +1056,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 d8bcf5d9a..5bd787e23 100644 --- a/chaoscenter/authentication/api/handlers/rest/user_handlers.go +++ b/chaoscenter/authentication/api/handlers/rest/user_handlers.go @@ -1,10 +1,12 @@ package rest import ( + "errors" "net/http" "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" @@ -34,6 +36,8 @@ const BearerSchema = "Bearer " // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.UserResponse{} // @Router /create_user [post] +// +// CreateUser creates a new user func CreateUser(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { userRole := c.MustGet("role").(string) @@ -94,7 +98,7 @@ func CreateUser(service services.ApplicationService) gin.HandlerFunc { userRequest.CreatedAt = createdAt userResponse, err := service.CreateUser(&userRequest) - if err == utils.ErrUserExists { + if errors.Is(err, utils.ErrUserExists) { log.Error(err) c.JSON(utils.ErrorStatusCodes[utils.ErrUserExists], presenter.CreateErrorResponse(utils.ErrUserExists)) return @@ -121,6 +125,8 @@ func CreateUser(service services.ApplicationService) gin.HandlerFunc { // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.MessageResponse{} // @Router /update/details [post] +// +// UpdateUser updates the user details func UpdateUser(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var userRequest entities.UserDetails @@ -149,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"}) } } @@ -168,8 +174,8 @@ func GetUser(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { uid := c.Param("uid") - // Validating logged in user - // Must be either requesting info from the logged in user + // Validating logged-in user + // Must be either requesting info from the logged-in user // or any user if it has the admin role role := c.MustGet("role").(string) if c.MustGet("uid").(string) != uid && role != string(entities.RoleAdmin) { @@ -199,6 +205,8 @@ func GetUser(service services.ApplicationService) gin.HandlerFunc { // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.UserResponse{} // @Router /users [get] +// +// FetchUsers fetches all the users func FetchUsers(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { userRole := c.MustGet("role").(string) @@ -227,6 +235,8 @@ func FetchUsers(service services.ApplicationService) gin.HandlerFunc { // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.UserResponse{} // @Router /invite_users/:project_id [get] +// +// InviteUsers invites users to the project func InviteUsers(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { projectID := c.Param("project_id") @@ -245,11 +255,11 @@ func InviteUsers(service services.ApplicationService) gin.HandlerFunc { projectMembers, err := service.GetProjectMembers(projectID, "all") - var uids []string + var userIds []string for _, k := range projectMembers { - uids = append(uids, k.UserID) + userIds = append(userIds, k.UserID) } - users, err := service.InviteUsers(uids) + users, err := service.InviteUsers(userIds) if err != nil { log.Error(err) c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError)) @@ -272,6 +282,8 @@ func InviteUsers(service services.ApplicationService) gin.HandlerFunc { // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.LoginResponse{} // @Router /login [post] +// +// LoginUser returns the token for the user if the credentials are valid func LoginUser(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var userRequest entities.User @@ -407,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"}) } } @@ -423,8 +433,10 @@ 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 func UpdatePassword(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { var userPasswordRequest entities.UserPassword @@ -515,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}) + } } @@ -534,6 +544,8 @@ func UpdatePassword(service services.ApplicationService) gin.HandlerFunc { // @Failure 500 {object} response.ErrServerError // @Success 200 {object} response.MessageResponse{} // @Router /reset/password [post] +// +// ResetPassword resets the user password func ResetPassword(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { userRole := c.MustGet("role").(string) @@ -591,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"}) } } @@ -607,6 +617,8 @@ func ResetPassword(service services.ApplicationService) gin.HandlerFunc { // @Failure 400 {object} response.ErrInvalidRequest // @Success 200 {object} response.MessageResponse{} // @Router /update/state [post] +// +// UpdateUserState updates the user state func UpdateUserState(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { @@ -660,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"}) } } @@ -689,8 +699,8 @@ func CreateApiToken(service services.ApplicationService) gin.HandlerFunc { return } - // Validating logged in user - // Requesting info must be from the logged in user + // Validating logged-in user + // Requesting info must be from the logged-in user if c.MustGet("uid").(string) != apiTokenRequest.UserID { log.Error("auth error: unauthorized") c.JSON(utils.ErrorStatusCodes[utils.ErrUnauthorized], @@ -746,8 +756,8 @@ func GetApiTokens(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { uid := c.Param("uid") - // Validating logged in user - // Requesting info must be from the logged in user + // Validating logged-in user + // Requesting info must be from the logged-in user if c.MustGet("uid").(string) != uid { log.Error("auth error: unauthorized") c.JSON(utils.ErrorStatusCodes[utils.ErrUnauthorized], @@ -789,8 +799,8 @@ func DeleteApiToken(service services.ApplicationService) gin.HandlerFunc { return } - // Validating logged in user - // Requesting info must be from the logged in user + // Validating logged-in user + // Requesting info must be from the logged-in user if c.MustGet("uid").(string) != deleteApiTokenRequest.UserID { log.Error("auth error: unauthorized") c.JSON(utils.ErrorStatusCodes[utils.ErrUnauthorized], @@ -821,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 fb65c112e..0070ce6ed 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"` diff --git a/mkdocs/docs/auth/v3.14.0/api.html b/mkdocs/docs/auth/v3.14.0/api.html new file mode 100644 index 000000000..cf7b97b87 --- /dev/null +++ b/mkdocs/docs/auth/v3.14.0/api.html @@ -0,0 +1,661 @@ + + + +
+ +Download OpenAPI specification:Download
Litmus Portal Authentication APIs are used to authenticate the identity of a user and to perform several user-specific tasks like:
{- "data": {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "description": "string",
- "isRemoved": true,
- "members": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ],
- "name": "string",
- "projectID": "string",
- "state": "string",
- "tags": [- "string"
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 }
 }
}{- "data": [- {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "description": "string",
- "isRemoved": true,
- "members": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ],
- "name": "string",
- "projectID": "string",
- "state": "string",
- "tags": [- "string"
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 }
 }
 ]
}Return a project.
+| project_id required | string Project ID+ | 
{- "data": {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "description": "string",
- "isRemoved": true,
- "members": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ],
- "name": "string",
- "projectID": "string",
- "state": "string",
- "tags": [- "string"
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 }
 }
}Return list of active project members.
+| state required | string State+ | 
{- "data": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ]
}Return list of active project owners.
+| state required | string State+ | 
{- "data": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ]
}Return users who have a project.
+| username required | string Username+ | 
{- "data": {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "email": "string",
- "id": "string",
- "isRemoved": true,
- "name": "string",
- "projects": [- {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "description": "string",
- "isRemoved": true,
- "members": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ],
- "name": "string",
- "projectID": "string",
- "state": "string",
- "tags": [- "string"
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 }
 }
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "username": "string"
 }
}Return list of invitations.
+| invitation_state required | string Invitation State+ | 
{- "data": [- {- "invitationRole": "Owner",
- "projectID": "string",
- "projectName": "string",
- "projectOwner": {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 }
 ]
}{- "data": {- "projects": [- {- "createdAt": 0,
- "createdBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 },
- "description": "string",
- "isRemoved": true,
- "members": [- {- "deactivatedAt": 0,
- "email": "string",
- "invitation": "Pending",
- "joinedAt": 0,
- "name": "string",
- "role": "Owner",
- "userID": "string",
- "username": "string"
 }
 ],
- "name": "string",
- "projectID": "string",
- "state": "string",
- "tags": [- "string"
 ],
- "updatedAt": 0,
- "updatedBy": {- "email": "string",
- "userID": "string",
- "username": "string"
 }
 }
 ],
- "totalNumberOfProjects": 0
 }
}