DRY up valid container name pattern usage
This commit is contained in:
parent
1940015824
commit
3ec39ad01a
|
@ -31,8 +31,9 @@ import (
|
||||||
const MaxImageDepth = 127
|
const MaxImageDepth = 127
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||||
validContainerName = regexp.MustCompile(`^/?[a-zA-Z0-9_.-]+$`)
|
validContainerNameChars = `[a-zA-Z0-9_.-]`
|
||||||
|
validContainerNamePattern = regexp.MustCompile(`^/?` + validContainerNameChars + `+$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type Capabilities struct {
|
type Capabilities struct {
|
||||||
|
@ -425,8 +426,8 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
||||||
name = utils.TruncateID(id)
|
name = utils.TruncateID(id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !validContainerName.MatchString(name) {
|
if !validContainerNamePattern.MatchString(name) {
|
||||||
return nil, nil, fmt.Errorf("Invalid container name (%s), only [a-zA-Z0-9_-] are allowed", name)
|
return nil, nil, fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue