Browse code

Move names to a more appropriate package.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/09/07 00:35:06
Showing 5 changed files
1 1
deleted file mode 100644
... ...
@@ -1,9 +0,0 @@
1
-package api
2
-
3
-import "regexp"
4
-
5
-// RestrictedNameChars collects the characters allowed to represent a name, normally used to validate container and volume names.
6
-const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
7
-
8
-// RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters.
9
-var RestrictedNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`)
... ...
@@ -7,13 +7,13 @@ import (
7 7
 	"os"
8 8
 	"path/filepath"
9 9
 
10
-	"github.com/docker/docker/api"
11 10
 	"github.com/docker/docker/api/types"
11
+	"github.com/docker/docker/daemon/names"
12 12
 )
13 13
 
14 14
 var (
15
-	validCheckpointNameChars   = api.RestrictedNameChars
16
-	validCheckpointNamePattern = api.RestrictedNamePattern
15
+	validCheckpointNameChars   = names.RestrictedNameChars
16
+	validCheckpointNamePattern = names.RestrictedNamePattern
17 17
 )
18 18
 
19 19
 // getCheckpointDir verifies checkpoint directory for create,remove, list options and checks if checkpoint already exists
... ...
@@ -4,8 +4,8 @@ import (
4 4
 	"fmt"
5 5
 	"strings"
6 6
 
7
-	"github.com/docker/docker/api"
8 7
 	"github.com/docker/docker/container"
8
+	"github.com/docker/docker/daemon/names"
9 9
 	"github.com/docker/docker/pkg/namesgenerator"
10 10
 	"github.com/docker/docker/pkg/stringid"
11 11
 	"github.com/pkg/errors"
... ...
@@ -13,8 +13,8 @@ import (
13 13
 )
14 14
 
15 15
 var (
16
-	validContainerNameChars   = api.RestrictedNameChars
17
-	validContainerNamePattern = api.RestrictedNamePattern
16
+	validContainerNameChars   = names.RestrictedNameChars
17
+	validContainerNamePattern = names.RestrictedNamePattern
18 18
 )
19 19
 
20 20
 func (daemon *Daemon) registerName(container *container.Container) error {
21 21
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+package names
1
+
2
+import "regexp"
3
+
4
+// RestrictedNameChars collects the characters allowed to represent a name, normally used to validate container and volume names.
5
+const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
6
+
7
+// RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters.
8
+var RestrictedNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`)
... ...
@@ -13,7 +13,7 @@ import (
13 13
 	"strings"
14 14
 	"sync"
15 15
 
16
-	"github.com/docker/docker/api"
16
+	"github.com/docker/docker/daemon/names"
17 17
 	"github.com/docker/docker/pkg/idtools"
18 18
 	"github.com/docker/docker/pkg/mount"
19 19
 	"github.com/docker/docker/volume"
... ...
@@ -35,7 +35,7 @@ var (
35 35
 	// volumeNameRegex ensures the name assigned for the volume is valid.
36 36
 	// This name is used to create the bind directory, so we need to avoid characters that
37 37
 	// would make the path to escape the root directory.
38
-	volumeNameRegex = api.RestrictedNamePattern
38
+	volumeNameRegex = names.RestrictedNamePattern
39 39
 )
40 40
 
41 41
 type activeMount struct {
... ...
@@ -298,7 +298,7 @@ func (r *Root) validateName(name string) error {
298 298
 		return validationError("volume name is too short, names should be at least two alphanumeric characters")
299 299
 	}
300 300
 	if !volumeNameRegex.MatchString(name) {
301
-		return validationError(fmt.Sprintf("%q includes invalid characters for a local volume name, only %q are allowed. If you intended to pass a host directory, use absolute path", name, api.RestrictedNameChars))
301
+		return validationError(fmt.Sprintf("%q includes invalid characters for a local volume name, only %q are allowed. If you intended to pass a host directory, use absolute path", name, names.RestrictedNameChars))
302 302
 	}
303 303
 	return nil
304 304
 }