config

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 21 Imported by: 1,952

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultHTTPClientConfig is the default HTTP client configuration.
	DefaultHTTPClientConfig = HTTPClientConfig{
		FollowRedirects: true,
		EnableHTTP2:     true,
	}
)
View Source
var TLSVersions = map[string]TLSVersion{
	"TLS13": (TLSVersion)(tls.VersionTLS13),
	"TLS12": (TLSVersion)(tls.VersionTLS12),
	"TLS11": (TLSVersion)(tls.VersionTLS11),
	"TLS10": (TLSVersion)(tls.VersionTLS10),
}

Functions

func JoinDir added in v0.13.0

func JoinDir(dir, path string) string

JoinDir joins dir and path if path is relative. If path is empty or absolute, it is returned unchanged.

func NewAuthorizationCredentialsFileRoundTripper added in v0.16.0

func NewAuthorizationCredentialsFileRoundTripper(authType, authCredentialsFile string, rt http.RoundTripper) http.RoundTripper

NewAuthorizationCredentialsFileRoundTripper adds the authorization credentials read from the provided file to a request unless the authorization header has already been set. This file is read for every request.

func NewAuthorizationCredentialsRoundTripper added in v0.16.0

func NewAuthorizationCredentialsRoundTripper(authType string, authCredentials Secret, rt http.RoundTripper) http.RoundTripper

NewAuthorizationCredentialsRoundTripper adds the provided credentials to a request unless the authorization header has already been set.

func NewBasicAuthRoundTripper

func NewBasicAuthRoundTripper(username string, password Secret, passwordFile string, 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 NewOAuth2RoundTripper added in v0.22.0

func NewOAuth2RoundTripper(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 NewTLSConfig

func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error)

NewTLSConfig creates a new tls.Config from the given TLSConfig.

func NewTLSRoundTripper added in v0.25.0

func NewTLSRoundTripper(
	cfg *tls.Config,
	settings TLSRoundTripperSettings,
	newRT func(*tls.Config) (http.RoundTripper, error),
) (http.RoundTripper, error)

func NewUserAgentRoundTripper added in v0.36.0

func NewUserAgentRoundTripper(userAgent string, rt http.RoundTripper) http.RoundTripper

NewUserAgentRoundTripper adds the user agent every request header.

Types

type Authorization added in v0.16.0

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:"credentials_file,omitempty"`
}

Authorization contains HTTP authorization credentials.

func (*Authorization) SetDirectory added in v0.16.0

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"`
	Password     Secret `yaml:"password,omitempty" json:"password,omitempty"`
	PasswordFile string `yaml:"password_file,omitempty" json:"password_file,omitempty"`
}

BasicAuth contains basic HTTP authentication credentials.

func (*BasicAuth) SetDirectory added in v0.13.0

func (a *BasicAuth) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*BasicAuth) UnmarshalYAML

func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type DialContextFunc added in v0.21.0

type DialContextFunc func(context.Context, string, string) (net.Conn, error)

DialContextFunc defines the signature of the DialContext() function implemented by net.Dialer.

type DirectorySetter added in v0.13.0

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 HTTPClientConfig

type HTTPClientConfig struct {
	// The HTTP basic authentication credentials for the targets.
	BasicAuth *BasicAuth `yaml:"basic_auth,omitempty" json:"basic_auth,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:"bearer_token,omitempty"`
	// The bearer token file for the targets. Deprecated in favour of
	// Authorization.CredentialsFile.
	BearerTokenFile string `yaml:"bearer_token_file,omitempty" json:"bearer_token_file,omitempty"`
	// TLSConfig to use to connect to the targets.
	TLSConfig TLSConfig `yaml:"tls_config,omitempty" json:"tls_config,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:"follow_redirects"`
	// 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:"enable_http2"`
	// Proxy configuration.
	ProxyConfig `yaml:",inline"`
}

HTTPClientConfig configures an HTTP client.

func LoadHTTPConfig added in v0.38.0

func LoadHTTPConfig(s string) (*HTTPClientConfig, error)

LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.

func LoadHTTPConfigFile added in v0.38.0

func LoadHTTPConfigFile(filename string) (*HTTPClientConfig, []byte, error)

LoadHTTPConfigFile parses the given YAML file into a HTTPClientConfig.

func (*HTTPClientConfig) SetDirectory added in v0.13.0

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 added in v0.24.0

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 added in v0.21.0

type HTTPClientOption func(options *httpClientOptions)

HTTPClientOption defines an option that can be applied to the HTTP client.

func WithDialContextFunc added in v0.21.0

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 added in v0.21.0

func WithHTTP2Disabled() HTTPClientOption

WithHTTP2Disabled allows to disable HTTP2.

func WithIdleConnTimeout added in v0.29.0

func WithIdleConnTimeout(timeout time.Duration) HTTPClientOption

WithIdleConnTimeout allows setting the idle connection timeout.

func WithKeepAlivesDisabled added in v0.21.0

func WithKeepAlivesDisabled() HTTPClientOption

WithKeepAlivesDisabled allows to disable HTTP keepalive.

func WithUserAgent added in v0.36.0

func WithUserAgent(ua string) HTTPClientOption

