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

Method claimsToContext

auth/agent_middleware.go:71–93  ·  view source on GitHub ↗
(ctx context.Context, claims *InstanceJWTClaims)

Source from the content-addressed store, hash-verified

69}
70
71func (amw *agentMiddleware) claimsToContext(ctx context.Context, claims *InstanceJWTClaims) (context.Context, error) {
72 if claims == nil {
73 return ctx, runnerErrors.ErrUnauthorized
74 }
75
76 if claims.Name == "" {
77 return nil, runnerErrors.ErrUnauthorized
78 }
79
80 instanceInfo, err := amw.store.GetInstance(ctx, claims.Name)
81 if err != nil {
82 return ctx, runnerErrors.ErrUnauthorized
83 }
84
85 entity, err := getForgeEntityFromInstance(ctx, amw.store, instanceInfo)
86 if err != nil {
87 slog.ErrorContext(ctx, "failed to get entity from instance", "error", err)
88 return ctx, runnerErrors.ErrUnauthorized
89 }
90
91 ctx = PopulateInstanceContext(ctx, instanceInfo, entity, claims)
92 return ctx, nil
93}
94
95// Middleware implements the middleware interface
96func (amw *agentMiddleware) 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