From 5b45a6c26010cc3664c0af9d6e178411ada5880f Mon Sep 17 00:00:00 2001 From: Isaque Veras <46972789+isaqueveras@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:20:57 -0300 Subject: [PATCH] refact: remove swagger (#139) (#140) --- README.md | 2 +- docs/docs.go | 390 ------------------------------ docs/swagger.json | 338 -------------------------- docs/swagger.yaml | 225 ----------------- i18n/en_US.json | 3 - i18n/es_ES.json | 3 - i18n/pt_BR.json | 3 - interface/http/auth/handler.go | 65 +---- interface/http/project/handler.go | 7 - main.go | 17 -- server/rest.go | 39 ++- 11 files changed, 18 insertions(+), 1074 deletions(-) delete mode 100644 docs/docs.go delete mode 100644 docs/swagger.json delete mode 100644 docs/swagger.yaml diff --git a/README.md b/README.md index 0a9991e..39a2db4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ PowerSSO is a authenticator and user manager for systems (under construction)

--- -![Sem título-2023-07-14-0950(1)](https://github.com/isaqueveras/powersso/assets/46972789/5aff3f9d-6516-451d-973f-b2cef93c2ce1) +![permission architecture](https://github.com/isaqueveras/powersso/assets/46972789/5aff3f9d-6516-451d-973f-b2cef93c2ce1) ## 🚀 How to run the project 📌 Before starting, you will need to have the [Golang][golang] language installed on your machine. diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index 851c461..0000000 --- a/docs/docs.go +++ /dev/null @@ -1,390 +0,0 @@ -// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT -// This file was generated by swaggo/swag at -// 2023-06-04 20:48:38.098497808 -0300 -03 m=+0.254476976 - -package docs - -import ( - "bytes" - "encoding/json" - - "github.com/alecthomas/template" - "github.com/swaggo/swag" -) - -var doc = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "This is PowerSSO app server.", - "title": "Documentation PowerSSO", - "contact": { - "name": "PowerSSO", - "url": "https://github.com/isaqueveras/powersso/issues" - }, - "license": { - "name": "MIT license", - "url": "https://github.com/isaqueveras/powersso/blob/main/LICENSE" - }, - "version": "1.0.0" - }, - "host": "localhost:5000", - "basePath": "/", - "paths": { - "/v1/auth/activation/{token}": { - "post": { - "description": "Route to activate the user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Activate the user", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/login": { - "post": { - "description": "Route to login a user account into the system", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "User login", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.Session" - } - } - } - } - }, - "/v1/auth/login/steps": { - "get": { - "description": "Steps to login", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Steps to login", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.Steps" - } - } - } - } - }, - "/v1/auth/logout": { - "delete": { - "description": "Route to logout a user account into the system", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "User logout", - "responses": { - "204": { - "description": "No Content", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/register": { - "post": { - "description": "Register a user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Register a user", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/disable": { - "put": { - "description": "Route to disable a user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/User" - ], - "summary": "Disable user", - "parameters": [ - { - "type": "string", - "description": "UUID of the user", - "name": "user_uuid", - "in": "path", - "required": true - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/configure": { - "post": { - "description": "Configure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "Configure a user's OTP", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/qrcode": { - "get": { - "description": "Configure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "Configure a user's OTP", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.QRCode" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/unconfigure": { - "put": { - "description": "unconfigure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "unconfigure a user's OTP", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/project/create": { - "post": { - "description": "Register a project including several users to the project", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Project" - ], - "summary": "Register a projet", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - } - }, - "definitions": { - "auth.QRCode": { - "type": "object", - "properties": { - "url": { - "type": "string" - } - } - }, - "auth.Session": { - "type": "object", - "properties": { - "about": { - "type": "string" - }, - "created_at": { - "type": "string" - }, - "data": { - "type": "object" - }, - "email": { - "type": "string" - }, - "expires_at": { - "type": "string" - }, - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - }, - "level": { - "type": "string" - }, - "session_id": { - "type": "string" - }, - "token": { - "type": "string" - }, - "user_id": { - "type": "string" - } - } - }, - "auth.Steps": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "otp": { - "type": "boolean" - } - } - }, - "utils.NoContent": { - "type": "object" - } - }, - "securityDefinitions": { - "ApiKeyAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - } -}` - -type swaggerInfo struct { - Version string - Host string - BasePath string - Schemes []string - Title string - Description string -} - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = swaggerInfo{ Schemes: []string{}} - -type s struct{} - -func (s *s) ReadDoc() string { - t, err := template.New("swagger_info").Funcs(template.FuncMap{ - "marshal": func(v interface {}) string { - a, _ := json.Marshal(v) - return string(a) - }, - }).Parse(doc) - if err != nil { - return doc - } - - var tpl bytes.Buffer - if err := t.Execute(&tpl, SwaggerInfo); err != nil { - return doc - } - - return tpl.String() -} - -func init() { - swag.Register(swag.Name, &s{}) -} diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index 84eccfd..0000000 --- a/docs/swagger.json +++ /dev/null @@ -1,338 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "This is PowerSSO app server.", - "title": "Documentation PowerSSO", - "contact": { - "name": "PowerSSO", - "url": "https://github.com/isaqueveras/powersso/issues" - }, - "license": { - "name": "MIT license", - "url": "https://github.com/isaqueveras/powersso/blob/main/LICENSE" - }, - "version": "1.0.0" - }, - "host": "localhost:5000", - "basePath": "/", - "paths": { - "/v1/auth/activation/{token}": { - "post": { - "description": "Route to activate the user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Activate the user", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/login": { - "post": { - "description": "Route to login a user account into the system", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "User login", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.Session" - } - } - } - } - }, - "/v1/auth/login/steps": { - "get": { - "description": "Steps to login", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Steps to login", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.Steps" - } - } - } - } - }, - "/v1/auth/logout": { - "delete": { - "description": "Route to logout a user account into the system", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "User logout", - "responses": { - "204": { - "description": "No Content", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/register": { - "post": { - "description": "Register a user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth" - ], - "summary": "Register a user", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/disable": { - "put": { - "description": "Route to disable a user", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/User" - ], - "summary": "Disable user", - "parameters": [ - { - "type": "string", - "description": "UUID of the user", - "name": "user_uuid", - "in": "path", - "required": true - } - ], - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/configure": { - "post": { - "description": "Configure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "Configure a user's OTP", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/qrcode": { - "get": { - "description": "Configure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "Configure a user's OTP", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "object", - "$ref": "#/definitions/auth.QRCode" - } - } - } - } - }, - "/v1/auth/user/{user_uuid}/otp/unconfigure": { - "put": { - "description": "unconfigure a user's OTP", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Auth/OTP" - ], - "summary": "unconfigure a user's OTP", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - }, - "/v1/project/create": { - "post": { - "description": "Register a project including several users to the project", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Http/Project" - ], - "summary": "Register a projet", - "responses": { - "201": { - "description": "Created", - "schema": { - "type": "object", - "$ref": "#/definitions/utils.NoContent" - } - } - } - } - } - }, - "definitions": { - "auth.QRCode": { - "type": "object", - "properties": { - "url": { - "type": "string" - } - } - }, - "auth.Session": { - "type": "object", - "properties": { - "about": { - "type": "string" - }, - "created_at": { - "type": "string" - }, - "data": { - "type": "object" - }, - "email": { - "type": "string" - }, - "expires_at": { - "type": "string" - }, - "first_name": { - "type": "string" - }, - "last_name": { - "type": "string" - }, - "level": { - "type": "string" - }, - "session_id": { - "type": "string" - }, - "token": { - "type": "string" - }, - "user_id": { - "type": "string" - } - } - }, - "auth.Steps": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "otp": { - "type": "boolean" - } - } - }, - "utils.NoContent": { - "type": "object" - } - }, - "securityDefinitions": { - "ApiKeyAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - } -} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml deleted file mode 100644 index 3017ab4..0000000 --- a/docs/swagger.yaml +++ /dev/null @@ -1,225 +0,0 @@ -basePath: / -definitions: - auth.QRCode: - properties: - url: - type: string - type: object - auth.Session: - properties: - about: - type: string - created_at: - type: string - data: - type: object - email: - type: string - expires_at: - type: string - first_name: - type: string - last_name: - type: string - level: - type: string - session_id: - type: string - token: - type: string - user_id: - type: string - type: object - auth.Steps: - properties: - name: - type: string - otp: - type: boolean - type: object - utils.NoContent: - type: object -host: localhost:5000 -info: - contact: - name: PowerSSO - url: https://github.com/isaqueveras/powersso/issues - description: This is PowerSSO app server. - license: - name: MIT license - url: https://github.com/isaqueveras/powersso/blob/main/LICENSE - title: Documentation PowerSSO - version: 1.0.0 -paths: - /v1/auth/activation/{token}: - post: - consumes: - - application/json - description: Route to activate the user - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: Activate the user - tags: - - Http/Auth - /v1/auth/login: - post: - consumes: - - application/json - description: Route to login a user account into the system - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/auth.Session' - type: object - summary: User login - tags: - - Http/Auth - /v1/auth/login/steps: - get: - consumes: - - application/json - description: Steps to login - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/auth.Steps' - type: object - summary: Steps to login - tags: - - Http/Auth - /v1/auth/logout: - delete: - consumes: - - application/json - description: Route to logout a user account into the system - produces: - - application/json - responses: - "204": - description: No Content - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: User logout - tags: - - Http/Auth - /v1/auth/register: - post: - consumes: - - application/json - description: Register a user - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: Register a user - tags: - - Http/Auth - /v1/auth/user/{user_uuid}/disable: - put: - consumes: - - application/json - description: Route to disable a user - parameters: - - description: UUID of the user - in: path - name: user_uuid - required: true - type: string - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: Disable user - tags: - - Http/Auth/User - /v1/auth/user/{user_uuid}/otp/configure: - post: - consumes: - - application/json - description: Configure a user's OTP - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: Configure a user's OTP - tags: - - Http/Auth/OTP - /v1/auth/user/{user_uuid}/otp/qrcode: - get: - consumes: - - application/json - description: Configure a user's OTP - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/auth.QRCode' - type: object - summary: Configure a user's OTP - tags: - - Http/Auth/OTP - /v1/auth/user/{user_uuid}/otp/unconfigure: - put: - consumes: - - application/json - description: unconfigure a user's OTP - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: unconfigure a user's OTP - tags: - - Http/Auth/OTP - /v1/project/create: - post: - consumes: - - application/json - description: Register a project including several users to the project - produces: - - application/json - responses: - "201": - description: Created - schema: - $ref: '#/definitions/utils.NoContent' - type: object - summary: Register a projet - tags: - - Http/Project -securityDefinitions: - ApiKeyAuth: - in: header - name: Authorization - type: apiKey -swagger: "2.0" diff --git a/i18n/en_US.json b/i18n/en_US.json index f16b955..910f6b9 100644 --- a/i18n/en_US.json +++ b/i18n/en_US.json @@ -1,7 +1,4 @@ { - "welcome": { - "title": "Welcome to PowerSSO" - }, "errors": { "default": "Unknown error", "handling": { diff --git a/i18n/es_ES.json b/i18n/es_ES.json index d532886..3db25fe 100644 --- a/i18n/es_ES.json +++ b/i18n/es_ES.json @@ -1,7 +1,4 @@ { - "welcome": { - "title": "Bienvenido a PowerSSO" - }, "errors": { "default": "Error desconocido", "handling": { diff --git a/i18n/pt_BR.json b/i18n/pt_BR.json index a7d51a9..18f2373 100644 --- a/i18n/pt_BR.json +++ b/i18n/pt_BR.json @@ -1,7 +1,4 @@ { - "welcome": { - "title": "Bem-vindo ao PowerSSO" - }, "errors": { "default": "Erro desconhecido", "handling": { diff --git a/interface/http/auth/handler.go b/interface/http/auth/handler.go index b2d101a..f9b752e 100644 --- a/interface/http/auth/handler.go +++ b/interface/http/auth/handler.go @@ -17,13 +17,6 @@ import ( "github.com/isaqueveras/powersso/utils" ) -// register godoc -// @Summary Register a user -// @Description Register a user -// @Tags Http/Auth -// @Accept json -// @Produce json -// @Success 201 {object} utils.NoContent{} // @Router /v1/auth/create_account [post] func createAccount(ctx *gin.Context) { var input domain.CreateAccount @@ -40,13 +33,6 @@ func createAccount(ctx *gin.Context) { ctx.JSON(http.StatusCreated, utils.NoContent{}) } -// activation godoc -// @Summary Activate the user -// @Description Route to activate the user -// @Tags Http/Auth -// @Accept json -// @Produce json -// @Success 200 {object} utils.NoContent{} // @Router /v1/auth/activation/{token} [post] func activation(ctx *gin.Context) { token, err := uuid.Parse(ctx.Param("token")) @@ -63,13 +49,6 @@ func activation(ctx *gin.Context) { ctx.JSON(http.StatusOK, utils.NoContent{}) } -// login godoc -// @Summary User login -// @Description Route to login a user account into the system -// @Tags Http/Auth -// @Accept json -// @Produce json -// @Success 200 {object} auth.Session // @Router /v1/auth/login [post] func login(ctx *gin.Context) { var input domain.Login @@ -91,6 +70,7 @@ func login(ctx *gin.Context) { ctx.JSON(http.StatusOK, output) } +// @Router /v1/auth/change_password [put] func changePassword(ctx *gin.Context) { in := &domain.ChangePassword{} if err := ctx.ShouldBindJSON(in); err != nil { @@ -111,13 +91,6 @@ func changePassword(ctx *gin.Context) { ctx.JSON(http.StatusOK, nil) } -// logout godoc -// @Summary User logout -// @Description Route to logout a user account into the system -// @Tags Http/Auth -// @Accept json -// @Produce json -// @Success 204 {object} utils.NoContent{} // @Router /v1/auth/logout [delete] func logout(ctx *gin.Context) { sessionID, err := uuid.Parse(gopowersso.GetSession(ctx).SessionID) @@ -134,13 +107,6 @@ func logout(ctx *gin.Context) { ctx.JSON(http.StatusNoContent, utils.NoContent{}) } -// loginSteps godoc -// @Summary Steps to login -// @Description Steps to login -// @Tags Http/Auth -// @Accept json -// @Produce json -// @Success 200 {object} auth.Steps // @Router /v1/auth/login/steps [get] func loginSteps(ctx *gin.Context) { res, err := app.LoginSteps(ctx, utils.Pointer(ctx.Query("email"))) @@ -152,14 +118,6 @@ func loginSteps(ctx *gin.Context) { ctx.JSON(http.StatusOK, res) } -// disable godoc -// @Summary Disable user -// @Description Route to disable a user -// @Tags Http/Auth/User -// @Param user_uuid path string true "UUID of the user" -// @Accept json -// @Produce json -// @Success 201 {object} utils.NoContent{} // @Router /v1/auth/user/{user_uuid}/disable [put] func disable(ctx *gin.Context) { userID, err := uuid.Parse(ctx.Param("user_uuid")) @@ -176,13 +134,6 @@ func disable(ctx *gin.Context) { ctx.JSON(http.StatusCreated, utils.NoContent{}) } -// configure godoc -// @Summary Configure a user's OTP -// @Description Configure a user's OTP -// @Tags Http/Auth/OTP -// @Accept json -// @Produce json -// @Success 201 {object} utils.NoContent{} // @Router /v1/auth/user/{user_uuid}/otp/configure [post] func configure(ctx *gin.Context) { userID, err := uuid.Parse(ctx.Param("user_uuid")) @@ -199,13 +150,6 @@ func configure(ctx *gin.Context) { ctx.JSON(http.StatusCreated, utils.NoContent{}) } -// unconfigure godoc -// @Summary unconfigure a user's OTP -// @Description unconfigure a user's OTP -// @Tags Http/Auth/OTP -// @Accept json -// @Produce json -// @Success 201 {object} utils.NoContent{} // @Router /v1/auth/user/{user_uuid}/otp/unconfigure [put] func unconfigure(ctx *gin.Context) { userID, err := uuid.Parse(ctx.Param("user_uuid")) @@ -222,13 +166,6 @@ func unconfigure(ctx *gin.Context) { ctx.JSON(http.StatusCreated, utils.NoContent{}) } -// qrcode godoc -// @Summary Configure a user's OTP -// @Description Configure a user's OTP -// @Tags Http/Auth/OTP -// @Accept json -// @Produce json -// @Success 200 {object} auth.QRCode // @Router /v1/auth/user/{user_uuid}/otp/qrcode [get] func qrcode(ctx *gin.Context) { userID, err := uuid.Parse(ctx.Param("user_uuid")) diff --git a/interface/http/project/handler.go b/interface/http/project/handler.go index 038c3a6..8263aa6 100644 --- a/interface/http/project/handler.go +++ b/interface/http/project/handler.go @@ -15,13 +15,6 @@ import ( "github.com/isaqueveras/powersso/utils" ) -// create godoc -// @Summary Register a projet -// @Description Register a project including several users to the project -// @Tags Http/Project -// @Accept json -// @Produce json -// @Success 201 {object} utils.NoContent{} // @Router /v1/project/create [post] func create(ctx *gin.Context) { var ( diff --git a/main.go b/main.go index 06f0664..97dca35 100644 --- a/main.go +++ b/main.go @@ -11,28 +11,11 @@ import ( "github.com/isaqueveras/powersso/config" "github.com/isaqueveras/powersso/database/postgres" - _ "github.com/isaqueveras/powersso/docs" "github.com/isaqueveras/powersso/scripts" "github.com/isaqueveras/powersso/server" "github.com/isaqueveras/powersso/utils" ) -// @title Documentation PowerSSO -// @version 1.0.0 -// @description This is PowerSSO app server. - -// @contact.name PowerSSO -// @contact.url https://github.com/isaqueveras/powersso/issues - -// @license.name MIT license -// @license.url https://github.com/isaqueveras/powersso/blob/main/LICENSE - -// @securityDefinitions.apikey ApiKeyAuth -// @in header -// @name Authorization - -// @host localhost:5000 -// @BasePath / func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) diff --git a/server/rest.go b/server/rest.go index a0142cd..0208c5f 100644 --- a/server/rest.go +++ b/server/rest.go @@ -12,10 +12,7 @@ import ( "github.com/gin-gonic/gin" "github.com/isaqueveras/endless" gopowersso "github.com/isaqueveras/go-powersso" - swaggerFiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" - "github.com/isaqueveras/powersso/i18n" "github.com/isaqueveras/powersso/interface/http/auth" "github.com/isaqueveras/powersso/interface/http/project" "github.com/isaqueveras/powersso/middleware" @@ -46,10 +43,6 @@ func (s *Server) ServerHTTP() (err error) { project.RouterAuthorization(v1.Group("project", gopowersso.Authorization(&s.cfg.UserAuthToken.SecretKey))) auth.RouterAuthorization(v1.Group("auth", gopowersso.Authorization(&s.cfg.UserAuthToken.SecretKey))) - router.GET("", func(ctx *gin.Context) { - ctx.JSON(http.StatusOK, gin.H{"message": i18n.Value("welcome.title"), "date": time.Now()}) - }) - endless.DefaultReadTimeOut = s.cfg.Server.ReadTimeout * time.Second endless.DefaultWriteTimeOut = s.cfg.Server.WriteTimeout * time.Second endless.DefaultMaxHeaderBytes = http.DefaultMaxHeaderBytes @@ -63,24 +56,24 @@ func (s *Server) ServerHTTP() (err error) { }) s.routerDebugPProf(router) - - // TODO: add permission in documentation route - router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) - return } func (s *Server) routerDebugPProf(router *gin.Engine) { - prefixRouter := router.Group("debug/pprof") - prefixRouter.GET("/", - gopowersso.Authorization(&s.cfg.UserAuthToken.SecretKey), - gopowersso.OnlyAdmin(), - func(c *gin.Context) { - pprof.Index(c.Writer, c.Request) - }, - ) - - s.group.Go(func() error { - return endless.ListenAndServe("0.0.0.0"+s.cfg.Server.PprofPort, router) - }) + r := router.Group("debug/pprof") + r.Use(gopowersso.Authorization(&s.cfg.UserAuthToken.SecretKey), gopowersso.OnlyAdmin()) + + r.GET("/", func(c *gin.Context) { pprof.Index(c.Writer, c.Request) }) + r.GET("/cmdline", func(c *gin.Context) { pprof.Cmdline(c.Writer, c.Request) }) + r.GET("/profile", func(c *gin.Context) { pprof.Profile(c.Writer, c.Request) }) + r.POST("/symbol", func(c *gin.Context) { pprof.Symbol(c.Writer, c.Request) }) + r.GET("/trace", func(c *gin.Context) { pprof.Trace(c.Writer, c.Request) }) + r.GET("/allocs", func(c *gin.Context) { pprof.Handler("allocs").ServeHTTP(c.Writer, c.Request) }) + r.GET("/block", func(c *gin.Context) { pprof.Handler("block").ServeHTTP(c.Writer, c.Request) }) + r.GET("/goroutine", func(c *gin.Context) { pprof.Handler("goroutine").ServeHTTP(c.Writer, c.Request) }) + r.GET("/heap", func(c *gin.Context) { pprof.Handler("heap").ServeHTTP(c.Writer, c.Request) }) + r.GET("/mutex", func(c *gin.Context) { pprof.Handler("mutex").ServeHTTP(c.Writer, c.Request) }) + r.GET("/threadcreate", func(c *gin.Context) { pprof.Handler("threadcreate").ServeHTTP(c.Writer, c.Request) }) + + s.group.Go(func() error { return endless.ListenAndServe("0.0.0.0"+s.cfg.Server.PprofPort, router) }) }