mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 21:44:23 +01:00
Added option to specify .gitleaksignore path (#1179)
This commit is contained in:
1 parent
190ac977be
commit
f257b05d3b
2 files changed
+36
-1
No files matched your search
+18
-1
@@ -20,7 +20,7 @@ func init() {
|
|||||||
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
|
detectCmd.Flags().Bool("no-git", false, "treat git repo as a regular directory and scan those files, --log-opts has no effect on the scan when --no-git is set")
|
||||||
detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
|
detectCmd.Flags().Bool("pipe", false, "scan input from stdin, ex: `cat some_file | gitleaks detect --pipe`")
|
||||||
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
detectCmd.Flags().Bool("follow-symlinks", false, "scan files that are symlinks to other files")
|
||||||
|
detectCmd.Flags().StringP("gitleaks-ignore-path","i",".","path to .gitleaksignore file or folder containing one")
|
||||||
}
|
}
|
||||||
|
|
||||||
var detectCmd = &cobra.Command{
|
var detectCmd = &cobra.Command{
|
||||||
@@ -81,6 +81,23 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitleaksIgnorePath, err:= cmd.Flags().GetString("gitleaks-ignore-path")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(gitleaksIgnorePath) {
|
||||||
|
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||||
|
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
protectCmd.Flags().Bool("staged", false, "detect secrets in a --staged state")
|
||||||
protectCmd.Flags().String("log-opts", "", "git log options")
|
protectCmd.Flags().String("log-opts", "", "git log options")
|
||||||
|
protectCmd.Flags().StringP("gitleaks-ignore-path","i",".","path to .gitleaksignore file or folder containing one")
|
||||||
rootCmd.AddCommand(protectCmd)
|
rootCmd.AddCommand(protectCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +75,23 @@ func runProtect(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitleaksIgnorePath, err:= cmd.Flags().GetString("gitleaks-ignore-path")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not get .gitleaksignore path")
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(gitleaksIgnorePath) {
|
||||||
|
if err = detector.AddGitleaksIgnore(gitleaksIgnorePath); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileExists(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")) {
|
||||||
|
if err = detector.AddGitleaksIgnore(filepath.Join(gitleaksIgnorePath, ".gitleaksignore")); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
if fileExists(filepath.Join(source, ".gitleaksignore")) {
|
||||||
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
if err = detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore")); err != nil {
|
||||||
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
log.Fatal().Err(err).Msg("could not call AddGitleaksIgnore")
|
||||||
|
|||||||
Reference in new issue
Block a user