Define common regexps used across registry application
This commit adds regular expression definitions for several string identifiers used througout the registry. The repository name regex supports up to five path path components and restricts repeated periods, dashes and underscores. The tag regex simply validates the length of the tag and that printable characters are required. Though we define a new package common, these definition should land in docker core.
This commit is contained in:
parent
d245a502b2
commit
375f3cc136
4 changed files with 230 additions and 0 deletions
19
common/names.go
Normal file
19
common/names.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// RepositoryNameComponentRegexp restricts registtry path components names to
|
||||
// start with at least two letters or numbers, with following parts able to
|
||||
// separated by one period, dash or underscore.
|
||||
var RepositoryNameComponentRegexp = regexp.MustCompile(`[a-z0-9](?:[a-z0-9]+[._-]?)*[a-z0-9]`)
|
||||
|
||||
// RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow 2 to
|
||||
// 5 path components, separated by a forward slash.
|
||||
var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/){1,4}` + RepositoryNameComponentRegexp.String())
|
||||
|
||||
// TagNameRegexp matches valid tag names. From docker/docker:graph/tags.go.
|
||||
var TagNameRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`)
|
||||
|
||||
// TODO(stevvooe): Contribute these exports back to core, so they are shared.
|
Loading…
Add table
Add a link
Reference in a new issue