Documentation
¶
Overview ¶
Package webhook implements the webhook auth mode
Index ¶
- Variables
- type CustomWebhookAuthHeadersConfig
- type CustomWebhookRequestConfig
- type CustomWebhookResponseConfig
- type RelyAuthWebhookConfig
- type WebhookAuthCustomRequestConfig
- type WebhookAuthCustomResponseConfig
- type WebhookAuthHeadersConfig
- type WebhookAuthenticator
- func (wa *WebhookAuthenticator) Authenticate(ctx context.Context, body *authmode.AuthenticateRequestData) (authmode.AuthenticatedOutput, error)
- func (wa *WebhookAuthenticator) Close() error
- func (wa WebhookAuthenticator) Equal(target WebhookAuthenticator) bool
- func (*WebhookAuthenticator) Mode() authmode.AuthMode
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMethodNotAllowed occurs when the method is neither GET nor POST. ErrMethodNotAllowed = errors.New("webhook mode must be one of GET or POST") // ErrResponseBodyRequired occurs when the response body have no content. ErrResponseBodyRequired = errors.New("response body must have content") // ErrMalformedTransformedResponseBody occurs when the transformed response body is malformed. ErrMalformedTransformedResponseBody = errors.New("malformed response body. Expected a map") )
Functions ¶
This section is empty.
Types ¶
type CustomWebhookAuthHeadersConfig ¶
type CustomWebhookAuthHeadersConfig struct {
// The headers to be forwarded from the client request.
Forward *goutils.AllOrListString
// The additional headers to be sent to the auth hook.
Additional map[string]jmes.FieldMappingEntryString
}
CustomWebhookAuthHeadersConfig represents a custom webhook auth header config.
func NewCustomWebhookAuthHeadersConfig ¶
func NewCustomWebhookAuthHeadersConfig( input *WebhookAuthHeadersConfig, getEnvFunc goenvconf.GetEnvFunc, ) (*CustomWebhookAuthHeadersConfig, error)
func (CustomWebhookAuthHeadersConfig) Equal ¶
func (cwr CustomWebhookAuthHeadersConfig) Equal(target CustomWebhookAuthHeadersConfig) bool
Equal checks if the target value is equal.
type CustomWebhookRequestConfig ¶
type CustomWebhookRequestConfig struct {
Headers *CustomWebhookAuthHeadersConfig
Body gotransform.TemplateTransformer
}
CustomWebhookRequestConfig represents a custom webhook request config.
func (CustomWebhookRequestConfig) Equal ¶
func (cwr CustomWebhookRequestConfig) Equal(target CustomWebhookRequestConfig) bool
Equal checks if the target value is equal.
type CustomWebhookResponseConfig ¶
type CustomWebhookResponseConfig struct {
Body gotransform.TemplateTransformer
}
CustomWebhookResponseConfig represents a custom webhook response config.
func (CustomWebhookResponseConfig) Equal ¶
func (cwr CustomWebhookResponseConfig) Equal(target CustomWebhookResponseConfig) bool
Equal checks if the target value is equal.
type RelyAuthWebhookConfig ¶
type RelyAuthWebhookConfig struct {
// Unique identity of the auth config.
// If not set, ID will be the index of the array.
ID string `json:"id,omitempty" yaml:"id,omitempty"`
// Authentication mode which is always webhook.
Mode authmode.AuthMode `json:"mode" yaml:"mode"`
// Request method. Accept GET or POST.
Method string `json:"method" yaml:"method"`
// The URL of the authentication webhook.
URL goenvconf.EnvString `json:"url" yaml:"url"`
// Brief description of the auth config.
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// Configurations for request headers and transformed request body to be sent to the auth hook.
CustomRequest *WebhookAuthCustomRequestConfig `json:"customRequest,omitempty" yaml:"customRequest,omitempty"`
// The configuration for transforming response bodies.
CustomResponse *WebhookAuthCustomResponseConfig `json:"customResponse,omitempty" yaml:"customResponse,omitempty"`
// Configurations for the HTTP client.
HTTPClient *httpconfig.HTTPClientConfig `json:"httpClient,omitempty" yaml:"httpClient,omitempty"`
}
RelyAuthWebhookConfig contains the configuration schema for webhook authentication.
func NewRelyAuthWebhookConfig ¶
func NewRelyAuthWebhookConfig( webhookURL goenvconf.EnvString, method string, ) *RelyAuthWebhookConfig
NewRelyAuthWebhookConfig creates a new RelyAuthWebhookConfig instance.
func (RelyAuthWebhookConfig) Equal ¶
func (j RelyAuthWebhookConfig) Equal(target RelyAuthWebhookConfig) bool
Equal checks if the target value is equal.
func (RelyAuthWebhookConfig) GetMode ¶
func (RelyAuthWebhookConfig) GetMode() authmode.AuthMode
GetMode get the auth mode of the current config.
func (RelyAuthWebhookConfig) IsZero ¶
func (j RelyAuthWebhookConfig) IsZero() bool
IsZero if the current instance is empty.
func (RelyAuthWebhookConfig) JSONSchema ¶
func (RelyAuthWebhookConfig) JSONSchema() *jsonschema.Schema
JSONSchema is used to generate a custom jsonschema.
func (RelyAuthWebhookConfig) Validate ¶
func (j RelyAuthWebhookConfig) Validate() error
Validate if the current instance is valid.
type WebhookAuthCustomRequestConfig ¶
type WebhookAuthCustomRequestConfig struct {
// The configuration to transform request headers.
Headers *WebhookAuthHeadersConfig `json:"headers,omitempty" yaml:"headers,omitempty"`
// The configuration to transform request body.
Body *gotransform.TemplateTransformerConfig `json:"body,omitempty" yaml:"body,omitempty"`
}
WebhookAuthCustomRequestConfig represents the configuration for request headers and transformed request body to be sent to the auth hook.
func (WebhookAuthCustomRequestConfig) Equal ¶
func (wa WebhookAuthCustomRequestConfig) Equal(target WebhookAuthCustomRequestConfig) bool
Equal checks if the target value is equal.
func (WebhookAuthCustomRequestConfig) IsZero ¶
func (wa WebhookAuthCustomRequestConfig) IsZero() bool
IsZero if the current instance is empty.
type WebhookAuthCustomResponseConfig ¶
type WebhookAuthCustomResponseConfig struct {
// The template to transform the response body.
Body *gotransform.TemplateTransformerConfig `json:"response,omitempty" yaml:"response,omitempty"`
}
WebhookAuthCustomResponseConfig is the configuration for transforming response bodies.
func (WebhookAuthCustomResponseConfig) Equal ¶
func (wa WebhookAuthCustomResponseConfig) Equal(target WebhookAuthCustomResponseConfig) bool
Equal checks if the target value is equal.
func (WebhookAuthCustomResponseConfig) IsZero ¶
func (wa WebhookAuthCustomResponseConfig) IsZero() bool
IsZero if the current instance is empty.
type WebhookAuthHeadersConfig ¶
type WebhookAuthHeadersConfig struct {
// The headers to be forwarded from the client request.
Forward *goutils.AllOrListString `json:"forward,omitempty" yaml:"forward,omitempty"`
// The additional headers to be sent to the auth hook.
Additional map[string]jmes.FieldMappingEntryStringConfig `json:"additional,omitempty" yaml:"additional,omitempty"`
}
WebhookAuthHeadersConfig is the configuration for the headers to be sent to the auth hook.
func (WebhookAuthHeadersConfig) Equal ¶
func (wa WebhookAuthHeadersConfig) Equal(target WebhookAuthHeadersConfig) bool
Equal checks if the target value is equal.
func (WebhookAuthHeadersConfig) IsZero ¶
func (wa WebhookAuthHeadersConfig) IsZero() bool
IsZero if the current instance is empty.
type WebhookAuthenticator ¶
type WebhookAuthenticator struct {
// contains filtered or unexported fields
}
WebhookAuthenticator implements the authenticator with API key.
func NewWebhookAuthenticator ¶
func NewWebhookAuthenticator( ctx context.Context, config *RelyAuthWebhookConfig, opts authmode.RelyAuthenticatorOptions, ) (*WebhookAuthenticator, error)
NewWebhookAuthenticator creates a webhook authenticator instance.
func (*WebhookAuthenticator) Authenticate ¶
func (wa *WebhookAuthenticator) Authenticate( ctx context.Context, body *authmode.AuthenticateRequestData, ) (authmode.AuthenticatedOutput, error)
Authenticate validates and authenticates the token from the auth webhook request.
func (*WebhookAuthenticator) Close ¶
func (wa *WebhookAuthenticator) Close() error
Close handles the resources cleaning.
func (WebhookAuthenticator) Equal ¶
func (wa WebhookAuthenticator) Equal(target WebhookAuthenticator) bool
Equal checks if the target value is equal.
func (*WebhookAuthenticator) Mode ¶
func (*WebhookAuthenticator) Mode() authmode.AuthMode
Mode returns the auth mode of the current authenticator.