feat(api): implement new api handler

This commit is contained in:
nils måsén 2023-10-21 19:35:41 +02:00
parent 72e437f173
commit 47091761a5
17 changed files with 571 additions and 294 deletions

View file

@ -0,0 +1,24 @@
package middleware
import (
"fmt"
. "github.com/containrrr/watchtower/pkg/api/prelude"
)
// RequireToken returns a prelude.Middleware that checks token validity
func RequireToken(token string) Middleware {
return func(next HandlerFunc) HandlerFunc {
want := fmt.Sprintf("Bearer %s", token)
return func(c *Context) Response {
auth := c.Request.Header.Get("Authorization")
if auth == "" {
return Error(ErrMissingToken)
}
if auth != want {
return Error(ErrInvalidToken)
}
return next(c)
}
}
}