mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-17 04:38:06 +01:00
feat(api): implement new api handler
This commit is contained in:
parent
72e437f173
commit
47091761a5
17 changed files with 571 additions and 294 deletions
24
pkg/api/middleware/require_token.go
Normal file
24
pkg/api/middleware/require_token.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue