(ctx context.Context, claims *InstanceJWTClaims)
| 152 | } |
| 153 | |
| 154 | func (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 |
| 182 | func (amw *instanceMiddleware) Middleware(next http.Handler) http.Handler { |
no test coverage detected