http

package
v0.0.0-...-beed7e5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: AGPL-3.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const TestCACert = `` /* 289-byte string literal not displayed */
View Source
const TestCertPem = `` /* 586-byte string literal not displayed */
View Source
const TestKeyPem = `` /* 226-byte string literal not displayed */

Variables

View Source
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")
)
View Source
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")
)
View Source
var ErrInvalidMethod = errors.New("webhook only supports HTTP methods PUT or POST")

Functions

func GetBasicAuthHeader

func GetBasicAuthHeader(user string, password string) string

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

func (ns *Client) SendWebhook(ctx context.Context, l log.Logger, webhook *receivers.SendWebhookSettings) error

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

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.

func (*HMACRoundTripper) RoundTrip

func (rt *HMACRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

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

func (*OAuth2RoundTripper) RoundTrip

func (rt *OAuth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

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

func (*ProxyConfig) Proxy

func (cfg *ProxyConfig) Proxy() func(*http.Request) (*url.URL, error)

Proxy returns the Proxy URL for a request.

type URL

type URL = config.URL

Simple wrapper to allow marshalling and unmarshalling of URL in YAML and JSON formats with validation.

func MustURL

func MustURL(u string) URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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