Fix login miss behavior and update op

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-07-01 14:08:49 +02:00
parent 58a67cf86b
commit 2f710b0ce4
3 changed files with 10 additions and 17 deletions

View File

@ -2,7 +2,6 @@ package solver
import ( import (
"context" "context"
"net/url"
"strings" "strings"
"sync" "sync"
@ -41,9 +40,9 @@ func (a *RegistryAuthProvider) Register(server *grpc.Server) {
} }
func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.CredentialsRequest) (*bkauth.CredentialsResponse, error) { func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.CredentialsRequest) (*bkauth.CredentialsResponse, error) {
reqURL, err := parseAuthHost(req.Host) host := req.Host
if err != nil { if host == "registry-1.docker.io" {
return nil, err host = "docker.io"
} }
a.m.RLock() a.m.RLock()
@ -55,7 +54,7 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred
return nil, err return nil, err
} }
if u.Host == reqURL.Host { if u == host {
return auth, nil return auth, nil
} }
} }
@ -63,23 +62,16 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred
return &bkauth.CredentialsResponse{}, nil return &bkauth.CredentialsResponse{}, nil
} }
func parseAuthHost(host string) (*url.URL, error) { func parseAuthHost(host string) (string, error) {
host = strings.TrimPrefix(host, "http://") host = strings.TrimPrefix(host, "http://")
host = strings.TrimPrefix(host, "https://") host = strings.TrimPrefix(host, "https://")
// Retrieve only the registry
host = strings.SplitN(host, "/", 2)[0]
ref, err := reference.ParseNormalizedNamed(host) ref, err := reference.ParseNormalizedNamed(host)
if err != nil {
return nil, err
}
host = ref.String()
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") { if err != nil {
host = "https://" + host return "", err
} }
return url.Parse(host) return reference.Domain(ref), nil
} }
func (a *RegistryAuthProvider) FetchToken(ctx context.Context, req *bkauth.FetchTokenRequest) (rr *bkauth.FetchTokenResponse, err error) { func (a *RegistryAuthProvider) FetchToken(ctx context.Context, req *bkauth.FetchTokenRequest) (rr *bkauth.FetchTokenResponse, err error) {

View File

@ -59,7 +59,7 @@ package op
#DockerLogin: { #DockerLogin: {
do: "docker-login" do: "docker-login"
target: string | *"https://index.docker.io/v1/" target: string
username: string username: string
// FIXME: should be a #Secret (circular import) // FIXME: should be a #Secret (circular import)
secret: string | bytes secret: string | bytes

View File

@ -21,6 +21,7 @@ TestPushContainer: {
ref: "daggerio/ci-test:\(tag.out)" ref: "daggerio/ci-test:\(tag.out)"
#up: [ #up: [
op.#DockerLogin & { op.#DockerLogin & {
target: ref
registry registry
}, },
op.#WriteFile & { op.#WriteFile & {