-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Create command to print config #1654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
d94e6c9
to
75f66bb
Compare
75f66bb
to
98a6b18
Compare
283d329
to
34d00ad
Compare
34d00ad
to
b855095
Compare
06bc6ed
to
fe3993e
Compare
I'm thinking
I think they should be hidden. We want to display what the user sees when editing a config file (partial config if they are using extended configs) |
quick sanity test too: Wherever this feature lands, the above commands should work |
diff --git a/cmd/config.go b/cmd/config.go
index 0a0d2d4..668714f 100644
--- a/cmd/config.go
+++ b/cmd/config.go
@@ -3,6 +3,8 @@ package cmd
import (
"bytes"
"fmt"
+ "regexp"
+ "strconv"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog/log"
@@ -45,7 +47,22 @@ func runShowConfig(cmd *cobra.Command, args []string) {
if err := enc.Encode(outputConfig); err != nil {
log.Fatal().Err(err).Msg("could not encode config")
}
- fmt.Println(buf.String())
+ out := buf.String()
+ re := regexp.MustCompile(`(?m)^(\s*regex\s*=\s*)"(.+)"$`)
+ out = re.ReplaceAllStringFunc(out, func(m string) string {
+ parts := re.FindStringSubmatch(m)
+ // parts[1] == leading " regex = "
+ // parts[2] == the raw inner escaped content
+ unq, err := strconv.Unquote(`"` + parts[2] + `"`)
+ if err != nil {
+ // fallback to the escaped form
+ unq = parts[2]
+ }
+ // wrap in a TOML multi-line literal (no escaping ever)
+ // see TOML spec: multi-line literal = '''…''' :contentReference[oaicite:1]{index=1}
+ return parts[1] + "'''" + unq + "'''"
+ })
+ fmt.Println(out)
}
// effectiveConfig matches the structure of `gitleaks.toml`.
@@ -54,5 +71,5 @@ type effectiveConfig struct {
Title string `toml:"title,omitempty"`
Extend config.Extend `toml:"extend,omitempty"`
Rules []config.Rule `toml:"rules,omitempty"`
- Allowlists []*config.Allowlist `toml:"allowlist,omitempty"`
+ Allowlists []*config.Allowlist `toml:"allowlists,omitempty"`
} This passes my simple |
It's better but can still fail for |
Description:
This creates a new command to show the effective config that Gitleaks actually uses, to help troubleshoot issues where
Questions
source
+config
command like others, or take a single argument pointing to a config file?Files
orPath
which don't get picked up; explicit empty fields would make that obvious, but add a lot of noise.Checklist: