Skip to content

Commit

Permalink
DRY up valid container name pattern usage
Browse files Browse the repository at this point in the history
  • Loading branch information
titanous committed Dec 18, 2013
1 parent 1940015 commit 3ec39ad
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
const MaxImageDepth = 127

var (
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
validContainerName = regexp.MustCompile(`^/?[a-zA-Z0-9_.-]+$`)
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
validContainerNameChars = `[a-zA-Z0-9_.-]`
validContainerNamePattern = regexp.MustCompile(`^/?` + validContainerNameChars + `+$`)
)

type Capabilities struct {
Expand Down Expand Up @@ -425,8 +426,8 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
name = utils.TruncateID(id)
}
} else {
if !validContainerName.MatchString(name) {
return nil, nil, fmt.Errorf("Invalid container name (%s), only [a-zA-Z0-9_-] are allowed", name)
if !validContainerNamePattern.MatchString(name) {
return nil, nil, fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)
}
}

Expand Down

0 comments on commit 3ec39ad

Please sign in to comment.