wip: add api auth and /resume endpoint
This commit is contained in:
parent
22e2f6005f
commit
aaec8ec08d
23 changed files with 1244 additions and 271 deletions
30
internal/delivery/http/v1/middleware.go
Normal file
30
internal/delivery/http/v1/middleware.go
Normal 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")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue