Skip to content

Commit

Permalink
fix: sanitize repo creds in error messages (#12309) (#12320)
Browse files Browse the repository at this point in the history
* fix: sanitize repo creds in error messages (#12309)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* simplify

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* comment

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* include error message

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
crenshaw-dev committed Feb 8, 2023
1 parent acc554f commit cac327c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/apis/application/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"fmt"
"net/url"

"github.com/argoproj/argo-cd/v2/util/cert"
Expand Down Expand Up @@ -265,6 +266,14 @@ func (m *Repository) CopySettingsFrom(source *Repository) {
}
}

// StringForLogging gets a string representation of the Repository which is safe to log or return to the user.
func (m *Repository) StringForLogging() string {
if m == nil {
return ""
}
return fmt.Sprintf("&Repository{Repo: %q, Type: %q, Name: %q, Project: %q}", m.Repo, m.Type, m.Name, m.Project)
}

// Repositories defines a list of Repository configurations
type Repositories []*Repository

Expand Down
2 changes: 1 addition & 1 deletion util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func validateRepo(ctx context.Context,
return nil, err
}
if err := TestRepoWithKnownType(ctx, repoClient, repo, source.IsHelm(), source.IsHelmOci()); err != nil {
errMessage = fmt.Sprintf("repositories not accessible: %v", repo)
errMessage = fmt.Sprintf("repositories not accessible: %v: %v", repo.StringForLogging(), err)
}
repoAccessible := false

Expand Down

0 comments on commit cac327c

Please sign in to comment.