Documentation
¶
Index ¶
- Variables
- func JoinDir(dir, path string) string
- func NewAuthorizationCredentialsRoundTripper(authType string, authCredentials SecretReader, rt http.RoundTripper) http.RoundTripper
- func NewBasicAuthRoundTripper(username SecretReader, password SecretReader, rt http.RoundTripper) http.RoundTripper
- func NewClientFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (*http.Client, error)
- func NewHeadersRoundTripper(config *Headers, next http.RoundTripper) http.RoundTripper
- func NewHostRoundTripper(host string, rt http.RoundTripper) http.RoundTripper
- func NewOAuth2RoundTripper(clientSecret SecretReader, config *OAuth2, next http.RoundTripper, ...) http.RoundTripper
- func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (http.RoundTripper, error)
- func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientConfig, name string, ...) (http.RoundTripper, error)
- func NewTLSConfig(cfg *TLSConfig, optFuncs ...TLSConfigOption) (*tls.Config, error)
- func NewTLSConfigWithContext(ctx context.Context, cfg *TLSConfig, optFuncs ...TLSConfigOption) (*tls.Config, error)
- func NewTLSRoundTripper(cfg *tls.Config, settings TLSRoundTripperSettings, ...) (http.RoundTripper, error)
- func NewTLSRoundTripperWithContext(ctx context.Context, cfg *tls.Config, settings TLSRoundTripperSettings, ...) (http.RoundTripper, error)
- func NewUserAgentRoundTripper(userAgent string, rt http.RoundTripper) http.RoundTripper
- func WithSecretManager(manager SecretManager) *secretManagerOption
- type Authorization
- type BasicAuth
- type DialContextFunc
- type DirectorySetter
- type FileSecret
- type HTTPClientConfig
- type HTTPClientOption
- func WithDialContextFunc(fn DialContextFunc) HTTPClientOption
- func WithHTTP2Disabled() HTTPClientOption
- func WithHost(host string) HTTPClientOption
- func WithIdleConnTimeout(timeout time.Duration) HTTPClientOption
- func WithKeepAlivesDisabled() HTTPClientOption
- func WithUserAgent(ua string) HTTPClientOption
- type Header
- type Headers
- type InlineSecret
- type OAuth2
- type ProxyConfig
- type ProxyHeader
- type Secret
- type SecretManager
- type SecretReader
- type TLSConfig
- type TLSConfigOption
- type TLSRoundTripperSettings
- type TLSVersion
- type URL
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultHTTPClientConfig is the default HTTP client configuration. DefaultHTTPClientConfig = HTTPClientConfig{ FollowRedirects: true, EnableHTTP2: true, } )
var MarshalSecretValue bool = false
MarshalSecretValue if set to true will expose Secret type through the marshal interfaces. Useful for outside projects that load and marshal the Prometheus config.
var TLSVersions = map[string]TLSVersion{ "TLS13": (TLSVersion)(tls.VersionTLS13), "TLS12": (TLSVersion)(tls.VersionTLS12), "TLS11": (TLSVersion)(tls.VersionTLS11), "TLS10": (TLSVersion)(tls.VersionTLS10), }
Functions ¶
func JoinDir ¶
JoinDir joins dir and path if path is relative. If path is empty or absolute, it is returned unchanged.
func NewAuthorizationCredentialsRoundTripper ¶
func NewAuthorizationCredentialsRoundTripper(authType string, authCredentials SecretReader, rt http.RoundTripper) http.RoundTripper
NewAuthorizationCredentialsRoundTripper adds the authorization credentials read from the provided SecretReader to a request unless the authorization header has already been set.
func NewBasicAuthRoundTripper ¶
func NewBasicAuthRoundTripper(username SecretReader, password SecretReader, rt http.RoundTripper) http.RoundTripper
NewBasicAuthRoundTripper will apply a BASIC auth authorization header to a request unless it has already been set.
func NewClientFromConfig ¶
func NewClientFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (*http.Client, error)
NewClientFromConfig returns a new HTTP client configured for the given config.HTTPClientConfig and config.HTTPClientOption. The name is used as go-conntrack metric label.
func NewHeadersRoundTripper ¶
func NewHeadersRoundTripper(config *Headers, next http.RoundTripper) http.RoundTripper
NewHeadersRoundTripper returns a RoundTripper that sets HTTP headers on requests as configured.
func NewHostRoundTripper ¶
func NewHostRoundTripper(host string, rt http.RoundTripper) http.RoundTripper
NewHostRoundTripper sets the http.Request.Host of every request.
func NewOAuth2RoundTripper ¶
func NewOAuth2RoundTripper(clientSecret SecretReader, config *OAuth2, next http.RoundTripper, opts *httpClientOptions) http.RoundTripper
func NewRoundTripperFromConfig ¶
func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (http.RoundTripper, error)
NewRoundTripperFromConfig returns a new HTTP RoundTripper configured for the given config.HTTPClientConfig and config.HTTPClientOption. The name is used as go-conntrack metric label.
func NewRoundTripperFromConfigWithContext ¶
func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientConfig, name string, optFuncs ...HTTPClientOption) (http.RoundTripper, error)
NewRoundTripperFromConfigWithContext returns a new HTTP RoundTripper configured for the given config.HTTPClientConfig and config.HTTPClientOption. The name is used as go-conntrack metric label.
func NewTLSConfig ¶
func NewTLSConfig(cfg *TLSConfig, optFuncs ...TLSConfigOption) (*tls.Config, error)
NewTLSConfig creates a new tls.Config from the given TLSConfig.
func NewTLSConfigWithContext ¶
func NewTLSConfigWithContext(ctx context.Context, cfg *TLSConfig, optFuncs ...TLSConfigOption) (*tls.Config, error)
NewTLSConfigWithContext creates a new tls.Config from the given TLSConfig.
func NewTLSRoundTripper ¶
func NewTLSRoundTripper( cfg *tls.Config, settings TLSRoundTripperSettings, newRT func(*tls.Config) (http.RoundTripper, error), ) (http.RoundTripper, error)
func NewTLSRoundTripperWithContext ¶
func NewTLSRoundTripperWithContext( ctx context.Context, cfg *tls.Config, settings TLSRoundTripperSettings, newRT func(*tls.Config) (http.RoundTripper, error), ) (http.RoundTripper, error)
func NewUserAgentRoundTripper ¶
func NewUserAgentRoundTripper(userAgent string, rt http.RoundTripper) http.RoundTripper
NewUserAgentRoundTripper adds the user agent every request header.
func WithSecretManager ¶
func WithSecretManager(manager SecretManager) *secretManagerOption
WithSecretManager allows setting the secret manager.
Types ¶
type Authorization ¶
type Authorization struct {
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Credentials Secret `yaml:"credentials,omitempty" json:"credentials,omitempty"`
CredentialsFile string `yaml:"credentials_file,omitempty" json:"credentialsFile,omitempty"`
// CredentialsRef is the name of the secret within the secret manager to use as credentials.
CredentialsRef string `yaml:"credentials_ref,omitempty" json:"credentialsRef,omitempty"`
}
Authorization contains HTTP authorization credentials.
func (*Authorization) SetDirectory ¶
func (a *Authorization) SetDirectory(dir string)
SetDirectory joins any relative file paths with dir.
type BasicAuth ¶
type BasicAuth struct {
Username string `yaml:"username" json:"username"`
UsernameFile string `yaml:"username_file,omitempty" json:"usernameFile,omitempty"`
// UsernameRef is the name of the secret within the secret manager to use as the username.
UsernameRef string `yaml:"username_ref,omitempty" json:"usernameRef,omitempty"`
Password Secret `yaml:"password,omitempty" json:"password,omitempty"`
PasswordFile string `yaml:"password_file,omitempty" json:"passwordFile,omitempty"`
// PasswordRef is the name of the secret within the secret manager to use as the password.
PasswordRef string `yaml:"password_ref,omitempty" json:"passwordRef,omitempty"`
}
BasicAuth contains basic HTTP authentication credentials.
func (*BasicAuth) SetDirectory ¶
SetDirectory joins any relative file paths with dir.
func (*BasicAuth) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.
type DialContextFunc ¶
DialContextFunc defines the signature of the DialContext() function implemented by net.Dialer.
type DirectorySetter ¶
type DirectorySetter interface {
// SetDirectory joins any relative file paths with dir.
// Any paths that are empty or absolute remain unchanged.
SetDirectory(dir string)
}
DirectorySetter is a config type that contains file paths that may be relative to the file containing the config.
type FileSecret ¶
type FileSecret struct {
// contains filtered or unexported fields
}
func NewFileSecret ¶
func NewFileSecret(file string) *FileSecret
func (*FileSecret) Description ¶
func (s *FileSecret) Description() string
func (*FileSecret) Immutable ¶
func (s *FileSecret) Immutable() bool
type HTTPClientConfig ¶
type HTTPClientConfig struct {
// The HTTP basic authentication credentials for the targets.
BasicAuth *BasicAuth `yaml:"basic_auth,omitempty" json:"basicAuth,omitempty"`
// The HTTP authorization credentials for the targets.
Authorization *Authorization `yaml:"authorization,omitempty" json:"authorization,omitempty"`
// The OAuth2 client credentials used to fetch a token for the targets.
OAuth2 *OAuth2 `yaml:"oauth2,omitempty" json:"oauth2,omitempty"`
// The bearer token for the targets. Deprecated in favour of
// Authorization.Credentials.
BearerToken Secret `yaml:"bearer_token,omitempty" json:"bearerToken,omitempty"`
// The bearer token file for the targets. Deprecated in favour of
// Authorization.CredentialsFile.
BearerTokenFile string `yaml:"bearer_token_file,omitempty" json:"bearerTokenFile,omitempty"`
// TLSConfig to use to connect to the targets.
TLSConfig TLSConfig `yaml:"tls_config,omitempty" json:"tlsConfig,omitempty"`
// FollowRedirects specifies whether the client should follow HTTP 3xx redirects.
// The omitempty flag is not set, because it would be hidden from the
// marshalled configuration when set to false.
FollowRedirects bool `yaml:"follow_redirects" json:"followRedirects"`
// EnableHTTP2 specifies whether the client should configure HTTP2.
// The omitempty flag is not set, because it would be hidden from the
// marshalled configuration when set to false.
EnableHTTP2 bool `yaml:"enable_http2" json:"enableHttp2"`
// Proxy configuration.
ProxyConfig `yaml:",inline"`
// HTTPHeaders specify headers to inject in the requests. Those headers
// could be marshalled back to the users.
HTTPHeaders *Headers `yaml:"http_headers,omitempty" json:"httpHeaders,omitempty"`
}
HTTPClientConfig configures an HTTP client.
func LoadHTTPConfig ¶
func LoadHTTPConfig(s string) (*HTTPClientConfig, error)
LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.
func LoadHTTPConfigFile ¶
func LoadHTTPConfigFile(filename string) (*HTTPClientConfig, []byte, error)
LoadHTTPConfigFile parses the given YAML file into a HTTPClientConfig.
func (*HTTPClientConfig) SetDirectory ¶
func (c *HTTPClientConfig) SetDirectory(dir string)
SetDirectory joins any relative file paths with dir.
func (HTTPClientConfig) String ¶
func (c HTTPClientConfig) String() string
func (*HTTPClientConfig) UnmarshalJSON ¶
func (c *HTTPClientConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Marshaler interface for URL.
func (*HTTPClientConfig) UnmarshalYAML ¶
func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface
func (*HTTPClientConfig) Validate ¶
func (c *HTTPClientConfig) Validate() error
Validate validates the HTTPClientConfig to check only one of BearerToken, BasicAuth and BearerTokenFile is configured. It also validates that ProxyURL is set if ProxyConnectHeader is set.
type HTTPClientOption ¶
type HTTPClientOption interface {
// contains filtered or unexported methods
}
HTTPClientOption defines an option that can be applied to the HTTP client.
func WithDialContextFunc ¶
func WithDialContextFunc(fn DialContextFunc) HTTPClientOption
WithDialContextFunc allows you to override func gets used for the actual dialing. The default is `net.Dialer.DialContext`.
func WithHTTP2Disabled ¶
func WithHTTP2Disabled() HTTPClientOption
WithHTTP2Disabled allows to disable HTTP2.
func WithHost ¶
func WithHost(host string) HTTPClientOption
WithHost allows setting the host header.
func WithIdleConnTimeout ¶
func WithIdleConnTimeout(timeout time.Duration) HTTPClientOption
WithIdleConnTimeout allows setting the idle connection timeout.
func WithKeepAlivesDisabled ¶
func WithKeepAlivesDisabled() HTTPClientOption
WithKeepAlivesDisabled allows to disable HTTP keepalive.
func WithUserAgent ¶
func WithUserAgent(ua string) HTTPClientOption
WithUserAgent allows setting the user agent.
type Header ¶
type Header struct {
Values []string `yaml:"values,omitempty" json:"values,omitempty"`
Secrets []Secret `yaml:"secrets,omitempty" json:"secrets,omitempty"`
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
}
Header represents the configuration for a single HTTP header.
type Headers ¶
type Headers struct {
Headers map[string]Header `yaml:",inline"`
// contains filtered or unexported fields
}
Headers represents the configuration for HTTP headers.
func (Headers) MarshalJSON ¶
func (*Headers) SetDirectory ¶
SetDirectory records the directory to make headers file relative to the configuration file.
func (*Headers) UnmarshalJSON ¶
type InlineSecret ¶
type InlineSecret struct {
// contains filtered or unexported fields
}
func NewInlineSecret ¶
func NewInlineSecret(text string) *InlineSecret
func (*InlineSecret) Description ¶
func (s *InlineSecret) Description() string
func (*InlineSecret) Immutable ¶
func (s *InlineSecret) Immutable() bool
type OAuth2 ¶
type OAuth2 struct {
ClientID string `yaml:"client_id" json:"clientId"`
ClientSecret Secret `yaml:"client_secret" json:"clientSecret"`
ClientSecretFile string `yaml:"client_secret_file" json:"clientSecretFile"`
// ClientSecretRef is the name of the secret within the secret manager to use as the client
// secret.
ClientSecretRef string `yaml:"client_secret_ref" json:"clientSecretRef"`
Scopes []string `yaml:"scopes,omitempty" json:"scopes,omitempty"`
TokenURL string `yaml:"token_url" json:"tokenUrl"`
EndpointParams map[string]string `yaml:"endpoint_params,omitempty" json:"endpointParams,omitempty"`
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
ProxyConfig `yaml:",inline"`
}
OAuth2 is the oauth2 client configuration.
func (*OAuth2) SetDirectory ¶
SetDirectory joins any relative file paths with dir.
func (*OAuth2) UnmarshalJSON ¶
UnmarshalJSON implements the json.Marshaler interface for URL.
func (*OAuth2) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface
type ProxyConfig ¶
type ProxyConfig struct {
// HTTP proxy server to use to connect to the targets.
ProxyURL URL `yaml:"proxy_url,omitempty" json:"proxyUrl,omitempty"`
// NoProxy contains addresses that should not use a proxy.
NoProxy string `yaml:"no_proxy,omitempty" json:"noProxy,omitempty"`
// ProxyFromEnvironment makes use of net/http ProxyFromEnvironment function
// to determine proxies.
ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty" json:"proxyFromEnvironment,omitempty"`
// ProxyConnectHeader optionally specifies headers to send to
// proxies during CONNECT requests. Assume that at least _some_ of
// these headers are going to contain secrets and use Secret as the
// value type instead of string.
ProxyConnectHeader ProxyHeader `yaml:"proxy_connect_header,omitempty" json:"proxyConnectHeader,omitempty"`
// contains filtered or unexported fields
}
func (*ProxyConfig) GetProxyConnectHeader ¶
func (c *ProxyConfig) GetProxyConnectHeader() http.Header
ProxyConnectHeader() return the Proxy Connext Headers.
func (*ProxyConfig) Validate ¶
func (c *ProxyConfig) Validate() error
UnmarshalYAML implements the yaml.Unmarshaler interface.
type ProxyHeader ¶
func (*ProxyHeader) HTTPHeader ¶
func (h *ProxyHeader) HTTPHeader() http.Header
type SecretManager ¶
type SecretManager interface {
// Fetch returns the secret data given a secret name indicated by `secretRef`.
Fetch(ctx context.Context, secretRef string) (string, error)
}
SecretManager manages secret data mapped to names known as "references" or "refs".
type SecretReader ¶
type TLSConfig ¶
type TLSConfig struct {
// Text of the CA cert to use for the targets.
CA string `yaml:"ca,omitempty" json:"ca,omitempty"`
// Text of the client cert file for the targets.
Cert string `yaml:"cert,omitempty" json:"cert,omitempty"`
// Text of the client key file for the targets.
Key Secret `yaml:"key,omitempty" json:"key,omitempty"`
// The CA cert to use for the targets.
CAFile string `yaml:"ca_file,omitempty" json:"caFile,omitempty"`
// The client cert file for the targets.
CertFile string `yaml:"cert_file,omitempty" json:"certFile,omitempty"`
// The client key file for the targets.
KeyFile string `yaml:"key_file,omitempty" json:"keyFile,omitempty"`
// CARef is the name of the secret within the secret manager to use as the CA cert for the
// targets.
CARef string `yaml:"ca_ref,omitempty" json:"caRef,omitempty"`
// CertRef is the name of the secret within the secret manager to use as the client cert for
// the targets.
CertRef string `yaml:"cert_ref,omitempty" json:"certRef,omitempty"`
// KeyRef is the name of the secret within the secret manager to use as the client key for
// the targets.
KeyRef string `yaml:"key_ref,omitempty" json:"keyRef,omitempty"`
// Used to verify the hostname for the targets.
ServerName string `yaml:"server_name,omitempty" json:"serverName,omitempty"`
// Disable target certificate validation.
InsecureSkipVerify bool `yaml:"insecure_skip_verify" json:"insecureSkipVerify"`
// Minimum TLS version.
MinVersion TLSVersion `yaml:"min_version,omitempty" json:"minVersion,omitempty"`
// Maximum TLS version.
MaxVersion TLSVersion `yaml:"max_version,omitempty" json:"maxVersion,omitempty"`
}
TLSConfig configures the options for TLS connections.
func (*TLSConfig) SetDirectory ¶
SetDirectory joins any relative file paths with dir.
func (*TLSConfig) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.
type TLSConfigOption ¶
type TLSConfigOption interface {
// contains filtered or unexported methods
}
TLSConfigOption defines an option that can be applied to the HTTP client.
type TLSRoundTripperSettings ¶
type TLSRoundTripperSettings struct {
CA SecretReader
Cert SecretReader
Key SecretReader
}
type TLSVersion ¶
type TLSVersion uint16
func (TLSVersion) MarshalJSON ¶
func (tv TLSVersion) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for TLSVersion.
func (TLSVersion) MarshalYAML ¶
func (tv TLSVersion) MarshalYAML() (interface{}, error)
func (*TLSVersion) String ¶
func (tv *TLSVersion) String() string
String implements the fmt.Stringer interface for TLSVersion.
func (*TLSVersion) UnmarshalJSON ¶
func (tv *TLSVersion) UnmarshalJSON(data []byte) error
MarshalJSON implements the json.Unmarshaler interface for TLSVersion.
func (*TLSVersion) UnmarshalYAML ¶
func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error
type URL ¶
type URL struct {
// contains filtered or unexported fields
}
URL is a custom URL type that allows validation at configuration load time.
func (URL) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for URL.
func (URL) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface for URLs.
func (*URL) UnmarshalJSON ¶
UnmarshalJSON implements the json.Marshaler interface for URL.
func (*URL) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface for URLs.