Browse code

DRY up valid container name pattern usage

Jonathan Rudenberg authored on 2013/12/17 11:17:22
Showing 1 changed files
... ...
@@ -31,8 +31,9 @@ import (
31 31
 const MaxImageDepth = 127
32 32
 
33 33
 var (
34
-	defaultDns         = []string{"8.8.8.8", "8.8.4.4"}
35
-	validContainerName = regexp.MustCompile(`^/?[a-zA-Z0-9_.-]+$`)
34
+	defaultDns                = []string{"8.8.8.8", "8.8.4.4"}
35
+	validContainerNameChars   = `[a-zA-Z0-9_.-]`
36
+	validContainerNamePattern = regexp.MustCompile(`^/?` + validContainerNameChars + `+$`)
36 37
 )
37 38
 
38 39
 type Capabilities struct {
... ...
@@ -425,8 +426,8 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
425 425
 			name = utils.TruncateID(id)
426 426
 		}
427 427
 	} else {
428
-		if !validContainerName.MatchString(name) {
429
-			return nil, nil, fmt.Errorf("Invalid container name (%s), only [a-zA-Z0-9_-] are allowed", name)
428
+		if !validContainerNamePattern.MatchString(name) {
429
+			return nil, nil, fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)
430 430
 		}
431 431
 	}
432 432