WithUserAgent allows setting the user agent.

type Header map[string][]Secret

func (*Header) HTTPHeader added in v0.39.0

func (h *Header) HTTPHeader() http.Header

type OAuth2 added in v0.22.0

type OAuth2 struct {
	ClientID         string            `yaml:"client_id" json:"client_id"`
	ClientSecret     Secret            `yaml:"client_secret" json:"client_secret"`
	ClientSecretFile string            `yaml:"client_secret_file" json:"client_secret_file"`
	Scopes           []string          `yaml:"scopes,omitempty" json:"scopes,omitempty"`
	TokenURL         string            `yaml:"token_url" json:"token_url"`
	EndpointParams   map[string]string `yaml:"endpoint_params,omitempty" json:"endpoint_params,omitempty"`
	TLSConfig        TLSConfig         `yaml:"tls_config,omitempty"`
	ProxyConfig      `yaml:",inline"`
}

OAuth2 is the oauth2 client configuration.

func (*OAuth2) SetDirectory added in v0.22.0

func (a *OAuth2) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*OAuth2) UnmarshalJSON added in v0.42.0

func (o *OAuth2) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler interface for URL.

func (*OAuth2) UnmarshalYAML added in v0.42.0

func (o *OAuth2) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type ProxyConfig added in v0.42.0

type ProxyConfig struct {
	// 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 makes use of net/http ProxyFromEnvironment function
	// 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. Assume that at least _some_ of
	// these headers are going to contain secrets and use Secret as the
	// value type instead of string.
	ProxyConnectHeader Header `yaml:"proxy_connect_header,omitempty" json:"proxy_connect_header,omitempty"`
	// contains filtered or unexported fields
}

func (*ProxyConfig) GetProxyConnectHeader added in v0.42.0

func (c *ProxyConfig) GetProxyConnectHeader() http.Header

ProxyConnectHeader() return the Proxy Connext Headers.

func (*ProxyConfig) Proxy added in v0.42.0

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

Proxy returns the Proxy URL for a request.

func (*ProxyConfig) Validate added in v0.42.0

func (c *ProxyConfig) Validate() error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Secret

type Secret string

Secret special type for storing secrets.

func (Secret) MarshalJSON added in v0.24.0

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Secret.

func (Secret) MarshalYAML

func (s Secret) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Secrets.

func (*Secret) UnmarshalYAML

func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Secrets.

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:"ca_file,omitempty"`
	// The client cert file for the targets.
	CertFile string `yaml:"cert_file,omitempty" json:"cert_file,omitempty"`
	// The client key file for the targets.
	KeyFile string `yaml:"key_file,omitempty" json:"key_file,omitempty"`
	// Used to verify the hostname for the targets.
	ServerName string `yaml:"server_name,omitempty" json:"server_name,omitempty"`
	// Disable target certificate validation.
	InsecureSkipVerify bool `yaml:"insecure_skip_verify" json:"insecure_skip_verify"`
	// Minimum TLS version.
	MinVersion TLSVersion `yaml:"min_version,omitempty" json:"min_version,omitempty"`
	// Maximum TLS version.
	MaxVersion TLSVersion `yaml:"max_version,omitempty" json:"max_version,omitempty"`
}

TLSConfig configures the options for TLS connections.

func (*TLSConfig) SetDirectory added in v0.13.0

func (c *TLSConfig) SetDirectory(dir string)

SetDirectory joins any relative file paths with dir.

func (*TLSConfig) UnmarshalYAML

func (c *TLSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*TLSConfig) Validate added in v0.44.0

func (c *TLSConfig) Validate() error

Validate validates the TLSConfig to check that only one of the inlined or file-based fields for the TLS CA, client certificate, and client key are used.

type TLSRoundTripperSettings added in v0.44.0

type TLSRoundTripperSettings struct {
	CA, CAFile     string
	Cert, CertFile string
	Key, KeyFile   string
}

type TLSVersion added in v0.34.0

type TLSVersion uint16

func (TLSVersion) MarshalJSON added in v0.34.0

func (tv TLSVersion) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for TLSVersion.

func (TLSVersion) MarshalYAML added in v0.34.0

func (tv TLSVersion) MarshalYAML() (interface{}, error)

func (*TLSVersion) String added in v0.38.0

func (tv *TLSVersion) String() string

String implements the fmt.Stringer interface for TLSVersion.

func (*TLSVersion) UnmarshalJSON added in v0.34.0

func (tv *TLSVersion) UnmarshalJSON(data []byte) error

MarshalJSON implements the json.Unmarshaler interface for TLSVersion.

func (*TLSVersion) UnmarshalYAML added in v0.34.0

func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error

type URL

type URL struct {
	*url.URL
}

URL is a custom URL type that allows validation at configuration load time.

func (URL) MarshalJSON added in v0.24.0

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for URL.

func (URL) MarshalYAML

func (u URL) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for URLs.

func (URL) Redacted added in v0.30.1

func (u URL) Redacted() string

Redacted returns the URL but replaces any password with "xxxxx".

func (*URL) UnmarshalJSON added in v0.24.0

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler interface for URL.

func (*URL) UnmarshalYAML

func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for URLs.

Jump to

Keyboard shortcuts

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