MCPcopy Create free account
hub / github.com/cloudbase/garm / Middleware

Method Middleware

auth/init_required.go:38–53  ·  view source on GitHub ↗

Middleware implements the middleware interface

(next http.Handler)

Source from the content-addressed store, hash-verified

36
37// Middleware implements the middleware interface
38func (i *initRequired) Middleware(next http.Handler) http.Handler {
39 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
40 ctx := r.Context()
41
42 if !i.store.HasAdminUser(ctx) {
43 w.Header().Add("Content-Type", "application/json")
44 w.WriteHeader(http.StatusConflict)
45 if err := json.NewEncoder(w).Encode(params.InitializationRequired); err != nil {
46 slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
47 }
48 return
49 }
50
51 next.ServeHTTP(w, r.WithContext(ctx))
52 })
53}
54
55func NewUrlsRequiredMiddleware(store common.Store) (Middleware, error) {
56 return &urlsRequired{

Callers

nothing calls this directly

Calls 3

AddMethod · 0.80
HasAdminUserMethod · 0.65
WithContextMethod · 0.45

Tested by

no test coverage detected