-
Notifications
You must be signed in to change notification settings - Fork 782
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
Support custom transport dialer #1520
Conversation
Adds a TransportDialer interface to support using a custom Dial() in the Vault client.
config/transport.go
Outdated
// TransportDialer is an interface that allows passing a custom dialer to an | ||
// HTTP client's transport config | ||
type TransportDialer interface { | ||
Dial(network, address string) (net.Conn, error) |
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.
Should the interface also cover DialContext
? Both net.Dialer
and bufconn.Listener
should still satisfy this.
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.
I suppose it could, but DialContext
isn't called anywhere in consul-template that I see.
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.
It looks like Dial
on http.Transport
is deprecated, so it might be good to have this interface satisfy both in case we switch over.
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.
Good point! Added in 9860065.
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.
👍 Thanks for including DialContext. There are plans on the roadmap for updating CT to use Context.
"custom_transport_dialer", | ||
&TransportConfig{CustomDialer: &net.Dialer{Timeout: 10 * time.Second}}, | ||
&TransportConfig{CustomDialer: &net.Dialer{Timeout: 20 * time.Second}}, | ||
&TransportConfig{CustomDialer: &net.Dialer{Timeout: 20 * time.Second}}, |
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.
Does the second one or the one with the highest timeout win?
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.
In this test it's the second one, i.e. the "other" takes precedence in Merge:
consul-template/config/transport.go
Lines 89 to 93 in 799d656
// Merge combines all values in this configuration with the values in the other | |
// configuration, with values in the other configuration taking precedence. | |
// Maps and slices are merged, most other values are overwritten. Complex | |
// structs define their own merge functionality. | |
func (c *TransportConfig) Merge(o *TransportConfig) *TransportConfig { |
and add some doc strings
dependency/client_set.go
Outdated
@@ -12,6 +12,8 @@ import ( | |||
consulapi "github.com/hashicorp/consul/api" | |||
rootcerts "github.com/hashicorp/go-rootcerts" | |||
vaultapi "github.com/hashicorp/vault/api" | |||
|
|||
"github.com/hashicorp/consul-template/config" |
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.
Would you rework this to not import hashicorp/consul-template/config. I'll need to port this to hashicat (the library replacing consul-template's library functionality) and it doesn't have a config module like this.
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.
Sure! Is 03d3cad what you had in mind?
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.
That would totally work. Thanks!
and into dependency
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.
This looks good to me now. Let me know if you have anything else in mind.
If not I'll merge it.
@eikenb Nothing else in mind here, thanks! |
Adds a
TransportDialer
interface toTransportConfig
, to allow using a custom Dial() in clients such as Vault.Vault's case is illustrated in this PR, where an in-process connection is setup between consul-template and vault-agent: hashicorp/vault#12762