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

Method claimsToContext

auth/instance_middleware.go:154–179  ·  view source on GitHub ↗
(ctx context.Context, claims *InstanceJWTClaims)

Source from the content-addressed store, hash-verified

152}
153
154func (amw *instanceMiddleware) claimsToContext(ctx context.Context, claims *InstanceJWTClaims) (context.Context, error) {
155 if claims == nil {
156 slog.InfoContext(ctx, "no claims for instance")
157 return ctx, runnerErrors.ErrUnauthorized
158 }
159
160 if claims.Name == "" {
161 slog.ErrorContext(ctx, "no name in calaims")
162 return nil, runnerErrors.ErrUnauthorized
163 }
164
165 instanceInfo, err := amw.store.GetInstance(ctx, claims.Name)
166 if err != nil {
167 slog.ErrorContext(ctx, "failed to get instance", "error", err)
168 return ctx, runnerErrors.ErrUnauthorized
169 }
170
171 entity, err := getForgeEntityFromInstance(ctx, amw.store, instanceInfo)
172 if err != nil {
173 slog.ErrorContext(ctx, "failed to get entity from instance", "error", err)
174 return ctx, runnerErrors.ErrUnauthorized
175 }
176
177 ctx = PopulateInstanceContext(ctx, instanceInfo, entity, claims)
178 return ctx, nil
179}
180
181// Middleware implements the middleware interface
182func (amw *instanceMiddleware) Middleware(next http.Handler) http.Handler {

Callers 1

MiddlewareMethod · 0.95

Calls 3

PopulateInstanceContextFunction · 0.85
GetInstanceMethod · 0.65

Tested by

no test coverage detected