mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Small refactor detect and sources (#1297)
This commit is contained in:
1 parent
01e60c81e6
commit
ca7aa14542
11 files changed
+359
-346
No files matched your search
+11
-3
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -63,7 +63,11 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
|
||||
// start the detector scan
|
||||
if noGit {
|
||||
findings, err = detector.DetectFiles(source)
|
||||
paths, err := sources.FilesystemTargets(source, detector.Sema, detector.FollowSymlinks)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
findings, err = detector.DetectFiles(paths)
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Err(err).Msg("")
|
||||
@@ -81,7 +85,11 @@ func runDetect(cmd *cobra.Command, args []string) {
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
findings, err = detector.DetectGit(source, logOpts, detect.DetectType)
|
||||
gitCmd, err := sources.NewGitLogCmd(source, logOpts)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
findings, err = detector.DetectGit(gitCmd)
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Err(err).Msg("")
|
||||
|
||||
+5
-12
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
"github.com/zricethezav/gitleaks/v8/sources"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -35,22 +35,15 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
start := time.Now()
|
||||
|
||||
detector := Detector(cmd, cfg, source)
|
||||
|
||||
// get log options for git scan
|
||||
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
|
||||
// start git scan
|
||||
var findings []report.Finding
|
||||
if staged {
|
||||
findings, err = detector.DetectGit(source, logOpts, detect.ProtectStagedType)
|
||||
} else {
|
||||
findings, err = detector.DetectGit(source, logOpts, detect.ProtectType)
|
||||
gitCmd, err := sources.NewGitDiffCmd(source, staged)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("")
|
||||
}
|
||||
findings, err = detector.DetectGit(gitCmd)
|
||||
|
||||
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err)
|
||||
}
|
||||
Reference in new issue
Block a user