Skip to content

Commit

Permalink
Fixed unmasked urls in debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Jul 28, 2024
1 parent 3f4be7e commit fe30e8f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport/client"
"github.com/jfrog/froggit-go/vcsutils"
"github.com/jfrog/jfrog-cli-security/utils/techutils"
clientutils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"

"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -162,7 +163,8 @@ func (gm *GitManager) Clone(destinationPath, branchName string) error {
transport.UnsupportedCapabilities = []capability.Capability{
capability.ThinPack,
}
log.Debug(fmt.Sprintf("Running git clone %s (%s branch)...", gm.remoteGitUrl, branchName))
maskedRemoteGitUrl := getMaskedUrlIfNeeded(gm.remoteGitUrl)
log.Debug(fmt.Sprintf("Running git clone %s (%s branch)...", maskedRemoteGitUrl, branchName))
cloneOptions := &git.CloneOptions{
URL: gm.remoteGitUrl,
Auth: gm.auth,
Expand All @@ -174,10 +176,10 @@ func (gm *GitManager) Clone(destinationPath, branchName string) error {
}
repo, err := git.PlainClone(destinationPath, false, cloneOptions)
if err != nil {
return fmt.Errorf("git clone %s from %s failed with error: %s", branchName, gm.remoteGitUrl, err.Error())
return fmt.Errorf("git clone %s from %s failed with error: %s", branchName, maskedRemoteGitUrl, err.Error())
}
gm.localGitRepository = repo
log.Debug(fmt.Sprintf("Project cloned from %s to %s", gm.remoteGitUrl, destinationPath))
log.Debug(fmt.Sprintf("Project cloned from %s to %s", maskedRemoteGitUrl, destinationPath))
return nil
}

Expand Down Expand Up @@ -512,3 +514,11 @@ func parseCustomTemplate(customTemplate string, tech []techutils.Technology) str
}
return normalizeWhitespaces(result) + suffix
}

func getMaskedUrlIfNeeded(url string) string {
matchedResult := regexp.MustCompile(clientutils.CredentialsInUrlRegexp).FindString(url)
if matchedResult == "" {
return url
}
return clientutils.RemoveCredentials(url, matchedResult)
}

0 comments on commit fe30e8f

Please sign in to comment.