CI step for static check (#467)

* CI step for static check

* fix staticcheck
This commit is contained in:
David Zhao
2022-02-24 23:07:15 -08:00
committed by GitHub
parent 778d1aa141
commit 130decbf1d
6 changed files with 19 additions and 15 deletions
+8 -3
View File
@@ -15,10 +15,11 @@ import (
const (
authorizationHeader = "Authorization"
bearerPrefix = "Bearer "
grantsKey = "grants"
accessTokenParam = "access_token"
)
type grantsKey struct{}
var (
ErrPermissionDenied = errors.New("permissions denied")
)
@@ -75,20 +76,24 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
// set grants in context
ctx := r.Context()
r = r.WithContext(context.WithValue(ctx, grantsKey, grants))
r = r.WithContext(context.WithValue(ctx, grantsKey{}, grants))
}
next.ServeHTTP(w, r)
}
func GetGrants(ctx context.Context) *auth.ClaimGrants {
claims, ok := ctx.Value(grantsKey).(*auth.ClaimGrants)
claims, ok := ctx.Value(grantsKey{}).(*auth.ClaimGrants)
if !ok {
return nil
}
return claims
}
func WithGrants(ctx context.Context, grants *auth.ClaimGrants) context.Context {
return context.WithValue(ctx, grantsKey{}, grants)
}
func SetAuthorizationToken(r *http.Request, token string) {
r.Header.Set(authorizationHeader, bearerPrefix+token)
}