More testing done around jwt and things are looking ok. Should be able to work on the portal now some.

This commit is contained in:
James Tombleson 2024-05-07 22:10:17 -07:00
parent 5ff6a8ddae
commit c0fb43df7d
5 changed files with 172 additions and 39 deletions

15
.vscode/launch.json vendored
View File

@ -1,15 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "."
}
]
}

View File

@ -203,6 +203,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks": { "/v1/discord/webhooks": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -234,6 +239,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/by/serverAndChannel": { "/v1/discord/webhooks/by/serverAndChannel": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -281,6 +291,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/new": { "/v1/discord/webhooks/new": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -369,6 +384,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/{ID}/disable": { "/v1/discord/webhooks/{ID}/disable": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -406,6 +426,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/{ID}/enable": { "/v1/discord/webhooks/{ID}/enable": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -424,6 +449,11 @@ const docTemplate = `{
}, },
"/v1/discord/webhooks/{id}": { "/v1/discord/webhooks/{id}": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -810,14 +840,33 @@ const docTemplate = `{
"summary": "Marks a source as deleted based on its ID value.", "summary": "Marks a source as deleted based on its ID value.",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "integer",
"description": "id", "description": "id",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
], ],
"responses": {} "responses": {
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.BaseResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.BaseResponse"
}
}
}
} }
}, },
"/v1/sources/{id}/disable": { "/v1/sources/{id}/disable": {
@ -1036,6 +1085,11 @@ const docTemplate = `{
}, },
"/v1/users/scopes/add": { "/v1/users/scopes/add": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -1081,6 +1135,11 @@ const docTemplate = `{
}, },
"/v1/users/scopes/remove": { "/v1/users/scopes/remove": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],

View File

@ -194,6 +194,11 @@
}, },
"/v1/discord/webhooks": { "/v1/discord/webhooks": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -225,6 +230,11 @@
}, },
"/v1/discord/webhooks/by/serverAndChannel": { "/v1/discord/webhooks/by/serverAndChannel": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -272,6 +282,11 @@
}, },
"/v1/discord/webhooks/new": { "/v1/discord/webhooks/new": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -360,6 +375,11 @@
}, },
"/v1/discord/webhooks/{ID}/disable": { "/v1/discord/webhooks/{ID}/disable": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -397,6 +417,11 @@
}, },
"/v1/discord/webhooks/{ID}/enable": { "/v1/discord/webhooks/{ID}/enable": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"tags": [ "tags": [
"DiscordWebhook" "DiscordWebhook"
], ],
@ -415,6 +440,11 @@
}, },
"/v1/discord/webhooks/{id}": { "/v1/discord/webhooks/{id}": {
"get": { "get": {
"security": [
{
"Bearer": []
}
],
"produces": [ "produces": [
"application/json" "application/json"
], ],
@ -801,14 +831,33 @@
"summary": "Marks a source as deleted based on its ID value.", "summary": "Marks a source as deleted based on its ID value.",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "integer",
"description": "id", "description": "id",
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
} }
], ],
"responses": {} "responses": {
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/domain.SourcesResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/domain.BaseResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/domain.BaseResponse"
}
}
}
} }
}, },
"/v1/sources/{id}/disable": { "/v1/sources/{id}/disable": {
@ -1027,6 +1076,11 @@
}, },
"/v1/users/scopes/add": { "/v1/users/scopes/add": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -1072,6 +1126,11 @@
}, },
"/v1/users/scopes/remove": { "/v1/users/scopes/remove": {
"post": { "post": {
"security": [
{
"Bearer": []
}
],
"consumes": [ "consumes": [
"application/json" "application/json"
], ],

View File

@ -269,6 +269,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Returns the top 100 summary: Returns the top 100
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -317,6 +319,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Disables a Webhook from being used. summary: Disables a Webhook from being used.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -329,6 +333,8 @@ paths:
required: true required: true
type: integer type: integer
responses: {} responses: {}
security:
- Bearer: []
summary: Enables a source to continue processing. summary: Enables a source to continue processing.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -355,6 +361,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Returns the top 100 entries from the queue to be processed. summary: Returns the top 100 entries from the queue to be processed.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -386,6 +394,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Returns all the known web hooks based on the Server and Channel given. summary: Returns all the known web hooks based on the Server and Channel given.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -420,6 +430,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Creates a new record for a discord web hook to post data to. summary: Creates a new record for a discord web hook to post data to.
tags: tags:
- DiscordWebhook - DiscordWebhook
@ -480,8 +492,20 @@ paths:
in: path in: path
name: id name: id
required: true required: true
type: string type: integer
responses: {} responses:
"200":
description: ok
schema:
$ref: '#/definitions/domain.SourcesResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/domain.BaseResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/domain.BaseResponse'
security: security:
- Bearer: [] - Bearer: []
summary: Marks a source as deleted based on its ID value. summary: Marks a source as deleted based on its ID value.
@ -806,6 +830,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Adds a new scope to a user account summary: Adds a new scope to a user account
tags: tags:
- Users - Users
@ -835,6 +861,8 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.BaseResponse' $ref: '#/definitions/domain.BaseResponse'
security:
- Bearer: []
summary: Adds a new scope to a user account summary: Adds a new scope to a user account
tags: tags:
- Users - Users

View File

@ -20,9 +20,9 @@ const (
// @Router /v1/users/register [post] // @Router /v1/users/register [post]
// @Param request formData domain.LoginFormRequest true "form" // @Param request formData domain.LoginFormRequest true "form"
// @Accepts x-www-form-urlencoded // @Accepts x-www-form-urlencoded
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
func (h *Handler) AuthRegister(c echo.Context) error { func (h *Handler) AuthRegister(c echo.Context) error {
@ -62,11 +62,11 @@ func (h *Handler) AuthRegister(c echo.Context) error {
// @Router /v1/users/login [post] // @Router /v1/users/login [post]
// @Param request formData domain.LoginFormRequest true "form" // @Param request formData domain.LoginFormRequest true "form"
// @Accepts x-www-form-urlencoded // @Accepts x-www-form-urlencoded
// @Produce json // @Produce json
// @Tags Users // @Tags Users
// @Success 200 {object} domain.LoginResponse // @Success 200 {object} domain.LoginResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
func (h *Handler) AuthLogin(c echo.Context) error { func (h *Handler) AuthLogin(c echo.Context) error {
username := c.FormValue("username") username := c.FormValue("username")
password := c.FormValue("password") password := c.FormValue("password")
@ -144,10 +144,10 @@ func (h *Handler) createAdminToken(c echo.Context, password string) error {
// @Summary Generates a new token // @Summary Generates a new token
// @Router /v1/users/refreshToken [post] // @Router /v1/users/refreshToken [post]
// @Param request body domain.RefreshTokenRequest true "body" // @Param request body domain.RefreshTokenRequest true "body"
// @Tags Users // @Tags Users
// @Success 200 {object} domain.LoginResponse // @Success 200 {object} domain.LoginResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer // @Security Bearer
func (h *Handler) RefreshJwtToken(c echo.Context) error { func (h *Handler) RefreshJwtToken(c echo.Context) error {
_, err := h.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) _, err := h.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate)
@ -193,15 +193,16 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error {
}) })
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
// @Router /v1/users/scopes/add [post] // @Router /v1/users/scopes/add [post]
// @Param request body domain.UpdateScopesRequest true "body" // @Param request body domain.UpdateScopesRequest true "body"
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer
func (h *Handler) AddScopes(c echo.Context) error { func (h *Handler) AddScopes(c echo.Context) error {
_, err := h.ValidateJwtToken(c, domain.ScopeAll) _, err := h.ValidateJwtToken(c, domain.ScopeAll)
if err != nil { if err != nil {
@ -224,15 +225,16 @@ func (h *Handler) AddScopes(c echo.Context) error {
}) })
} }
// @Summary Adds a new scope to a user account // @Summary Adds a new scope to a user account
// @Router /v1/users/scopes/remove [post] // @Router /v1/users/scopes/remove [post]
// @Param request body domain.UpdateScopesRequest true "body" // @Param request body domain.UpdateScopesRequest true "body"
// @Tags Users // @Tags Users
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} domain.BaseResponse // @Success 200 {object} domain.BaseResponse
// @Failure 400 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse
// @Failure 500 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse
// @Security Bearer
func (h *Handler) RemoveScopes(c echo.Context) error { func (h *Handler) RemoveScopes(c echo.Context) error {
token, err := h.getJwtTokenFromContext(c) token, err := h.getJwtTokenFromContext(c)
if err != nil { if err != nil {