Merge pull request #2490 from hashicorp/b-fix-api-tls

Fix TLS use in AllocFS API and region/dc detection
This commit is contained in:
Michael Schurter 2017-03-28 09:40:22 -07:00 committed by GitHub
commit f2288b022d
2 changed files with 24 additions and 3 deletions

View File

@ -60,10 +60,14 @@ func (a *Agent) populateCache(self *AgentSelf) {
a.nodeName = self.Member.Name
}
if a.datacenter == "" {
a.datacenter, _ = self.Member.Tags["dc"]
if val, ok := self.Config["Datacenter"]; ok {
a.datacenter, _ = val.(string)
}
}
if a.region == "" {
a.region, _ = self.Member.Tags["region"]
if val, ok := self.Config["Region"]; ok {
a.region, _ = val.(string)
}
}
}

View File

@ -57,8 +57,25 @@ func (a *AllocFS) getNodeClient(node *Node, allocID string, q **QueryOptions) (*
return nil, fmt.Errorf("http addr of the node where alloc %q is running is not advertised", allocID)
}
region := ""
if q != nil && *q != nil && (*q).Region != "" {
region = (*q).Region
} else if a.client.config.Region != "" {
// Use the region from the client
region = a.client.config.Region
} else {
// Use the region from the agent
agentRegion, err := a.client.Agent().Region()
if err != nil {
return nil, err
}
region = agentRegion
}
// Get an API client for the node
nodeClient, err := NewClient(a.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled))
conf := a.client.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
}