Merge pull request #2798 from hashicorp/f-lower-id

Forces user-supplied node IDs to lower case for consistency.
This commit is contained in:
James Phillips 2017-03-14 17:52:35 -07:00 committed by GitHub
commit de78d70a33
2 changed files with 4 additions and 2 deletions

View File

@ -646,6 +646,7 @@ func (a *Agent) setupNodeID(config *Config) error {
// If they've configured a node ID manually then just use that, as // If they've configured a node ID manually then just use that, as
// long as it's valid. // long as it's valid.
if config.NodeID != "" { if config.NodeID != "" {
config.NodeID = types.NodeID(strings.ToLower(string(config.NodeID)))
if _, err := uuid.ParseUUID(string(config.NodeID)); err != nil { if _, err := uuid.ParseUUID(string(config.NodeID)); err != nil {
return err return err
} }
@ -674,6 +675,7 @@ func (a *Agent) setupNodeID(config *Config) error {
} }
nodeID := strings.TrimSpace(string(rawID)) nodeID := strings.TrimSpace(string(rawID))
nodeID = strings.ToLower(nodeID)
if _, err := uuid.ParseUUID(nodeID); err != nil { if _, err := uuid.ParseUUID(nodeID); err != nil {
return err return err
} }

View File

@ -341,7 +341,7 @@ func TestAgent_NodeID(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
c.NodeID = types.NodeID(newID) c.NodeID = types.NodeID(strings.ToUpper(newID))
if err := agent.setupNodeID(c); err != nil { if err := agent.setupNodeID(c); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
@ -361,7 +361,7 @@ func TestAgent_NodeID(t *testing.T) {
} }
// Set a valid ID via the file. // Set a valid ID via the file.
if err := ioutil.WriteFile(fileID, []byte("adf4238a-882b-9ddc-4a9d-5b6758e4159e"), 0600); err != nil { if err := ioutil.WriteFile(fileID, []byte("ADF4238a-882b-9ddc-4a9d-5b6758e4159e"), 0600); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
c.NodeID = "" c.NodeID = ""