use non-string context key

This commit is contained in:
rushtehrani
2020-06-08 15:43:31 -07:00
parent 601541ebbf
commit 4c4d01ed09
2 changed files with 8 additions and 3 deletions

View File

@@ -16,7 +16,12 @@ import (
authorizationv1 "k8s.io/api/authorization/v1"
)
const ClientContextKey = "client"
type key int
const (
// ContextClientKey is the key used to identify the Client value in Context
ContextClientKey key = iota
)
func getBearerToken(ctx context.Context) (*string, bool) {
md, ok := metadata.FromIncomingContext(ctx)
@@ -60,7 +65,7 @@ func getClient(ctx context.Context, kubeConfig *v1.Config, db *v1.DB) (context.C
return nil, err
}
return context.WithValue(ctx, ClientContextKey, client), nil
return context.WithValue(ctx, ContextClientKey, client), nil
}
func IsAuthorized(c *v1.Client, namespace, verb, group, resource, name string) (allowed bool, err error) {