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

View File

@ -1,16 +0,0 @@
setup() {
load 'helpers'
common_setup
}
# FIXME: move to universe/universe.bats
# Assigned to: <ADD YOUR NAME HERE>
# Changes in https://github.com/dagger/dagger/pull/628
@test "stdlib: docker: push-and-pull" {
skip_unless_secrets_available "$TESTDIR"/stdlib/docker/push-pull/inputs.yaml
# check that they succeed with the credentials
run "$DAGGER" compute --input-yaml "$TESTDIR"/stdlib/docker/push-pull/inputs.yaml --input-dir source="$TESTDIR"/stdlib/docker/push-pull/testdata "$TESTDIR"/stdlib/docker/push-pull/
assert_success
}