-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix TLSServerName for Node API Client #3127
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4d3b75d
Fix TLSServerName for Node API Client
dadgar f5fb62c
Node Client doesn't share HTTP client
dadgar 5d65af5
Check for errors initializing client for autocomplete
dadgar 734a73e
tls cluster
dadgar 9e63e7b
Add readmes
dadgar 0fa161b
Update README.md
dadgar d759dc8
Address feedback
dadgar 40a8efb
Merge branch 'b-tls-api' of github.com:hashicorp/nomad into b-tls-api
dadgar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,9 @@ func (c *Config) ClientConfig(region, address string, tlsEnabled bool) *Config { | |
WaitTime: c.WaitTime, | ||
TLSConfig: c.TLSConfig.Copy(), | ||
} | ||
config.TLSConfig.TLSServerName = fmt.Sprintf("client.%s.nomad", c.Region) | ||
if tlsEnabled && config.TLSConfig != nil { | ||
config.TLSConfig.TLSServerName = fmt.Sprintf("client.%s.nomad", region) | ||
} | ||
|
||
return config | ||
} | ||
|
@@ -221,6 +223,9 @@ func DefaultConfig() *Config { | |
|
||
// ConfigureTLS applies a set of TLS configurations to the the HTTP client. | ||
func (c *Config) ConfigureTLS() error { | ||
if c.TLSConfig == nil { | ||
return nil | ||
} | ||
if c.HttpClient == nil { | ||
return fmt.Errorf("config HTTP Client must be set") | ||
} | ||
|
@@ -300,7 +305,17 @@ func (c *Client) SetRegion(region string) { | |
// GetNodeClient returns a new Client that will dial the specified node. If the | ||
// QueryOptions is set, its region will be used. | ||
func (c *Client) GetNodeClient(nodeID string, q *QueryOptions) (*Client, error) { | ||
node, _, err := c.Nodes().Info(nodeID, q) | ||
return c.getNodeClientImpl(nodeID, q, c.Nodes().Info) | ||
} | ||
|
||
// nodeLookup is used to lookup a node | ||
type nodeLookup func(nodeID string, q *QueryOptions) (*Node, *QueryMeta, error) | ||
|
||
// getNodeClientImpl is the implementation of creating a API client for | ||
// contacting a node. It is takes a function to lookup the node such that it can | ||
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. "It is takes" :) |
||
// be mocked during tests. | ||
func (c *Client) getNodeClientImpl(nodeID string, q *QueryOptions, lookup nodeLookup) (*Client, error) { | ||
node, _, err := lookup(nodeID, q) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -316,6 +331,10 @@ func (c *Client) GetNodeClient(nodeID string, q *QueryOptions) (*Client, error) | |
region = q.Region | ||
} | ||
|
||
if region == "" { | ||
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 logic is a bit confusing with 329-332. Is there a way (case statement or "else if") to have region only be assigned a value once? |
||
region = "global" | ||
} | ||
|
||
// Get an API client for the node | ||
conf := c.config.ClientConfig(region, node.HTTPAddr, node.TLSEnabled) | ||
return NewClient(conf) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe a bit more detail in the comment here