Skip to content

Commit 09e4f72

Browse files
authored
[POA-2246] Display warning when repro mode flag is used (#91)
This change will display the following warning when the `--repro-mode` flag is set on a command that supports it: ``` [WARNING] Turning on the --repro-mode flag enbales the Postman Insights Agent to send payload data to the Postman cloud. The Postman Insights Agent will automatically redact values in a default list of sensitive fields, as well as any additionally specified fields. For more information, please see: https://postmanlabs.atlassian.net/wiki/spaces/PIIUG/pages/5513740658/Data+handling+and+access#When-Repro-Mode-is-enabled. ``` --- ### Previews with various log formats With `--log-format` set to `color`: <img width="1172" alt="Screenshot 2025-03-13 at 2 23 15 PM" src="https://github.com/user-attachments/assets/96f8aad3-023c-45d5-a189-6691c6baadc8" /> With `--log-format` set to `plain`: <img width="1172" alt="Screenshot 2025-03-13 at 2 24 54 PM" src="https://github.com/user-attachments/assets/2f88e456-0a8c-4245-87ba-27f2ae6f4121" /> With `--log-format` set to `json`: <img width="1172" alt="Screenshot 2025-03-13 at 2 25 47 PM" src="https://github.com/user-attachments/assets/054ed581-3773-43c4-815f-d3b85d055c8b" /> --- ### Manual tests I manually verified, doesn't look like we have a test suite for this, that the warning is only shown on on commands that actually support the flag. For example, passing `--repro-mode` to `./bin/postman-insights-agent kube` or just `./bin/postman-insights-agent` will display an error: ``` [ERROR] unknown flag: --repro-mode ```
1 parent 36cd55b commit 09e4f72

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

cmd/root.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,21 @@ var (
4242
logFormatFlag string
4343
)
4444

45-
var (
46-
rootCmd = &cobra.Command{
47-
Use: "postman-insights-agent",
48-
Short: "The Postman Insights Agent",
49-
Long: "Documentation is available at https://learning.postman.com/docs/insights/insights-early-access/",
50-
Version: version.CLIDisplayString(),
51-
SilenceErrors: true, // We print our own errors from subcommands in Execute function
52-
// Don't print usage after error, we only print help if we cannot parse
53-
// flags. See init function below.
54-
SilenceUsage: true,
55-
RunE: func(cmd *cobra.Command, args []string) error {
56-
return cmd.Help()
57-
},
58-
PersistentPreRun: preRun,
59-
PersistentPostRun: stopProfiling,
60-
}
61-
)
45+
var rootCmd = &cobra.Command{
46+
Use: "postman-insights-agent",
47+
Short: "The Postman Insights Agent",
48+
Long: "Documentation is available at https://learning.postman.com/docs/insights/insights-early-access/",
49+
Version: version.CLIDisplayString(),
50+
SilenceErrors: true, // We print our own errors from subcommands in Execute function
51+
// Don't print usage after error, we only print help if we cannot parse
52+
// flags. See init function below.
53+
SilenceUsage: true,
54+
RunE: func(cmd *cobra.Command, args []string) error {
55+
return cmd.Help()
56+
},
57+
PersistentPreRun: preRun,
58+
PersistentPostRun: stopProfiling,
59+
}
6260

6361
func preRun(cmd *cobra.Command, args []string) {
6462
// Decide on the domain name to use, _before_ initializing telemetry,
@@ -96,7 +94,7 @@ func preRun(cmd *cobra.Command, args []string) {
9694

9795
startProfiling(cmd, args)
9896

99-
printFlagsWarning()
97+
printFlagsWarning(cmd)
10098
}
10199

102100
func startProfiling(cmd *cobra.Command, args []string) {
@@ -143,7 +141,14 @@ func stopProfiling(cmd *cobra.Command, args []string) {
143141
}
144142
}
145143

146-
func printFlagsWarning() {
144+
func printFlagsWarning(cmd *cobra.Command) {
145+
if enabled, err := cmd.Flags().GetBool("repro-mode"); err == nil && enabled {
146+
util.PrintReproModeWarning("--repro-mode")
147+
}
148+
if enabled, err := cmd.Flags().GetBool("send-witness-payloads"); err == nil && enabled {
149+
util.PrintReproModeWarning("--send-witness-payloads")
150+
}
151+
147152
testingFlags := make(map[string]string)
148153

149154
if testOnlyUseHTTPSFlag {

util/printWarningMsg.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ func PrintFlagsWarning(warningFlags map[string]string) {
3636
// Print new line
3737
fmt.Printf("\n")
3838
}
39+
40+
const reproModeMessage = `Turning on the %s flag enables the Postman Insights Agent to send payload data to the Postman cloud.
41+
42+
The Postman Insights Agent will automatically redact values in a default list of sensitive fields, as well as any additionally specified fields.
43+
For more information, please see: %s.
44+
`
45+
46+
func PrintReproModeWarning(flag string) {
47+
printer.Warningf(reproModeMessage,
48+
printer.Color.Yellow(flag),
49+
printer.Color.Blue("https://postmanlabs.atlassian.net/wiki/spaces/PIIUG/pages/5513740658/Data+handling+and+access#When-Repro-Mode-is-enabled"))
50+
}

0 commit comments

Comments
 (0)