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": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -234,6 +239,11 @@ const docTemplate = `{
},
"/v1/discord/webhooks/by/serverAndChannel": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -281,6 +291,11 @@ const docTemplate = `{
},
"/v1/discord/webhooks/new": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -369,6 +384,11 @@ const docTemplate = `{
},
"/v1/discord/webhooks/{ID}/disable": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -406,6 +426,11 @@ const docTemplate = `{
},
"/v1/discord/webhooks/{ID}/enable": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -424,6 +449,11 @@ const docTemplate = `{
},
"/v1/discord/webhooks/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -810,14 +840,33 @@ const docTemplate = `{
"summary": "Marks a source as deleted based on its ID value.",
"parameters": [
{
"type": "string",
"type": "integer",
"description": "id",
"name": "id",
"in": "path",
"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": {
@ -1036,6 +1085,11 @@ const docTemplate = `{
},
"/v1/users/scopes/add": {
"post": {
"security": [
{
"Bearer": []
}
],
"consumes": [
"application/json"
],
@ -1081,6 +1135,11 @@ const docTemplate = `{
},
"/v1/users/scopes/remove": {
"post": {
"security": [
{
"Bearer": []
}
],
"consumes": [
"application/json"
],

View File

@ -194,6 +194,11 @@
},
"/v1/discord/webhooks": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -225,6 +230,11 @@
},
"/v1/discord/webhooks/by/serverAndChannel": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -272,6 +282,11 @@
},
"/v1/discord/webhooks/new": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -360,6 +375,11 @@
},
"/v1/discord/webhooks/{ID}/disable": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -397,6 +417,11 @@
},
"/v1/discord/webhooks/{ID}/enable": {
"post": {
"security": [
{
"Bearer": []
}
],
"tags": [
"DiscordWebhook"
],
@ -415,6 +440,11 @@
},
"/v1/discord/webhooks/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
@ -801,14 +831,33 @@
"summary": "Marks a source as deleted based on its ID value.",
"parameters": [
{
"type": "string",
"type": "integer",
"description": "id",
"name": "id",
"in": "path",
"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": {
@ -1027,6 +1076,11 @@
},
"/v1/users/scopes/add": {
"post": {
"security": [
{
"Bearer": []
}
],
"consumes": [
"application/json"
],
@ -1072,6 +1126,11 @@
},
"/v1/users/scopes/remove": {
"post": {
"security": [
{
"Bearer": []
}
],
"consumes": [
"application/json"
],

View File

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

View File

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