(ctx context.Context, claims *InstanceJWTClaims)
| 69 | } |
| 70 | |
| 71 | func (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 |
| 96 | func (amw *agentMiddleware) Middleware(next http.Handler) http.Handler { |
no test coverage detected