Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_config: Allow customizing TLS config and settings. #748

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,14 @@ func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error {
type DialContextFunc func(context.Context, string, string) (net.Conn, error)

type httpClientOptions struct {
dialContextFunc DialContextFunc
keepAlivesEnabled bool
http2Enabled bool
idleConnTimeout time.Duration
userAgent string
host string
secretManager SecretManager
dialContextFunc DialContextFunc
keepAlivesEnabled bool
http2Enabled bool
idleConnTimeout time.Duration
userAgent string
host string
secretManager SecretManager
extendTLSConfigFunc TLSConfigExtension
}

// HTTPClientOption defines an option that can be applied to the HTTP client.
Expand Down Expand Up @@ -515,6 +516,17 @@ func WithHost(host string) HTTPClientOption {
})
}

// TLSConfigExtension modifies the given tls config and settings.
type TLSConfigExtension func(*tls.Config, TLSRoundTripperSettings) (*tls.Config, TLSRoundTripperSettings, error)
bwplotka marked this conversation as resolved.
Show resolved Hide resolved

// WithTLSConfigExtension allows to insert extension function that can freely modify
// TLSConfig and TLSRoundTripperSettings used for the round tripper creation.
func WithTLSConfigExtension(extendTLSConfigFunc TLSConfigExtension) HTTPClientOption {
return httpClientOptionFunc(func(opts *httpClientOptions) {
opts.extendTLSConfigFunc = extendTLSConfigFunc
})
}

type secretManagerOption struct {
secretManager SecretManager
}
Expand Down Expand Up @@ -679,6 +691,15 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
if err != nil {
return nil, err
}

// Allow customizing the TLS config and settings, if specified in opts.
if opts.extendTLSConfigFunc != nil {
tlsConfig, tlsSettings, err = opts.extendTLSConfigFunc(tlsConfig, tlsSettings)
if err != nil {
return nil, err
}
}

if tlsSettings.immutable() {
// No need for a RoundTripper that reloads the files automatically.
return newRT(tlsConfig)
Expand Down
Loading