Allowing namespaces in standalone registry
This commit is contained in:
parent
c6068feffa
commit
16fa043e34
1 changed files with 19 additions and 15 deletions
|
@ -20,8 +20,7 @@ import (
|
||||||
var ErrAlreadyExists = errors.New("Image already exists")
|
var ErrAlreadyExists = errors.New("Image already exists")
|
||||||
|
|
||||||
func pingRegistryEndpoint(endpoint string) error {
|
func pingRegistryEndpoint(endpoint string) error {
|
||||||
// FIXME: implement the check to discover if it should be http or https
|
resp, err := http.Get(endpoint + "/_ping")
|
||||||
resp, err := http.Get(endpoint)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -31,7 +30,19 @@ func pingRegistryEndpoint(endpoint string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateRepositoryName(namespace, name string) error {
|
func validateRepositoryName(repositoryName string) error {
|
||||||
|
var (
|
||||||
|
namespace string
|
||||||
|
name string
|
||||||
|
)
|
||||||
|
nameParts := strings.SplitN(repositoryName, "/", 2)
|
||||||
|
if len(nameParts) < 2 {
|
||||||
|
namespace = "library"
|
||||||
|
name = nameParts[0]
|
||||||
|
} else {
|
||||||
|
namespace = nameParts[0]
|
||||||
|
name = nameParts[1]
|
||||||
|
}
|
||||||
validNamespace := regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
|
validNamespace := regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
|
||||||
if !validNamespace.MatchString(namespace) {
|
if !validNamespace.MatchString(namespace) {
|
||||||
return fmt.Errorf("Invalid namespace name (%s), only [a-z0-9_] are allowed, size between 4 and 30", namespace)
|
return fmt.Errorf("Invalid namespace name (%s), only [a-z0-9_] are allowed, size between 4 and 30", namespace)
|
||||||
|
@ -48,12 +59,7 @@ func ResolveRepositoryName(reposName string) (string, string, error) {
|
||||||
nameParts := strings.SplitN(reposName, "/", 2)
|
nameParts := strings.SplitN(reposName, "/", 2)
|
||||||
if !strings.Contains(nameParts[0], ".") {
|
if !strings.Contains(nameParts[0], ".") {
|
||||||
// This is a Docker Index repos (ex: samalba/hipache or ubuntu)
|
// This is a Docker Index repos (ex: samalba/hipache or ubuntu)
|
||||||
var err error
|
err := validateRepositoryName(reposName)
|
||||||
if len(nameParts) < 2 {
|
|
||||||
err = validateRepositoryName("library", nameParts[0])
|
|
||||||
} else {
|
|
||||||
err = validateRepositoryName(nameParts[0], nameParts[1])
|
|
||||||
}
|
|
||||||
return "https://index.docker.io/v1/", reposName, err
|
return "https://index.docker.io/v1/", reposName, err
|
||||||
}
|
}
|
||||||
if len(nameParts) < 2 {
|
if len(nameParts) < 2 {
|
||||||
|
@ -61,20 +67,18 @@ func ResolveRepositoryName(reposName string) (string, string, error) {
|
||||||
// Is it a Registry address without repos name?
|
// Is it a Registry address without repos name?
|
||||||
return "", "", errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
return "", "", errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
||||||
}
|
}
|
||||||
n := strings.LastIndex(reposName, "/")
|
|
||||||
hostname := nameParts[0]
|
hostname := nameParts[0]
|
||||||
path := reposName[len(nameParts[0]):n]
|
reposName = nameParts[1]
|
||||||
reposName = reposName[n+1:]
|
endpoint := fmt.Sprintf("https://%s/v1/", hostname)
|
||||||
endpoint := fmt.Sprintf("https://%s%s/v1/", hostname, path)
|
|
||||||
if err := pingRegistryEndpoint(endpoint); err != nil {
|
if err := pingRegistryEndpoint(endpoint); err != nil {
|
||||||
utils.Debugf("Registry %s does not work (%s), falling back to http", endpoint, err)
|
utils.Debugf("Registry %s does not work (%s), falling back to http", endpoint, err)
|
||||||
endpoint = fmt.Sprintf("http://%s%s/v1/", hostname, path)
|
endpoint = fmt.Sprintf("http://%s/v1/", hostname)
|
||||||
if err = pingRegistryEndpoint(endpoint); err != nil {
|
if err = pingRegistryEndpoint(endpoint); err != nil {
|
||||||
//TODO: triggering highland build can be done there without "failing"
|
//TODO: triggering highland build can be done there without "failing"
|
||||||
return "", "", errors.New("Invalid Registry endpoint: " + err.Error())
|
return "", "", errors.New("Invalid Registry endpoint: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := validateRepositoryName("library", reposName)
|
err := validateRepositoryName(reposName)
|
||||||
return endpoint, reposName, err
|
return endpoint, reposName, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue