Skip to content

Commit 275bc99

Browse files
committed
chore: add more flags and ensure flag has a name before including
1 parent 064018c commit 275bc99

File tree

8 files changed

+47
-36
lines changed

8 files changed

+47
-36
lines changed

docs/docs/advanced/telemetry.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ The following information could be collected:
1717
The following flags will be included with their value:
1818
<!-- telemetry start -->
1919
```
20+
--debug
2021
--detection-priority
2122
--format
2223
--ignore-status
2324
--include-dev-deps
25+
--insecure
2426
--list-all-pkgs
2527
--misconfig-scanners
2628
--pkg-relationships
2729
--pkg-types
30+
--quiet
2831
--report
2932
--scanners
3033
--severity
3134
--show-suppressed
35+
--timeout
3236
--vuln-severity-source
3337
```
3438
<!-- telemetry end -->

pkg/commands/artifact/run.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ func NewRunner(ctx context.Context, cliOptions flag.Options, opts ...RunnerOptio
118118
opt(r)
119119
}
120120

121-
commandName := "trivy" // backup command, but expecting sub command
121+
// get the sub command name with fallback to trivy for version check telemetry
122+
commandName := "trivy"
122123
if len(os.Args) > 1 {
123124
commandName = os.Args[1]
124125
}
125-
126-
// If the user has not disabled notices or is running in quiet mode
127126
r.versionChecker = notification.NewVersionChecker(commandName, &cliOptions)
128127

129128
// Update the vulnerability database if needed.

pkg/flag/aws_flags.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ var (
1212
Usage: "AWS Endpoint override",
1313
}
1414
awsServiceFlag = Flag[[]string]{
15-
Name: "service",
16-
ConfigName: "cloud.aws.service",
17-
Usage: "Only scan AWS Service(s) specified with this flag. Can specify multiple services using --service A --service B etc.",
15+
Name: "service",
16+
ConfigName: "cloud.aws.service",
17+
Usage: "Only scan AWS Service(s) specified with this flag. Can specify multiple services using --service A --service B etc.",
18+
TelemetrySafe: true,
1819
}
1920
awsSkipServicesFlag = Flag[[]string]{
20-
Name: "skip-service",
21-
ConfigName: "cloud.aws.skip-service",
22-
Usage: "Skip selected AWS Service(s) specified with this flag. Can specify multiple services using --skip-service A --skip-service B etc.",
21+
Name: "skip-service",
22+
ConfigName: "cloud.aws.skip-service",
23+
Usage: "Skip selected AWS Service(s) specified with this flag. Can specify multiple services using --skip-service A --skip-service B etc.",
24+
TelemetrySafe: true,
2325
}
2426
awsAccountFlag = Flag[string]{
2527
Name: "account",

pkg/flag/global_flags.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,35 @@ var (
2727
Persistent: true,
2828
}
2929
QuietFlag = Flag[bool]{
30-
Name: "quiet",
31-
ConfigName: "quiet",
32-
Shorthand: "q",
33-
Usage: "suppress progress bar and log output",
34-
Persistent: true,
30+
Name: "quiet",
31+
ConfigName: "quiet",
32+
Shorthand: "q",
33+
Usage: "suppress progress bar and log output",
34+
Persistent: true,
35+
TelemetrySafe: true,
3536
}
3637
DebugFlag = Flag[bool]{
37-
Name: "debug",
38-
ConfigName: "debug",
39-
Shorthand: "d",
40-
Usage: "debug mode",
41-
Persistent: true,
38+
Name: "debug",
39+
ConfigName: "debug",
40+
Shorthand: "d",
41+
Usage: "debug mode",
42+
Persistent: true,
43+
TelemetrySafe: true,
4244
}
4345
InsecureFlag = Flag[bool]{
44-
Name: "insecure",
45-
ConfigName: "insecure",
46-
Usage: "allow insecure server connections",
47-
Persistent: true,
46+
Name: "insecure",
47+
ConfigName: "insecure",
48+
Usage: "allow insecure server connections",
49+
Persistent: true,
50+
TelemetrySafe: true,
4851
}
4952
TimeoutFlag = Flag[time.Duration]{
50-
Name: "timeout",
51-
ConfigName: "timeout",
52-
Default: time.Second * 300, // 5 mins
53-
Usage: "timeout",
54-
Persistent: true,
53+
Name: "timeout",
54+
ConfigName: "timeout",
55+
Default: time.Second * 300, // 5 mins
56+
Usage: "timeout",
57+
Persistent: true,
58+
TelemetrySafe: true,
5559
}
5660
CacheDirFlag = Flag[string]{
5761
Name: "cache-dir",

pkg/flag/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type Flag[T FlagType] struct {
7676
// Aliases represents aliases
7777
Aliases []Alias
7878

79-
// TelemetrySafe indicates if the flag is safe to be used in telemetry.
79+
// TelemetrySafe indicates if the flag value is safe to be included in telemetry.
8080
TelemetrySafe bool
8181

8282
// value is the value passed through CLI flag, env, or config file.

pkg/notification/flags.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ func getUsedFlags(cliOptions *flag.Options) string {
4343
case flagger[[]string]:
4444
val = strings.Join(ff.Value(), ",")
4545
default:
46-
val = "" // Default case for unsupported types
46+
val = "***" // Default case for unsupported types
4747
}
4848
} else {
49-
val = "******"
49+
val = "***"
50+
}
51+
if f.GetName() != "" {
52+
usedFlags = append(usedFlags, fmt.Sprintf("--%s=%s", f.GetName(), val))
5053
}
51-
usedFlags = append(usedFlags, fmt.Sprintf("--%s=%s", f.GetName(), val))
5254
}
5355
}
5456
}

pkg/notification/flags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestFlagExtraction(t *testing.T) {
4343
{
4444
name: "fs with discrete valued flags",
4545
commandArgs: []string{"fs", "--severity", "HIGH", "--vex", "repo", "--vuln-severity-source", "nvd,debian", "../trivy-ci-test"},
46-
expected: "--severity=HIGH --vex=****** --vuln-severity-source=nvd,debian",
46+
expected: "--severity=HIGH --vex=*** --vuln-severity-source=nvd,debian",
4747
},
4848
{
4949
name: "use short and long flags for same option",

pkg/notification/notice_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ func TestCheckCommandHeaders(t *testing.T) {
401401
command: "fs",
402402
commandArgs: []string{"--severity=HIGH", "--vex", "repo", "--vuln-severity-source", "nvd,debian", "../trivy-ci-test"},
403403
expectedCommandHeader: "fs",
404-
expectedCommandArgsHeader: "--severity=HIGH --vex=****** --vuln-severity-source=nvd,debian",
404+
expectedCommandArgsHeader: "--severity=HIGH --vex=*** --vuln-severity-source=nvd,debian",
405405
},
406406
{
407407
name: "filesystem command with flags including an invalid flag",
408408
command: "fs",
409409
commandArgs: []string{"--severity=HIGH", "--vex", "repo", "--vuln-severity-source", "nvd,debian", "--invalid-flag", "../trivy-ci-test"},
410410
ignoreParseError: true,
411411
expectedCommandHeader: "fs",
412-
expectedCommandArgsHeader: "--severity=HIGH --vex=****** --vuln-severity-source=nvd,debian",
412+
expectedCommandArgsHeader: "--severity=HIGH --vex=*** --vuln-severity-source=nvd,debian",
413413
},
414414
{
415415
name: "filesystem with environment variables",
@@ -419,7 +419,7 @@ func TestCheckCommandHeaders(t *testing.T) {
419419
"TRIVY_SCANNERS": "secret,misconfig",
420420
},
421421
expectedCommandHeader: "fs",
422-
expectedCommandArgsHeader: "--severity=HIGH --scanners=secret,misconfig --vex=******",
422+
expectedCommandArgsHeader: "--severity=HIGH --scanners=secret,misconfig --vex=***",
423423
},
424424
}
425425

0 commit comments

Comments
 (0)