Skip to content

Commit

Permalink
fix: Suppressed ssh scheme url warn log (#9836)
Browse files Browse the repository at this point in the history
* Fixed ssh scheme warn log degrade by #8508
Signed-off-by: kenchan0130 <tt.tanishi100@gmail.com>

* Expanded repository type getCAPath testing
Signed-off-by: kenchan0130 <tt.tanishi100@gmail.com>
  • Loading branch information
kenchan0130 authored and crenshaw-dev committed Aug 15, 2022
1 parent f071b29 commit 3b17121
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
40 changes: 25 additions & 15 deletions pkg/apis/application/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,40 @@ func (repo *Repository) GetHelmCreds() helm.Creds {
}

func getCAPath(repoURL string) string {
hostname := ""
// For git ssh protocol url without ssh://, url.Parse() will fail to parse.
// However, no warn log is output since ssh scheme url is a possible format.
if ok, _ := git.IsSSHURL(repoURL); ok {
return ""
}

hostname := ""
// url.Parse() will happily parse most things thrown at it. When the URL
// is either https or oci, we use the parsed hostname to receive the cert,
// otherwise we'll use the parsed path (OCI repos are often specified as
// hostname, without protocol).
if parsedURL, err := url.Parse(repoURL); err == nil {
if parsedURL.Scheme == "https" || parsedURL.Scheme == "oci" {
hostname = parsedURL.Host
} else if parsedURL.Scheme == "" {
hostname = parsedURL.Path
}
} else {
parsedURL, err := url.Parse(repoURL)
if err != nil {
log.Warnf("Could not parse repo URL '%s': %v", repoURL, err)
return ""
}
if parsedURL.Scheme == "https" || parsedURL.Scheme == "oci" {
hostname = parsedURL.Host
} else if parsedURL.Scheme == "" {
hostname = parsedURL.Path
}

if hostname != "" {
if caPath, err := cert.GetCertBundlePathForRepository(hostname); err == nil {
return caPath
} else {
log.Warnf("Could not get cert bundle path for repository '%s': %v", repoURL, err)
}
if hostname == "" {
log.Warnf("Could not get hostname for repository '%s'", repoURL)
return ""
}

caPath, err := cert.GetCertBundlePathForRepository(hostname)
if err != nil {
log.Warnf("Could not get cert bundle path for repository '%s': %v", repoURL, err)
return ""
}
return ""

return caPath
}

// CopySettingsFrom copies all repository settings from source to receiver
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,7 @@ func TestGetCAPath(t *testing.T) {
"oci://bar.example.com",
"bar.example.com",
"ssh://foo.example.com",
"git@example.com:organization/reponame.git",
"/some/invalid/thing",
"../another/invalid/thing",
"./also/invalid",
Expand Down

0 comments on commit 3b17121

Please sign in to comment.