-
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 TLS support in api pkg / cli #3108
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -285,6 +285,58 @@ func (c *Client) SetRegion(region string) { | |
c.config.Region = region | ||
} | ||
|
||
// GetNodeClient returns a new Client that will dial the specified node. If the | ||
// QueryOptions is set, the function will ensure that it is initialized and | ||
// that the Params field is valid. | ||
func (c *Client) GetNodeClient(nodeID string, q **QueryOptions) (*Client, error) { | ||
node, _, err := c.Nodes().Info(nodeID, &QueryOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if node.Status == "down" { | ||
return nil, NodeDownErr | ||
} | ||
if node.HTTPAddr == "" { | ||
return nil, fmt.Errorf("http addr of node %q (%s) is not advertised", node.Name, nodeID) | ||
} | ||
|
||
region := "" | ||
if q != nil && *q != nil && (*q).Region != "" { | ||
region = (*q).Region | ||
} else if c.config.Region != "" { | ||
// Use the region from the client | ||
region = c.config.Region | ||
} else { | ||
// Use the region from the agent | ||
agentRegion, err := c.Agent().Region() | ||
if err != nil { | ||
return nil, err | ||
} | ||
region = agentRegion | ||
} | ||
|
||
// Get an API client for the node | ||
conf := c.config.CopyConfig(node.HTTPAddr, node.TLSEnabled) | ||
conf.TLSConfig.TLSServerName = fmt.Sprintf("client.%s.nomad", region) | ||
nodeClient, err := NewClient(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set the query params | ||
if q == nil { | ||
return nodeClient, nil | ||
} | ||
|
||
if *q == nil { | ||
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. Not sure I understand this logic. If there isn't a reason for it, can you remove and just take a pointer, not a pointer to a pointer. |
||
*q = &QueryOptions{} | ||
} | ||
if actQ := *q; actQ.Params == nil { | ||
actQ.Params = make(map[string]string) | ||
} | ||
return nodeClient, nil | ||
} | ||
|
||
// request is used to help build up a request | ||
type request struct { | ||
config *Config | ||
|
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
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.
This seems odd. There may not be an agent if this is being embedded in another program and it would cause an error. It should just do nothing as the http handler would default to the global region
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.
Won't this query the agent at NOMAD_ADDR for the region? That seems potentially useful even in embedded circumstances.
(This logic was cargo culted from the previous location, so I may not fully grok it)