mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Deprecate detect and protect. Add git, dir, stdin (#1504)
* init backwards compatible cmd * update readme, todos * ... * moar comments, sprucing up root * readme change
This commit is contained in:
1 parent
e93a7c0d26
commit
44ad62e0b1
7 files changed
+270
-64
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v8/report"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(stdInCmd)
|
||||
}
|
||||
|
||||
var stdInCmd = &cobra.Command{
|
||||
Use: "stdin",
|
||||
Short: "detect secrets from stdin",
|
||||
Run: runStdIn,
|
||||
}
|
||||
|
||||
func runStdIn(cmd *cobra.Command, args []string) {
|
||||
initConfig()
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
)
|
||||
|
||||
// setup config (aka, the thing that defines rules)
|
||||
cfg := Config(cmd)
|
||||
|
||||
// start timer
|
||||
start := time.Now()
|
||||
detector := Detector(cmd, cfg, "")
|
||||
|
||||
// set exit code
|
||||
exitCode, err := cmd.Flags().GetInt("exit-code")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not get exit code")
|
||||
}
|
||||
|
||||
findings, err = detector.DetectReader(os.Stdin, 10)
|
||||
if err != nil {
|
||||
// log fatal to exit, no need to continue since a report
|
||||
// will not be generated when scanning from a pipe...for now
|
||||
log.Fatal().Err(err).Msg("failed scan input from stdin")
|
||||
}
|
||||
|
||||
findingSummaryAndExit(findings, cmd, cfg, exitCode, start, err)
|
||||
}
|
||||
Reference in new issue
Block a user