Skip to content

Find, verify, and analyze leaked credentials

fix npd for incompatible sources on json legacy output (#623)

Dustin Decker85ed11519f33
diff --git a/pkg/output/legacy_json.go b/pkg/output/legacy_json.go
index 76ad418b5..c280d7569 100644
--- a/pkg/output/legacy_json.go
+++ b/pkg/output/legacy_json.go
@@ -19,13 +19,27 @@ import (
)
func PrintLegacyJSON(r *detectors.ResultWithMetadata) {
- repoPath, remote, err := git.PrepareRepo(r.SourceMetadata.GetGithub().Repository)
+ var repo string
+ switch r.SourceType {
+ case sourcespb.SourceType_SOURCE_TYPE_GIT:
+ repo = r.SourceMetadata.GetGit().Repository
+ case sourcespb.SourceType_SOURCE_TYPE_GITHUB:
+ repo = r.SourceMetadata.GetGithub().Repository
+ case sourcespb.SourceType_SOURCE_TYPE_GITLAB:
+ repo = r.SourceMetadata.GetGitlab().Repository
+ default:
+ logrus.Errorf("unsupported source type for legacy json output: %s", r.SourceType)
+ }
+
+ // cloning the repo again here is not great and only works with unauthed repos
+ repoPath, remote, err := git.PrepareRepo(repo)
if err != nil || repoPath == "" {
logrus.WithError(err).Fatal("error preparing git repo for scanning")
}
if remote {
defer os.RemoveAll(repoPath)
}
+
legacy := ConvertToLegacyJSON(r, repoPath)
out, err := json.Marshal(legacy)
if err != nil {