fleet/cmd/fleetctl/flags.go
Roberto Dip 33a482448b
improve messaging of fleetctl debug errors and archive commands (#5590)
Related to https://github.com/fleetdm/fleet/issues/5504, this change attempts to improve the output of the `fleetctl debug errors` command by:

- Adding a warning message to redact sensitive data
- Adding a `json` extension to the output file
- Allowing to stream the output to stdout via the `-stdout` flag or the `STDOUT` env var

The output after this changes is:

```
~/projects/fleet $ ./build/fleetctl debug errors
################################################################################
# WARNING:
#   The generated file may contain sensitive data.
#   Please review the file before sharing.
#
#   Output written to: fleet-errors-2022-05-05T12:46:42-03:00.json
################################################################################
```

It also modifies the output of `fleetctl debug archive`

```
################################################################################
# WARNING:
#   The files in the generated archive may contain sensitive data.
#   Please review them before sharing.
#
#   Archive written to: fleet-profiles-archive-2022-05-05T12:46:59-03:00.tar.gz
################################################################################
```
2022-05-10 10:44:06 -03:00

60 lines
1.3 KiB
Go

package main
import "github.com/urfave/cli/v2"
const (
outfileFlagName = "outfile"
debugFlagName = "debug"
fleetCertificateFlagName = "fleet-certificate"
stdoutFlagName = "stdout"
)
func outfileFlag() cli.Flag {
return &cli.StringFlag{
Name: outfileFlagName,
Value: "",
EnvVars: []string{"OUTFILE"},
Usage: "Path to output file",
}
}
func getOutfile(c *cli.Context) string {
return c.String(outfileFlagName)
}
func debugFlag() cli.Flag {
return &cli.BoolFlag{
Name: debugFlagName,
EnvVars: []string{"DEBUG"},
Usage: "Enable debug http request logging",
}
}
func getDebug(c *cli.Context) bool {
return c.Bool(debugFlagName)
}
func fleetCertificateFlag() cli.Flag {
return &cli.StringFlag{
Name: fleetCertificateFlagName,
EnvVars: []string{"FLEET_CERTIFICATE"},
Usage: "Path of the TLS fleet certificate, can be used to provide additional connection debugging information",
}
}
func getFleetCertificate(c *cli.Context) string {
return c.String(fleetCertificateFlagName)
}
func stdoutFlag() cli.Flag {
return &cli.BoolFlag{
Name: stdoutFlagName,
EnvVars: []string{"STDOUT"},
Usage: "Print contents to stdout",
}
}
func getStdout(c *cli.Context) bool {
return c.Bool(stdoutFlagName)
}