Documentation
¶
Index ¶
- Constants
- Variables
- func GetBasicAuthHeader(user string, password string) string
- func NewOAuth2TokenSource(config OAuth2Config, clientConfig clientConfiguration) (oauth2.TokenSource, error)
- func NewTLSClient(tlsConfig *tls.Config, ...) *http.Client
- func ToHTTPClientOption(option ...ClientOption) []commoncfg.HTTPClientOption
- func ValidateHTTPClientConfig(cfg *HTTPClientConfig) error
- func ValidateOAuth2Config(config *OAuth2Config) error
- func ValidateProxyConfig(cfg ProxyConfig) error
- type Client
- type ClientOption
- type ForkedSender
- type HMACRoundTripper
- type HTTPClientConfig
- type OAuth2Config
- type OAuth2RoundTripper
- type ProxyConfig
- type URL
Constants ¶
const TestCACert = `` /* 289-byte string literal not displayed */
const TestCertPem = `` /* 586-byte string literal not displayed */
const TestKeyPem = `` /* 226-byte string literal not displayed */
Variables ¶
var ( // ErrInvalidOAuth2Config is returned when the OAuth2 configuration is invalid. ErrInvalidOAuth2Config = fmt.Errorf("invalid OAuth2 configuration") // ErrInvalidProxyConfig is returned when the proxy configuration is invalid. ErrInvalidProxyConfig = fmt.Errorf("invalid proxy configuration") )
var ( // ErrOAuth2ClientIDRequired is returned when OAuth2 ClientID is required but not provided. ErrOAuth2ClientIDRequired = fmt.Errorf("OAuth2 ClientID is required") // ErrOAuth2ClientSecretRequired is returned when OAuth2 ClientSecret is required but not provided. ErrOAuth2ClientSecretRequired = fmt.Errorf("OAuth2 ClientSecret is required") // ErrOAuth2TokenURLRequired is returned when OAuth2 TokenURL is required but not provided. ErrOAuth2TokenURLRequired = fmt.Errorf("OAuth2 TokenURL is required") // ErrOAuth2TLSConfigInvalid is returned when the provided TLS configuration is invalid. ErrOAuth2TLSConfigInvalid = fmt.Errorf("invalid TLS configuration") )
var ErrInvalidMethod = errors.New("webhook only supports HTTP methods PUT or POST")
Functions ¶
func GetBasicAuthHeader ¶
func NewOAuth2TokenSource ¶
func NewOAuth2TokenSource(config OAuth2Config, clientConfig clientConfiguration) (oauth2.TokenSource, error)
func NewTLSClient ¶
func NewTLSClient(tlsConfig *tls.Config, dialContextfunc func(context.Context, string, string) (net.Conn, error)) *http.Client
NewTLSClient creates a new HTTP client with the provided TLS configuration or with default settings.
func ToHTTPClientOption ¶
func ToHTTPClientOption(option ...ClientOption) []commoncfg.HTTPClientOption
func ValidateHTTPClientConfig ¶
func ValidateHTTPClientConfig(cfg *HTTPClientConfig) error
func ValidateOAuth2Config ¶
func ValidateOAuth2Config(config *OAuth2Config) error
func ValidateProxyConfig ¶
func ValidateProxyConfig(cfg ProxyConfig) error
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(httpClientConfig *HTTPClientConfig, opts ...ClientOption) (*Client, error)
func (*Client) SendWebhook ¶
type ClientOption ¶
type ClientOption func(*clientConfiguration)
func WithDialer ¶
func WithDialer(dialer net.Dialer) ClientOption
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
type ForkedSender ¶
type ForkedSender struct {
// contains filtered or unexported fields
}
func NewForkedSender ¶
func NewForkedSender(cli *Client) *ForkedSender
func (ForkedSender) SendWebhook ¶
func (f ForkedSender) SendWebhook(ctx context.Context, l log.Logger, cmd *receivers.SendWebhookSettings) error
type HMACRoundTripper ¶
type HMACRoundTripper struct {
// contains filtered or unexported fields
}
HMACRoundTripper is an HTTP transport that signs outgoing requests using HMAC SHA256. It can optionally include a timestamp in the signature calculation (if timestampHeader is not empty) and supports custom header names for both the signature and timestamp values.
func NewHMACRoundTripper ¶
func NewHMACRoundTripper(wrapped http.RoundTripper, clk clock.Clock, secret, header, timestampHeader string) (*HMACRoundTripper, error)
NewHMACRoundTripper creates a new HMACRoundTripper that wraps the provided RoundTripper. It signs requests using the provided secret key and places the signature in the specified header. If header is empty, it defaults to "X-Grafana-Alert-Signature". If timestampHeader is non-empty, the current timestamp will be included in the signature calculation and set in the specified header.
type HTTPClientConfig ¶
type HTTPClientConfig struct {
// The OAuth2 client credentials used to fetch a token for the targets.
OAuth2 *OAuth2Config `yaml:"oauth2,omitempty" json:"oauth2,omitempty"`
}
HTTPClientConfig holds common configuration for notifier HTTP clients.
func (*HTTPClientConfig) Decrypt ¶
func (c *HTTPClientConfig) Decrypt(decryptFn receivers.DecryptFunc)
Decrypt decrypts sensitive fields in the HTTPClientConfig.
type OAuth2Config ¶
type OAuth2Config struct {
ClientID string `json:"client_id" yaml:"client_id"`
ClientSecret string `json:"client_secret" yaml:"client_secret"`
TokenURL string `json:"token_url" yaml:"token_url"`
Scopes []string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
EndpointParams map[string]string `json:"endpoint_params,omitempty" yaml:"endpoint_params,omitempty"`
TLSConfig *receivers.TLSConfig `json:"tls_config,omitempty" yaml:"tls_config,omitempty"`
ProxyConfig *ProxyConfig `json:"proxy_config,omitempty" yaml:"proxy_config,omitempty"`
}
OAuth2Config is the oauth2 client configuration.
type OAuth2RoundTripper ¶
type OAuth2RoundTripper struct {
// contains filtered or unexported fields
}
func NewOAuth2RoundTripper ¶
func NewOAuth2RoundTripper(tokenSource oauth2.TokenSource, next http.RoundTripper) *OAuth2RoundTripper
type ProxyConfig ¶
type ProxyConfig struct {
// ProxyURL is the HTTP proxy server to use to connect to the targets.
ProxyURL URL `yaml:"proxy_url,omitempty" json:"proxy_url,omitempty"`
// NoProxy contains addresses that should not use a proxy.
NoProxy string `yaml:"no_proxy,omitempty" json:"no_proxy,omitempty"`
// ProxyFromEnvironment uses environment HTTP_PROXY, HTTPS_PROXY and NO_PROXY to determine proxies.
ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty" json:"proxy_from_environment,omitempty"`
// ProxyConnectHeader optionally specifies headers to send to proxies during CONNECT requests.
ProxyConnectHeader map[string]string `yaml:"proxy_connect_header,omitempty" json:"proxy_connect_header,omitempty"`
}
func (*ProxyConfig) GetProxyConnectHeader ¶
func (cfg *ProxyConfig) GetProxyConnectHeader() http.Header