client

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 33 Imported by: 1

Documentation

Overview

Package client contains functions to add and retrieve client from context

Index

Constants

View Source
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

View Source
var (
	DefaultTimeout         = 10 * time.Second
	DefaultQPS     float32 = 50.0
	DefaultBurst           = 60
)
View Source
var WithUser = request.WithUser

WithUser set User into context

Functions

func BuildCmdConfig

func BuildCmdConfig(authInfo *api.AuthInfo, cfg *rest.Config) clientcmd.ClientConfig

func Client

func Client(ctx context.Context) client.Client

Client returns a client.Client in a given context. Returns nil if not found

func Cluster

func Cluster(ctx context.Context) cluster.Cluster

Cluster returns a cluster.Cluster, returns nil if not found

func DirectClient

func DirectClient(ctx context.Context) client.Client

DirectClient returns a client.Client in a given context. Returns nil if not found

func DynamicClient

func DynamicClient(ctx context.Context) (dynamic.Interface, error)

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

func GetAppConfig(ctx context.Context) *rest.Config

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

func ImpersonateFilter(ctx context.Context) restful.FilterFunction

ImpersonateFilter will inject current user into context and inject impersonate information into rest.Config in request

func ImpersonateUser added in v0.8.0

func ImpersonateUser(req *http.Request) user.Info

func InsecureSkipVerifyOption added in v0.8.0

func InsecureSkipVerifyOption(c *http.Client)

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

func ManagerFilter(ctx context.Context, mgr *Manager) restful.FilterFunction

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 User added in v0.7.0

func User(ctx context.Context) user.Info

User returns a user.Info, returns nil if not found

func UserFromBearerToken added in v0.9.0

func UserFromBearerToken(rawToken string) (user.Info, error)

func WithAppConfig added in v0.7.0

func WithAppConfig(ctx context.Context, cfg *rest.Config) context.Context

WithAppConfig associates a given config with the app context.

func WithCEClient added in v0.8.0

func WithCEClient(ctx context.Context, ceClient cloudevents.Client) context.Context

WithCEClient associates a given cloudevents client with the cloudevent client

func WithClient

func WithClient(ctx context.Context, clt client.Client) context.Context

WithClient sets a client instance into a context

func WithCluster

func WithCluster(ctx context.Context, client cluster.Cluster) context.Context

WithCluster sets a cluster.Cluster instance into a context

func WithCtxManagerFilters added in v0.7.0

func WithCtxManagerFilters(ctx context.Context, ws *restful.WebService) error

WithCtxManagerFilters put the manager in the context into the webservice.

func WithDirectClient

func WithDirectClient(ctx context.Context, clt client.Client) context.Context

WithDirectClient sets a client instance into a context

func WithDynamicClient

func WithDynamicClient(ctx context.Context, client dynamic.Interface) context.Context

WithDynamicClient sets a dynamic.Interface client instance into a context

func WithManager

func WithManager(ctx context.Context, mgr *Manager) context.Context

WithManager sets a manager instance into a context

Types

type GetBaseConfigFunc

type GetBaseConfigFunc func() (*rest.Config, error)

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

type HttpClientOption func(*http.Client)

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

func ManagerCtx(ctx context.Context) *Manager

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

func (*Manager) Filter

func (m *Manager) Filter(ctx context.Context) restful.FilterFunction

Filter returns a filter to be used in

func (*Manager) Filters added in v0.7.0

func (m *Manager) Filters(ctx context.Context) (filters []restful.FilterFunction, err error)

Filters returns manager.Filter with ImpersonateFilter

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL