mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-04 13:22:41 +08:00
use non-string context key
This commit is contained in:
@@ -16,7 +16,12 @@ import (
|
|||||||
authorizationv1 "k8s.io/api/authorization/v1"
|
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) {
|
func getBearerToken(ctx context.Context) (*string, bool) {
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
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 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) {
|
func IsAuthorized(c *v1.Client, namespace, verb, group, resource, name string) (allowed bool, err error) {
|
||||||
|
@@ -11,5 +11,5 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getClient(ctx context.Context) *v1.Client {
|
func getClient(ctx context.Context) *v1.Client {
|
||||||
return ctx.Value(auth.ClientContextKey).(*v1.Client)
|
return ctx.Value(auth.ContextClientKey).(*v1.Client)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user