Improve parseAuthHost function to work for all ref

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau
2021-06-30 18:27:26 +02:00
parent d10f2a49a5
commit 58a67cf86b
2 changed files with 9 additions and 25 deletions

View File

@@ -64,17 +64,17 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred
}
func parseAuthHost(host string) (*url.URL, error) {
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") && strings.Contains(host, "/") {
ref, err := reference.ParseNormalizedNamed(host)
if err != nil {
return nil, err
}
host = ref.String()
}
host = strings.TrimPrefix(host, "http://")
host = strings.TrimPrefix(host, "https://")
if strings.Contains(host, "docker.io") {
host = "https://index.docker.io/v1/"
// Retrieve only the registry
host = strings.SplitN(host, "/", 2)[0]
ref, err := reference.ParseNormalizedNamed(host)
if err != nil {
return nil, err
}
host = ref.String()
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
host = "https://" + host