Documentation ¶
Overview ¶
Package client contains functions to add and retrieve client from context
Index ¶
- Constants
- Variables
- func BuildCmdConfig(authInfo *api.AuthInfo, cfg *rest.Config) clientcmd.ClientConfig
- func Client(ctx context.Context) client.Client
- func Cluster(ctx context.Context) cluster.Cluster
- func DirectClient(ctx context.Context) client.Client
- func DynamicClient(ctx context.Context) (dynamic.Interface, error)
- func DynamicSubjectReviewFilter(ctx context.Context, resourceAttGetter ResourceAttributeGetter) restful.FilterFunction
- func FromBearerToken(req *restful.Request, baseConfig GetBaseConfigFunc) (config *rest.Config, err error)
- func GetAppConfig(ctx context.Context) *rest.Config
- func GetCEClient(ctx context.Context) cloudevents.Client
- func GetCachedOptions() *client.GetOptions
- func GetDefaultTransport() http.RoundTripper
- func GetToken(req *restful.Request) (token string)
- func ImpersonateFilter(ctx context.Context) restful.FilterFunction
- func ImpersonateUser(req *http.Request) user.Info
- func InsecureSkipVerifyOption(c *http.Client)
- func ListCachedOptions() *client.ListOptions
- func ManagerFilter(ctx context.Context, mgr *Manager) restful.FilterFunction
- func NewHTTPClient(options ...HttpClientOption) *http.Client
- func RequestSubjectAccessReview(ctx context.Context, clt client.Client, resourceAtt authv1.ResourceAttributes) error
- func SelfSubjectReviewFilterForResource(ctx context.Context, resourceAtt authv1.ResourceAttributes, ...) restful.FilterFunctiondeprecated
- func SubjectReviewFilterForResource(ctx context.Context, resourceAtt authv1.ResourceAttributes, ...) restful.FilterFunction
- func User(ctx context.Context) user.Info
- func UserFromBearerToken(rawToken string) (user.Info, error)
- func WithAppConfig(ctx context.Context, cfg *rest.Config) context.Context
- func WithCEClient(ctx context.Context, ceClient cloudevents.Client) context.Context
- func WithClient(ctx context.Context, clt client.Client) context.Context
- func WithCluster(ctx context.Context, client cluster.Cluster) context.Context
- func WithCtxManagerFilters(ctx context.Context, ws *restful.WebService) error
- func WithDirectClient(ctx context.Context, clt client.Client) context.Context
- func WithDynamicClient(ctx context.Context, client dynamic.Interface) context.Context
- func WithManager(ctx context.Context, mgr *Manager) context.Context
- type GetBaseConfigFunc
- type GetConfigFunc
- type GetOptions
- type GetResourceAttributesFunc
- type HttpClientOption
- type ListOptions
- type Manager
- type NewClusterRegistryClientFunc
- type ResourceAttributeGetter
- type SubjectAccessReviewClientGetter
Constants ¶
const ( // UserConfigName configuration/context for user UserConfigName = "UserConfig" // AuthorizationHeader authorization header for http requests AuthorizationHeader = "Authorization" // BearerPrefix bearer token prefix for token BearerPrefix = "Bearer " // QueryParameterTokenName authorization token for http requests QueryParameterTokenName = "token" )
Variables ¶
var ( DefaultTimeout = 10 * time.Second DefaultQPS float32 = 50.0 DefaultBurst = 60 )
var WithUser = request.WithUser
WithUser set User into context
Functions ¶
func BuildCmdConfig ¶
func DirectClient ¶
DirectClient returns a client.Client in a given context. Returns nil if not found
func DynamicClient ¶
DynamicClient returns a dynamic client.Client, returns nil if not found
func DynamicSubjectReviewFilter ¶ added in v0.7.0
func DynamicSubjectReviewFilter(ctx context.Context, resourceAttGetter ResourceAttributeGetter) restful.FilterFunction
DynamicSubjectReviewFilter makes a subject review and the ResourceAttribute can be dynamically obtained
func FromBearerToken ¶
func FromBearerToken(req *restful.Request, baseConfig GetBaseConfigFunc) (config *rest.Config, err error)
FromBearerToken retrieves config based on the bearer token
func GetAppConfig ¶ added in v0.7.0
GetAppConfig gets the current config of app (pod) from the context.
func GetCEClient ¶ added in v0.8.0
func GetCEClient(ctx context.Context) cloudevents.Client
GetCEClient gets cloudevents client from the context.
func GetCachedOptions ¶ added in v0.7.0
func GetCachedOptions() *client.GetOptions
GetCachedOptions returns GetOptions with ResourceVersion set to 0
func GetDefaultTransport ¶ added in v0.3.0
func GetDefaultTransport() http.RoundTripper
func GetToken ¶
func GetToken(req *restful.Request) (token string)
GetToken get token from request headers or request query parameters. return emtry if no token find
func ImpersonateFilter ¶ added in v0.7.0
ImpersonateFilter will inject current user into context and inject impersonate information into rest.Config in request
func InsecureSkipVerifyOption ¶ added in v0.8.0
InsecureSkipVerifyOption is a HttpClientOption that disables SSL certificate verification.
func ListCachedOptions ¶ added in v0.13.0
func ListCachedOptions() *client.ListOptions
ListCachedOptions returns ListOptions with ResourceVersion set to 0
func ManagerFilter ¶
ManagerFilter generates filter based on a manager to create a config based in a request and injects into context
func NewHTTPClient ¶ added in v0.3.0
func NewHTTPClient(options ...HttpClientOption) *http.Client
func RequestSubjectAccessReview ¶ added in v0.9.0
func RequestSubjectAccessReview(ctx context.Context, clt client.Client, resourceAtt authv1.ResourceAttributes) error
RequestSubjectAccessReview request the SubjectAccessReview resource to check whether it has permission.
func SelfSubjectReviewFilterForResource
deprecated
func SelfSubjectReviewFilterForResource(ctx context.Context, resourceAtt authv1.ResourceAttributes, namespaceParameter, nameParameter string) restful.FilterFunction
SelfSubjectReviewFilterForResource makes a self subject review based a configuration already present inside the request context using the user's bearer token
Deprecated: use SubjectReviewFilterForResource
func SubjectReviewFilterForResource ¶ added in v0.7.0
func SubjectReviewFilterForResource(ctx context.Context, resourceAtt authv1.ResourceAttributes, namespaceParameter, nameParameter string) restful.FilterFunction
SubjectReviewFilterForResource makes a self subject review based a configuration already present inside the request context using the user's bearer token also, it makes a subject review based on Impersonate User info in request header
func UserFromBearerToken ¶ added in v0.9.0
func WithAppConfig ¶ added in v0.7.0
WithAppConfig associates a given config with the app context.
func WithCEClient ¶ added in v0.8.0
WithCEClient associates a given cloudevents client with the cloudevent client
func WithClient ¶
WithClient sets a client instance into a context
func WithCluster ¶
WithCluster sets a cluster.Cluster instance into a context
func WithCtxManagerFilters ¶ added in v0.7.0
WithCtxManagerFilters put the manager in the context into the webservice.
func WithDirectClient ¶
WithDirectClient sets a client instance into a context
func WithDynamicClient ¶
WithDynamicClient sets a dynamic.Interface client instance into a context
Types ¶
type GetBaseConfigFunc ¶
type GetConfigFunc ¶
type GetConfigFunc func(req *restful.Request, baseConfig GetBaseConfigFunc) (*rest.Config, error)
GetConfigFunc retrieves a configuration based on a request
type GetOptions ¶ added in v0.7.0
type GetOptions struct {
client.GetOptions
}
GetOptions is a wrapper for client.GetOptions
func NewGetOptions ¶ added in v0.7.0
func NewGetOptions() *GetOptions
NewGetOptions returns a new GetOptions
func (*GetOptions) Build ¶ added in v0.7.0
func (opt *GetOptions) Build() *client.GetOptions
Build returns the client.GetOptions
func (*GetOptions) WithCached ¶ added in v0.7.0
func (opt *GetOptions) WithCached() *GetOptions
WithCached set the ResourceVersion to 0
type GetResourceAttributesFunc ¶ added in v0.7.0
type GetResourceAttributesFunc func(ctx context.Context, req *restful.Request) (authv1.ResourceAttributes, error)
GetResourceAttributesFunc helper function to warp a function to ResourceAttributeGetter
func (GetResourceAttributesFunc) GetResourceAttributes ¶ added in v0.7.0
func (p GetResourceAttributesFunc) GetResourceAttributes(ctx context.Context, req *restful.Request) (authv1.ResourceAttributes, error)
type HttpClientOption ¶ added in v0.8.0
HttpClientOption is a function that configures a http.Client.
type ListOptions ¶ added in v0.13.0
type ListOptions struct {
client.ListOptions
}
ListOptions is a wrapper for client.ListOptions
func NewListOptions ¶ added in v0.13.0
func NewListOptions() *ListOptions
NewListOptions returns a new ListOptions
func (*ListOptions) Build ¶ added in v0.13.0
func (opt *ListOptions) Build() *client.ListOptions
Build returns the client.ListOptions
func (*ListOptions) WithCached ¶ added in v0.13.0
func (opt *ListOptions) WithCached() *ListOptions
WithCached set the ResourceVersion to 0
func (*ListOptions) WithLimit ¶ added in v0.13.0
func (opt *ListOptions) WithLimit(limit int64) *ListOptions
WithLimit set the limit
func (*ListOptions) WithNamespace ¶ added in v0.13.0
func (opt *ListOptions) WithNamespace(namespace string) *ListOptions
WithNamespace set the namespace
func (*ListOptions) WithUnsafeDisableDeepCopy ¶ added in v0.13.0
func (opt *ListOptions) WithUnsafeDisableDeepCopy() *ListOptions
WithUnsafeDisableDeepCopy set the UnsafeDisableDeepCopy to true
type Manager ¶
type Manager struct { // GetConfig retrieves a configuration based on a request GetConfig GetConfigFunc // GetBasicConfig retrieves a configuration based on a request GetBasicConfig GetBaseConfigFunc // NewClusterRegistryClient constructs a multi cluster client based on the specified config. NewClusterRegistryClient NewClusterRegistryClientFunc *zap.SugaredLogger }
Manager dynamically generates client based on user requests
func ManagerCtx ¶
ManagerCtx returns a *Manager in a given context. Returns nil if not found
func NewManager ¶
func NewManager(ctx context.Context, get GetConfigFunc, baseConfig GetBaseConfigFunc, newClusterRegistryClient NewClusterRegistryClientFunc) *Manager
NewManager initializes a new manager based on func
type NewClusterRegistryClientFunc ¶ added in v0.10.0
type NewClusterRegistryClientFunc func(*rest.Config) (multicluster.Interface, error)
NewClusterRegistryClientFunc constructs a multi cluster client based on the specified config.
type ResourceAttributeGetter ¶ added in v0.7.0
type ResourceAttributeGetter interface { // GetResourceAttributes get resource attributes from request GetResourceAttributes(ctx context.Context, req *restful.Request) (authv1.ResourceAttributes, error) }
ResourceAttributeGetter describe an interface to get resource attributes form request
type SubjectAccessReviewClientGetter ¶ added in v0.7.0
type SubjectAccessReviewClientGetter interface { // GetClient get k8s client according to request GetClient(ctx context.Context, req *restful.Request) (client.Client, error) }
SubjectAccessReviewClientGetter describe an interface to get client for subject access review It is usually used for cross-cluster authentication.