| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package cmd
- import (
- "os"
- "time"
- "github.com/spf13/cobra"
- "github.com/zricethezav/gitleaks/v8/logging"
- "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 {
- logging.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
- logging.Fatal().Err(err).Msg("failed scan input from stdin")
- }
- findingSummaryAndExit(detector, findings, exitCode, start, err)
- }
|