Skip to content

Commit

Permalink
Merge pull request #2490 from hashicorp/b-fix-api-tls
Browse files Browse the repository at this point in the history
Fix TLS use in AllocFS API and region/dc detection
  • Loading branch information
schmichael authored Mar 28, 2017
2 parents 5903612 + 26e6073 commit fe98392
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
19 changes: 18 additions & 1 deletion api/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fe98392

Please sign in to comment.