Add experimental allowlist optimizations (#1731)

* feat(allowlist): optimization experiments

* refactor(allowlist): remove useOptimizations flag

* refactor(allowlist): simplify Validate() with helper func

* refactor(config): replace global feature flag
This commit is contained in:
Richard Gomez authored and GitHub committed 2025-06-08 10:33:05 -05:00
1 parent 79068b35e5
commit 9faaa4a09c
9 files changed
+363 -42

No files matched your search

+6
View File
@@ -77,6 +77,7 @@ func init() {
rootCmd.PersistentFlags().StringP("gitleaks-ignore-path", "i", ".", "path to .gitleaksignore file or folder containing one")
rootCmd.PersistentFlags().Int("max-decode-depth", 0, "allow recursive decoding up to this depth (default \"0\", no decoding is done)")
rootCmd.PersistentFlags().Int("max-archive-depth", 0, "allow scanning into nested archives up to this depth (default \"0\", no archive traversal is done)")
rootCmd.PersistentFlags().BoolP("experimental-optimizations", "", false, "enables experimental allowlist optimizations, increasing performance at the cost of startup time")
// Add diagnostics flags
rootCmd.PersistentFlags().String("diagnostics", "", "enable diagnostics (http OR comma-separated list: cpu,mem,trace). cpu=CPU prof, mem=memory prof, trace=exec tracing, http=serve via net/http/pprof")
@@ -222,6 +223,11 @@ func Config(cmd *cobra.Command) config.Config {
if err := viper.Unmarshal(&vc); err != nil {
logging.Fatal().Err(err).Msg("Failed to load config")
}
// set experimental feature flag(s)
if mustGetBoolFlag(cmd, "experimental-optimizations") {
logging.Warn().Msgf("using experimental allowlist optimizations, updates may contain breaking changes!")
vc.EnableExperimentalAllowlistOptimizations = true
}
cfg, err := vc.Translate()
if err != nil {
logging.Fatal().Err(err).Msg("Failed to load config")