Add some basic auth
This commit is contained in:
parent
66b46ae0ab
commit
0883fcd5cd
24 changed files with 1687 additions and 674 deletions
34
auth/init_required.go
Normal file
34
auth/init_required.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"runner-manager/apiserver/params"
|
||||
"runner-manager/database/common"
|
||||
)
|
||||
|
||||
// NewjwtMiddleware returns a populated jwtMiddleware
|
||||
func NewInitRequiredMiddleware(store common.Store) (Middleware, error) {
|
||||
return &initRequired{
|
||||
store: store,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type initRequired struct {
|
||||
store common.Store
|
||||
}
|
||||
|
||||
// Middleware implements the middleware interface
|
||||
func (i *initRequired) Middleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctrlInfo, err := i.store.ControllerInfo()
|
||||
if err != nil || ctrlInfo.ControllerID.String() == "" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
json.NewEncoder(w).Encode(params.InitializationRequired)
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue