Skip to content

Commit a2ef3ce

Browse files
authored
Refactor verbose flag to be global with log-level support (#329)
* Refactor verbose flag to be global with log-level support
1 parent 66c2f88 commit a2ef3ce

38 files changed

Lines changed: 367 additions & 142 deletions

docs/introduction/getting_started.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ Note: `high-verified` cannot be removed, but verification can be disabled using
7777

7878
When you run Pipeleak for the first time, it generates a `rules.yml` file based on [this repository](https://github.com/mazen160/secrets-patterns-db/blob/master/db/rules-stable.yml). You can customize your scan rules by modifying this file as needed.
7979

80-
### Keybindings
80+
### Log Levels
8181

82-
In the `scan` mode you can change interactively between log levels by pressing `t`: Trace, `d`: Debug, `i`: Info, `w`: Warn, `e`: Error. Pressing `s` will output the current status.
82+
Pipeleak supports different log levels to control output verbosity:
83+
84+
* **info** (default) - Standard informational messages
85+
* **debug** - Detailed diagnostic information
86+
* **warn** - Warning messages only
87+
* **error** - Error messages only
88+
* **trace** - Very detailed trace-level logging
89+
90+
You can set the log level in two ways:
91+
92+
**Using the verbose flag:**
93+
```bash
94+
# Short form - sets debug level
95+
pipeleak gl scan --token glpat-xxx --gitlab https://gitlab.com -v
96+
97+
# Long form with specific level
98+
pipeleak gl scan --token glpat-xxx --gitlab https://gitlab.com --log-level debug
99+
pipeleak gl scan --token glpat-xxx --gitlab https://gitlab.com --log-level trace
100+
pipeleak gl scan --token glpat-xxx --gitlab https://gitlab.com --log-level warn
101+
pipeleak gl scan --token glpat-xxx --gitlab https://gitlab.com --log-level error
102+
```
103+
104+
**Interactive keybindings:**
105+
During a scan, you can change log levels on the fly by pressing:
106+
* `t` - Trace level
107+
* `d` - Debug level
108+
* `i` - Info level
109+
* `w` - Warn level
110+
* `e` - Error level
111+
* `s` - Output current scan status

src/pipeleak/cmd/bitbucket/scan.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
type BitBucketScanOptions struct {
2222
Email string
2323
AccessToken string
24-
Verbose bool
2524
ConfidenceFilter []string
2625
MaxScanGoRoutines int
2726
TruffleHogVerification bool
@@ -78,8 +77,6 @@ pipeleak bb scan --token ATATTxxxxxx --email auser@example.com --public --maxPip
7877
scanCmd.PersistentFlags().BoolVarP(&options.Public, "public", "p", false, "Scan all public repositories")
7978
scanCmd.PersistentFlags().StringVarP(&options.After, "after", "", "", "Filter public repos by a given date in ISO 8601 format: 2025-04-02T15:00:00+02:00 ")
8079

81-
scanCmd.PersistentFlags().BoolVarP(&options.Verbose, "verbose", "v", false, "Verbose logging")
82-
8380
return scanCmd
8481
}
8582

@@ -88,7 +85,6 @@ func Scan(cmd *cobra.Command, args []string) {
8885
log.Fatal().Msg("When using --token you must also provide --email")
8986
}
9087

91-
logging.SetLogLevel(options.Verbose)
9288
go logging.ShortcutListeners(scanStatus)
9389

9490
runner.InitScanner(options.ConfidenceFilter)

src/pipeleak/cmd/bitbucket/scan_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ func TestNewScanCmd(t *testing.T) {
6565
if persistentFlags.Lookup("maxPipelines") == nil {
6666
t.Error("Expected 'maxPipelines' persistent flag to exist")
6767
}
68-
if persistentFlags.Lookup("verbose") == nil {
69-
t.Error("Expected 'verbose' persistent flag to exist")
70-
}
7168
}
7269

7370
func TestBitBucketScanOptions(t *testing.T) {
7471
opts := BitBucketScanOptions{
7572
Email: "test@example.com",
7673
AccessToken: "token123",
77-
Verbose: true,
7874
ConfidenceFilter: []string{"high", "medium"},
7975
MaxScanGoRoutines: 4,
8076
TruffleHogVerification: true,
@@ -94,9 +90,6 @@ func TestBitBucketScanOptions(t *testing.T) {
9490
if opts.AccessToken != "token123" {
9591
t.Errorf("Expected AccessToken 'token123', got %q", opts.AccessToken)
9692
}
97-
if !opts.Verbose {
98-
t.Error("Expected Verbose to be true")
99-
}
10093
if len(opts.ConfidenceFilter) != 2 {
10194
t.Errorf("Expected 2 confidence filters, got %d", len(opts.ConfidenceFilter))
10295
}

src/pipeleak/cmd/devops/devops_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,4 @@ func TestNewScanCmd(t *testing.T) {
8080
if persistentFlags.Lookup("maxBuilds") == nil {
8181
t.Error("Expected 'maxBuilds' persistent flag to exist")
8282
}
83-
if persistentFlags.Lookup("verbose") == nil {
84-
t.Error("Expected 'verbose' persistent flag to exist")
85-
}
8683
}

src/pipeleak/cmd/devops/scan.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
type DevOpsScanOptions struct {
1717
Username string
1818
AccessToken string
19-
Verbose bool
2019
ConfidenceFilter []string
2120
MaxScanGoRoutines int
2221
TruffleHogVerification bool
@@ -78,13 +77,10 @@ pipeleak ad scan --token xxxxxxxxxxx --username auser --artifacts --organization
7877
scanCmd.Flags().StringVarP(&options.Project, "project", "p", "", "Project name to scan - can be combined with organization")
7978
scanCmd.Flags().StringVarP(&options.DevOpsURL, "devops", "d", "https://dev.azure.com", "Azure DevOps base URL")
8079

81-
scanCmd.PersistentFlags().BoolVarP(&options.Verbose, "verbose", "v", false, "Verbose logging")
82-
8380
return scanCmd
8481
}
8582

8683
func Scan(cmd *cobra.Command, args []string) {
87-
logging.SetLogLevel(options.Verbose)
8884
go logging.ShortcutListeners(scanStatus)
8985

9086
runner.InitScanner(options.ConfidenceFilter)

src/pipeleak/cmd/gitea/enum/enum.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import (
44
"fmt"
55

66
"code.gitea.io/sdk/gitea"
7-
"github.com/CompassSecurity/pipeleak/pkg/logging"
87
"github.com/rs/zerolog/log"
98
"github.com/spf13/cobra"
109
)
1110

1211
var (
1312
giteaApiToken string
1413
giteaUrl string
15-
verbose bool
1614
)
1715

1816
func NewEnumCmd() *cobra.Command {
@@ -30,8 +28,6 @@ func NewEnumCmd() *cobra.Command {
3028
}
3129

3230
func Enum(cmd *cobra.Command, args []string) {
33-
logging.SetLogLevel(verbose)
34-
3531
if err := runEnum(giteaUrl, giteaApiToken); err != nil {
3632
log.Fatal().Stack().Err(err).Msg("Enumeration failed")
3733
}

src/pipeleak/cmd/gitea/gitea.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
var (
10-
verbose bool
11-
)
12-
139
func NewGiteaRootCmd() *cobra.Command {
1410
giteaCmd := &cobra.Command{
1511
Use: "gitea [command]",
@@ -21,7 +17,5 @@ func NewGiteaRootCmd() *cobra.Command {
2117
giteaCmd.AddCommand(enum.NewEnumCmd())
2218
giteaCmd.AddCommand(scan.NewScanCmd())
2319

24-
giteaCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose logging")
25-
2620
return giteaCmd
2721
}

src/pipeleak/cmd/gitea/gitea_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ func TestNewGiteaRootCmd(t *testing.T) {
2727
t.Errorf("Expected GroupID 'Gitea', got %q", cmd.GroupID)
2828
}
2929

30-
flags := cmd.PersistentFlags()
31-
if flags.Lookup("verbose") == nil {
32-
t.Error("Expected 'verbose' persistent flag to exist")
33-
}
34-
3530
if len(cmd.Commands()) < 2 {
3631
t.Errorf("Expected at least 2 subcommands, got %d", len(cmd.Commands()))
3732
}

src/pipeleak/cmd/gitea/scan/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type GiteaScanOptions struct {
1818
Token string
1919
GiteaURL string
2020
Artifacts bool
21-
Verbose bool
2221
ConfidenceFilter []string
2322
MaxScanGoRoutines int
2423
TruffleHogVerification bool

src/pipeleak/cmd/gitea/scan/http_utils_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ func setupTestScanOptions() {
479479
Token: "test-token",
480480
GiteaURL: "https://gitea.example.com",
481481
Artifacts: false,
482-
Verbose: false,
483482
ConfidenceFilter: []string{},
484483
MaxScanGoRoutines: 4,
485484
TruffleHogVerification: false,

0 commit comments

Comments
 (0)