From cee333fe416fda5447e42b917a53a415f4a77042 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Fri, 5 May 2023 10:12:49 +0200 Subject: [PATCH] chore: show validation error Signed-off-by: Miguel Martinez Trivino --- app/controlplane/internal/service/ocirepository.go | 4 ++-- internal/ociauth/auth.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controlplane/internal/service/ocirepository.go b/app/controlplane/internal/service/ocirepository.go index cac79efaf..3544b85b0 100644 --- a/app/controlplane/internal/service/ocirepository.go +++ b/app/controlplane/internal/service/ocirepository.go @@ -50,10 +50,10 @@ func (s *OCIRepositoryService) Save(ctx context.Context, req *pb.OCIRepositorySe username := req.GetKeyPair().Username password := req.GetKeyPair().Password - // Create credentials + // Create and validate credentials k, err := ociauth.NewCredentials(req.Repository, username, password) if err != nil { - return nil, sl.LogAndMaskErr(err, s.log) + return nil, errors.BadRequest("wrong credentials", err.Error()) } // Check credentials diff --git a/internal/ociauth/auth.go b/internal/ociauth/auth.go index 8d5ebac8c..da3ed236b 100644 --- a/internal/ociauth/auth.go +++ b/internal/ociauth/auth.go @@ -17,6 +17,7 @@ package ociauth import ( "errors" + "fmt" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" @@ -31,7 +32,7 @@ type Credentials struct { func NewCredentials(repoURI, username, password string) (authn.Keychain, error) { repo, err := name.NewRepository(repoURI) if err != nil { - return nil, err + return nil, fmt.Errorf("invalid repository URI: %w", err) } // NOTE: NewRepository parses incorrectly URIs with schemas