Skip to content

Commit

Permalink
Add better verification of a host's HostID.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean- committed Feb 3, 2017
1 parent b24c835 commit 31333ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hashicorp/nomad/client/stats"
"github.com/hashicorp/nomad/client/vaultclient"
"github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/tlsutil"
"github.com/hashicorp/nomad/nomad"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -636,7 +637,7 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner {
func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if err == nil && hostInfo.HostID != "" {
if err == nil && helper.IsUUID(hostInfo.HostID) {
hostID = hostInfo.HostID
} else {
// Generate a random hostID if no constant ID is available on
Expand Down
15 changes: 15 additions & 0 deletions helper/funcs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package helper

import "regexp"

// validUUID is used to check if a given string looks like a UUID
var validUUID = regexp.MustCompile(`(?i)^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$`)

// IsUUID returns true if the given string is a valid UUID.
func IsUUID(str string) bool {
const uuidLen = 36
if len(str) != uuidLen {
return false
}

return validUUID.MatchString(str)
}

// boolToPtr returns the pointer to a boolean
func BoolToPtr(b bool) *bool {
return &b
Expand Down

0 comments on commit 31333ee

Please sign in to comment.