Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(influx): enforce flag validation #19043

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v2.0.0-beta.16 [unreleased]

### Bug Fixes

1. [19043](https://github.com/influxdata/influxdb/pull/19043): Enforce all influx CLI flag args are valid


## v2.0.0-beta.15 [2020-07-23]

### Breaking
Expand Down
15 changes: 0 additions & 15 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ func (o genericCLIOpts) newCmd(use string, runE func(*cobra.Command, []string) e
Args: cobra.NoArgs,
Use: use,
RunE: runE,
FParseErrWhitelist: cobra.FParseErrWhitelist{
// allows for unknown flags, parser does not crap the bed
// when providing a flag that doesn't exist/match.
UnknownFlags: true,
},
}

canWrapRunE := runE != nil && o.runEWrapFn != nil
Expand Down Expand Up @@ -563,16 +558,6 @@ func setViperOptions() {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
}

func enforceFlagValidation(cmd *cobra.Command) {
cmd.FParseErrWhitelist = cobra.FParseErrWhitelist{
// disable unknown flags when short flag can conflict with a long flag.
// An example here is the --filter flag provided as -filter=foo will overwrite
// the -f flag to -f=ilter=foo, which generates a bad filename.
// remedies issue: https://github.com/influxdata/influxdb/issues/18850
UnknownFlags: false,
}
}

func writeJSON(w io.Writer, v interface{}) error {
enc := json.NewEncoder(w)
enc.SetIndent("", "\t")
Expand Down
2 changes: 1 addition & 1 deletion cmd/influx/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (b *cmdTelegrafBuilder) readConfig(file string) (string, error) {
func (b *cmdTelegrafBuilder) newCmd(use string, runE func(*cobra.Command, []string) error) *cobra.Command {
cmd := b.genericCLIOpts.newCmd(use, runE, true)
b.genericCLIOpts.registerPrintOptions(cmd)
enforceFlagValidation(cmd)
b.globalFlags.registerFlags(cmd)
return cmd
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/influx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func newCmdPkgerBuilder(svcFn templateSVCsFn, f *globalFlags, opts genericCLIOpt

func (b *cmdTemplateBuilder) cmdApply() *cobra.Command {
cmd := b.newCmd("apply", b.applyRunEFn)
enforceFlagValidation(cmd)
cmd.Short = "Apply a template to manage resources"
cmd.Long = `
The apply command applies InfluxDB template(s). Use the command to create new
Expand Down Expand Up @@ -456,7 +455,6 @@ func (b *cmdTemplateBuilder) cmdExportAll() *cobra.Command {
and
https://v2.docs.influxdata.com/v2.0/reference/cli/influx/export/all
`
enforceFlagValidation(cmd)

cmd.Flags().StringVarP(&b.file, "file", "f", "", "output file for created template; defaults to std out if no file provided; the extension of provided file (.yml/.json) will dictate encoding")
cmd.Flags().StringArrayVar(&b.filters, "filter", nil, "Filter exported resources by labelName or resourceKind (format: --filter=labelName=example)")
Expand Down
1 change: 0 additions & 1 deletion cmd/influx/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var writeFlags writeFlagsType

func cmdWrite(f *globalFlags, opt genericCLIOpts) *cobra.Command {
cmd := opt.newCmd("write", fluxWriteF, true)
enforceFlagValidation(cmd)
cmd.Args = cobra.MaximumNArgs(1)
cmd.Short = "Write points to InfluxDB"
cmd.Long = `Write data to InfluxDB via stdin, or add an entire file specified with the -f flag`
Expand Down