mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
handle goimports/go vet warnings
This commit is contained in:
1 parent
57d2d345b6
commit
8b70e7fc2f
12 files changed
+178
-127
No files matched your search
+69
-29
@@ -1,11 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/config"
|
||||
"github.com/zricethezav/gitleaks/v8/detect"
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -23,43 +29,77 @@ func runProtect(cmd *cobra.Command, args []string) {
|
||||
initConfig()
|
||||
var vc config.ViperConfig
|
||||
|
||||
viper.Unmarshal(&vc)
|
||||
if err := viper.Unmarshal(&vc); err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to load config")
|
||||
}
|
||||
cfg, err := vc.Translate()
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to load config")
|
||||
}
|
||||
|
||||
cfg.Path, _ = cmd.Flags().GetString("config")
|
||||
// source, _ := cmd.Flags().GetString("source")
|
||||
// verbose, _ := cmd.Flags().GetBool("verbose")
|
||||
// redact, _ := cmd.Flags().GetBool("redact")
|
||||
// exitCode, _ := cmd.Flags().GetInt("exit-code")
|
||||
// staged, _ := cmd.Flags().GetBool("staged")
|
||||
// if cfg.Path == "" {
|
||||
// cfg.Path = filepath.Join(source, ".gitleaks.toml")
|
||||
// }
|
||||
// start := time.Now()
|
||||
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
||||
staged, _ := cmd.Flags().GetBool("staged")
|
||||
start := time.Now()
|
||||
|
||||
// files, err := git.GitDiff(source, staged)
|
||||
// if err != nil {
|
||||
// log.Fatal().Err(err).Msg("Failed to get git log")
|
||||
// }
|
||||
// Setup detector
|
||||
detector := detect.NewDetector(cfg)
|
||||
detector.Config.Path, err = cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
source, err := cmd.Flags().GetString("source")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
// if config path is not set, then use the {source}/.gitleaks.toml path.
|
||||
// note that there may not be a `{source}/.gitleaks.toml` file, this is ok.
|
||||
if detector.Config.Path == "" {
|
||||
detector.Config.Path = filepath.Join(source, ".gitleaks.toml")
|
||||
}
|
||||
// set verbose flag
|
||||
if detector.Verbose, err = cmd.Flags().GetBool("verbose"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
// set redact flag
|
||||
if detector.Redact, err = cmd.Flags().GetBool("redact"); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
|
||||
// findings := detect.FromGit(files, cfg, detect.Options{Verbose: verbose, Redact: redact})
|
||||
// if len(findings) != 0 {
|
||||
// log.Warn().Msgf("leaks found: %d", len(findings))
|
||||
// } else {
|
||||
// log.Info().Msg("no leaks found")
|
||||
// }
|
||||
// get log options for git scan
|
||||
logOpts, err := cmd.Flags().GetString("log-opts")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
|
||||
// log.Info().Msgf("scan duration: %s", time.Since(start))
|
||||
// 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)
|
||||
}
|
||||
if err != nil {
|
||||
// don't exit on error, just log it
|
||||
log.Error().Err(err)
|
||||
}
|
||||
|
||||
// reportPath, _ := cmd.Flags().GetString("report-path")
|
||||
// ext, _ := cmd.Flags().GetString("report-format")
|
||||
// if reportPath != "" {
|
||||
// report.Write(findings, cfg, ext, reportPath)
|
||||
// }
|
||||
// if len(findings) != 0 {
|
||||
// os.Exit(exitCode)
|
||||
// }
|
||||
// log info about the scan
|
||||
log.Info().Msgf("scan completed in %s", time.Since(start))
|
||||
if len(findings) != 0 {
|
||||
log.Warn().Msgf("leaks found: %d", len(findings))
|
||||
} else {
|
||||
log.Info().Msg("no leaks found")
|
||||
}
|
||||
|
||||
reportPath, _ := cmd.Flags().GetString("report-path")
|
||||
ext, _ := cmd.Flags().GetString("report-format")
|
||||
if reportPath != "" {
|
||||
if err = report.Write(findings, cfg, ext, reportPath); err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
}
|
||||
if len(findings) != 0 {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user