Documentation ¶
Overview ¶
Package base contains functions to add and retrieve auth from context
Index ¶
- Constants
- func AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- func GetSubResourcesOptionsFromRequest(req *restful.Request) (opts metav1alpha1.SubResourcesOptions)
- func IsNotImplementedError(err error) bool
- func MetaFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- type Auth
- func (a *Auth) Basic() (AuthMethod, error)
- func (a *Auth) BearerToken(attribute string) (AuthMethod, error)
- func (a *Auth) Get(attribute string) (string, error)
- func (a *Auth) GetBasicInfo() (userName string, password string, err error)
- func (a *Auth) GetDynamicInfo() (ak string, sk string, err error)
- func (a *Auth) GetOAuth2Token() (string, error)
- func (a *Auth) Header(attribute string, header string) (AuthMethod, error)
- func (a *Auth) HeaderWithPrefix(attribute string, header string, prefix string) (AuthMethod, error)
- func (a *Auth) IsBasic() bool
- func (a *Auth) IsDynamic() bool
- func (a *Auth) IsOAuth2() bool
- func (a *Auth) OAuth2() (AuthMethod, error)
- func (a *Auth) Query(attribute string, query string) (AuthMethod, error)
- func (a *Auth) WithContext(ctx context.Context) context.Context
- type AuthMethod
- type BuildOptions
- type Client
- type Meta
- type OptionFunc
- func BodyOpts(body interface{}) OptionFunc
- func DefaultOptions() []OptionFunc
- func DoNotParseResponseOpts() OptionFunc
- func ErrorOpts(err interface{}) OptionFunc
- func HeaderOpts(key, value string) OptionFunc
- func ListOpts(opts metav1alpha1.ListOptions) OptionFunc
- func MetaOpts(meta Meta) OptionFunc
- func QueryOpts(params map[string]string) OptionFunc
- func ResultOpts(dest interface{}) OptionFunc
- func SecretOpts(secret corev1.Secret) OptionFunc
- func SubResourcesOpts(subResources []string) OptionFunc
- type PluginClient
- func (p *PluginClient) Clone() *PluginClient
- func (p *PluginClient) Delete(ctx context.Context, baseURL *duckv1.Addressable, path string, ...) error
- func (p *PluginClient) FullUrl(address *duckv1.Addressable, uri string) string
- func (p *PluginClient) Get(ctx context.Context, baseURL *duckv1.Addressable, path string, ...) error
- func (p *PluginClient) GetMeta() Meta
- func (p *PluginClient) GetResponse(ctx context.Context, baseURL *duckv1.Addressable, path string, ...) (*resty.Response, error)
- func (p *PluginClient) GetSecret() corev1.Secret
- func (p *PluginClient) HandleError(response *resty.Response, err error) error
- func (p *PluginClient) Post(ctx context.Context, baseURL *duckv1.Addressable, path string, ...) error
- func (p *PluginClient) Put(ctx context.Context, baseURL *duckv1.Addressable, path string, ...) error
- func (p *PluginClient) R(ctx context.Context, options ...OptionFunc) *resty.Request
- func (p *PluginClient) WithClassAddress(classAddress *duckv1.Addressable) *PluginClient
- func (p *PluginClient) WithMeta(meta Meta) *PluginClient
- func (p *PluginClient) WithRequestOptions(opts ...OptionFunc) *PluginClient
- func (p *PluginClient) WithSecret(secret corev1.Secret) *PluginClient
- type ResponseStatusErr
Constants ¶
const ( OAuth2KeyAccessToken = "accessToken" AuthHeaderAuthorization = "Authorization" AuthPrefixBearer = "Bearer" // OAuth2ClientIDKey is the key of the clientID for AuthTypeOAuth2 secrets OAuth2ClientIDKey = "clientID" // OAuth2ClientSecretKey is the key of the clientSecret for AuthTypeOAuth2 secrets OAuth2ClientSecretKey = "clientSecret" // OAuth2CodeKey is the key of the code for AuthTypeOAuth2 secrets OAuth2CodeKey = "code" // OAuth2AccessTokenKeyKey is the key of the accessTokenKey for AuthTypeOAuth2 secrets OAuth2AccessTokenKeyKey = "accessTokenKey" // OAuth2AccessTokenKey is the key of the accessToken for AuthTypeOAuth2 secrets OAuth2AccessTokenKey = "accessToken" // OAuth2ScopeKey is the key of the scope for AuthTypeOAuth2 secrets OAuth2ScopeKey = "scope" // OAuth2RefreshTokenKey is the key of the refreshToken for AuthTypeOAuth2 secrets OAuth2RefreshTokenKey = "refreshToken" // OAuth2ExpiresInKey is the key of the expiresIn for AuthTypeOAuth2 secrets OAuth2CreatedAtKey = "createdAt" // OAuth2ExpiresInKey is the key of the expiresIn for AuthTypeOAuth2 secrets OAuth2ExpiresInKey = "expiresIn" // OAuth2RedirectURLKey is the key of the redirectURL for AuthTypeOAuth2 secrets OAuth2RedirectURLKey = "redirectURL" // OAuth2BaseURLKey is the key of the baseURL for AuthTypeOAuth2 secrets OAuth2BaseURLKey = "baseURL" // DynamicUsernameKey is the key of the username for dynamic secrets. DynamicUsernameKey = corev1.BasicAuthUsernameKey // DynamicPasswordKey is the key of the password for dynamic secrets. DynamicPasswordKey = corev1.BasicAuthPasswordKey // DynamicClientKeyKey is the key of the clientKey for dynamic secret DynamicClientKeyKey = "key" // DynamicClientSecretKey is the key of the clientSecret for dynamic secret DynamicClientSecretKey = "secret" // redefine key for dynamic token reflush. DynamicAccessTokenKey = OAuth2AccessTokenKey DynamicRefreshTokenKey = OAuth2RefreshTokenKey DynamicCreatedAtKey = OAuth2CreatedAtKey DynamicExpiresInKey = OAuth2ExpiresInKey DynamicBaseURLKey = OAuth2BaseURLKey )
const ( // PluginAuthHeader header for auth type (kubernetes secret type) PluginAuthHeader = "X-Plugin-Auth" // PluginSecretHeader header to store data part of the secret PluginSecretHeader = "X-Plugin-Secret" )
const ( // PluginMetaHeader header to store metadata for the plugin PluginMetaHeader = "X-Plugin-Meta" // PluginSubresourcesHeader subresources header parameter // used as a header to avoid overloading the url query parameters // and any url length limits PluginSubresourcesHeader = "X-Subresources" )
Variables ¶
This section is empty.
Functions ¶
func AuthFilter ¶
func AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
AuthFilter auth filter for go restful, parsing plugin auth
func GetSubResourcesOptionsFromRequest ¶
func GetSubResourcesOptionsFromRequest(req *restful.Request) (opts metav1alpha1.SubResourcesOptions)
GetSubResourcesOptionsFromRequest returns SubResourcesOptions based on a request
func IsNotImplementedError ¶
IsNotImplementedError returns true if the plugin not implement the specified interface
func MetaFilter ¶
func MetaFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
MetaFilter meta filter for go restful, parsing plugin meta
Types ¶
type Auth ¶
type Auth struct { // Type secret type as in kubernetes secret.type Type v1alpha1.AuthType `json:"type"` // Secret 's data value extracted from kubernetes Secret map[string][]byte `json:"data"` }
Auth plugin auth
func AuthFromRequest ¶
func ExtractAuth ¶
ExtractAuth extract auth from a specific context
func (*Auth) BearerToken ¶
func (a *Auth) BearerToken(attribute string) (AuthMethod, error)
BearerToken return an bearer token auth method
func (*Auth) GetBasicInfo ¶
GetBasicInfo get basic auth username and password
func (*Auth) GetDynamicInfo ¶
GetDynamicInfo get dynamic auth ak and sk
func (*Auth) GetOAuth2Token ¶
GetOAuth2Token get oauth2 access token
func (*Auth) Header ¶
func (a *Auth) Header(attribute string, header string) (AuthMethod, error)
Header return an auth method which could append to header with specific attribute
func (*Auth) HeaderWithPrefix ¶
HeaderWithPrefix return an auth method which could append to header with specific attribute and prefix
func (*Auth) OAuth2 ¶
func (a *Auth) OAuth2() (AuthMethod, error)
OAuth2 return an oauth2 auth method
type AuthMethod ¶
type AuthMethod func(request *resty.Request)
type BuildOptions ¶
type BuildOptions func(client *PluginClient)
BuildOptions Options to build the plugin client
func ClientOpts ¶
func ClientOpts(clt *resty.Client) BuildOptions
ClientOpts adds a custom client build options for plugin client
type Client ¶
type Client interface { Get(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error GetResponse(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) (*resty.Response, error) Post(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error Put(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error Delete(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error }
Client interface for PluginClient, client code should use the interface as dependency
type Meta ¶
type Meta struct { Version string `json:"version,omitempty"` BaseURL string `json:"baseURL,omitempty"` }
Meta Plugin meta with base url and version info, for calling plugin api
func MetaFromRequest ¶
type OptionFunc ¶
type OptionFunc func(request *resty.Request)
OptionFunc options for requests
func DefaultOptions ¶
func DefaultOptions() []OptionFunc
DefaultOptions for default plugin client options
func DoNotParseResponseOpts ¶
func DoNotParseResponseOpts() OptionFunc
DoNotParseResponseOpts do not parse response
func QueryOpts ¶
func QueryOpts(params map[string]string) OptionFunc
QueryOpts query parameters for the request
func ResultOpts ¶
func ResultOpts(dest interface{}) OptionFunc
ResultOpts request result automatically marshalled into object
func SecretOpts ¶
func SecretOpts(secret corev1.Secret) OptionFunc
SecretOpts provides a secret to be assigned to the request in the header
func SubResourcesOpts ¶
func SubResourcesOpts(subResources []string) OptionFunc
SubResourcesOpts set subresources header for the request
type PluginClient ¶
type PluginClient struct { // ClassAddress is the address of the integration class // +optional ClassAddress *duckv1.Addressable // contains filtered or unexported fields }
PluginClient client for plugins
func NewPluginClient ¶
func NewPluginClient(opts ...BuildOptions) *PluginClient
NewPluginClient creates a new plugin client
func (*PluginClient) Clone ¶
func (p *PluginClient) Clone() *PluginClient
Clone shallow clone the plugin client used to update some fields without changing the original
func (*PluginClient) Delete ¶
func (p *PluginClient) Delete(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error
Delete performs a DELETE request with the given parameters
func (*PluginClient) FullUrl ¶
func (p *PluginClient) FullUrl(address *duckv1.Addressable, uri string) string
func (*PluginClient) Get ¶
func (p *PluginClient) Get(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error
Get performs a GET request using defined options
func (*PluginClient) GetMeta ¶
func (p *PluginClient) GetMeta() Meta
func (*PluginClient) GetResponse ¶
func (p *PluginClient) GetResponse(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) (*resty.Response, error)
GetResponse performs a GET request using defined options and return response
func (*PluginClient) GetSecret ¶
func (p *PluginClient) GetSecret() corev1.Secret
func (*PluginClient) HandleError ¶
func (p *PluginClient) HandleError(response *resty.Response, err error) error
func (*PluginClient) Post ¶
func (p *PluginClient) Post(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error
Post performs a POST request with the given parameters
func (*PluginClient) Put ¶
func (p *PluginClient) Put(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error
Put performs a PUT request with the given parameters
func (*PluginClient) R ¶
func (p *PluginClient) R(ctx context.Context, options ...OptionFunc) *resty.Request
R prepares a request based on the given information
func (*PluginClient) WithClassAddress ¶
func (p *PluginClient) WithClassAddress(classAddress *duckv1.Addressable) *PluginClient
func (*PluginClient) WithMeta ¶
func (p *PluginClient) WithMeta(meta Meta) *PluginClient
func (*PluginClient) WithRequestOptions ¶
func (p *PluginClient) WithRequestOptions(opts ...OptionFunc) *PluginClient
WithRequestOptions set request options
func (*PluginClient) WithSecret ¶
func (p *PluginClient) WithSecret(secret corev1.Secret) *PluginClient
type ResponseStatusErr ¶
ResponseStatusErr is an error with `Status` type, used to handle plugin response
func (ResponseStatusErr) Error ¶
func (p ResponseStatusErr) Error() string
Error implements error interface, output the error message