66 "fmt"
77 "net"
88 "net/url"
9- "regexp"
109 "strings"
1110
11+ "github.com/docker/distribution/registry/api/v2"
1212 "github.com/docker/docker/image"
1313 "github.com/docker/docker/opts"
1414 flag "github.com/docker/docker/pkg/mflag"
@@ -32,8 +32,6 @@ const (
3232var (
3333 ErrInvalidRepositoryName = errors .New ("Invalid repository name (ex: \" registry.domain.tld/myrepos\" )" )
3434 emptyServiceConfig = NewServiceConfig (nil )
35- validNamespaceChars = regexp .MustCompile (`^([a-z0-9-_]*)$` )
36- validRepo = regexp .MustCompile (`^([a-z0-9-_.]+)$` )
3735)
3836
3937func IndexServerAddress () string {
@@ -206,42 +204,16 @@ func ValidateIndexName(val string) (string, error) {
206204}
207205
208206func validateRemoteName (remoteName string ) error {
209- var (
210- namespace string
211- name string
212- )
213- nameParts := strings .SplitN (remoteName , "/" , 2 )
214- if len (nameParts ) < 2 {
215- namespace = "library"
216- name = nameParts [0 ]
207+
208+ if ! strings .Contains (remoteName , "/" ) {
217209
218210 // the repository name must not be a valid image ID
219- if err := image .ValidateID (name ); err == nil {
220- return fmt .Errorf ("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings" , name )
211+ if err := image .ValidateID (remoteName ); err == nil {
212+ return fmt .Errorf ("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings" , remoteName )
221213 }
222- } else {
223- namespace = nameParts [0 ]
224- name = nameParts [1 ]
225- }
226- if ! validNamespaceChars .MatchString (namespace ) {
227- return fmt .Errorf ("Invalid namespace name (%s). Only [a-z0-9-_] are allowed." , namespace )
228- }
229- if len (namespace ) < 2 || len (namespace ) > 255 {
230- return fmt .Errorf ("Invalid namespace name (%s). Cannot be fewer than 2 or more than 255 characters." , namespace )
231- }
232- if strings .HasPrefix (namespace , "-" ) || strings .HasSuffix (namespace , "-" ) {
233- return fmt .Errorf ("Invalid namespace name (%s). Cannot begin or end with a hyphen." , namespace )
234214 }
235- if strings .Contains (namespace , "--" ) {
236- return fmt .Errorf ("Invalid namespace name (%s). Cannot contain consecutive hyphens." , namespace )
237- }
238- if ! validRepo .MatchString (name ) {
239- return fmt .Errorf ("Invalid repository name (%s), only [a-z0-9-_.] are allowed" , name )
240- }
241- if strings .HasPrefix (name , "-" ) || strings .HasSuffix (name , "-" ) {
242- return fmt .Errorf ("Invalid repository name (%s). Cannot begin or end with a hyphen." , name )
243- }
244- return nil
215+
216+ return v2 .ValidateRepositoryName (remoteName )
245217}
246218
247219func validateNoSchema (reposName string ) error {
0 commit comments