wip: add api auth and /resume endpoint

This commit is contained in:
cătălin 2023-12-04 22:13:37 +01:00
commit aaec8ec08d
Signed by: catalin
GPG key ID: 0178DF42F43E5FD2
23 changed files with 1244 additions and 271 deletions

View file

@ -0,0 +1,30 @@
package v1
import (
"errors"
"github.com/gin-gonic/gin"
)
func containsValue(m map[string]string, value string) (string, error) {
for _, v := range m {
if v == value {
return v, nil
}
}
return value, errors.New("value is not in the provided map")
}
func (h *Handler) VerifyAuthentication(ctx *gin.Context) (string, error) {
header := ctx.GetHeader("X-API-KEY")
if header != "" {
return containsValue(h.services.Config.Auth.ApiKeys, header)
}
key := ctx.Query("api_key")
if key != "" {
return containsValue(h.services.Config.Auth.ApiKeys, key)
}
return "", errors.New("Missing API key")
}