-
Notifications
You must be signed in to change notification settings - Fork 337
Reload TLS certificates when needed #139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| "io/ioutil" | ||
| "net/http" | ||
| "net/url" | ||
| "reflect" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -146,6 +147,8 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTri | |
| ), | ||
| } | ||
|
|
||
| rt = NewTLSConfigRoundTripper(cfg, tlsConfig, name, rt) | ||
|
|
||
| // If a bearer token is provided, create a round tripper that will set the | ||
| // Authorization header correctly on each request. | ||
| if len(cfg.BearerToken) > 0 { | ||
|
|
@@ -162,6 +165,33 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTri | |
| return rt, nil | ||
| } | ||
|
|
||
| type tlsConfigRoundTripper struct { | ||
| cfg HTTPClientConfig | ||
| tlsConfig *tls.Config | ||
| name string | ||
| rt http.RoundTripper | ||
| } | ||
|
|
||
| // NewTLSConfigRoundTripper reads the tls configuration upton each request | ||
| // and updates the TLS configuration as needed | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fullstop |
||
| func NewTLSConfigRoundTripper(cfg HTTPClientConfig, tlsConfig *tls.Config, name string, rt http.RoundTripper) http.RoundTripper { | ||
| return &tlsConfigRoundTripper{cfg, tlsConfig, name, rt} | ||
| } | ||
|
|
||
| func (rt *tlsConfigRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| tlsConfig, err := NewTLSConfig(&rt.cfg.TLSConfig) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !reflect.DeepEqual(tlsConfig, rt.tlsConfig) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's mutable state in a tls.Config, so this may always return true and cause spurious reconnects |
||
| rt.rt, err = NewRoundTripperFromConfig(rt.cfg, rt.name) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like a layering violation, it'd be cleaner to take in a function that'd create a new round tripper |
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return rt.rt.RoundTrip(req) | ||
| } | ||
|
|
||
| type bearerAuthRoundTripper struct { | ||
| bearerToken Secret | ||
| rt http.RoundTripper | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upon