Skip to content

Commit

Permalink
fix(influx): enforce flag validation
Browse files Browse the repository at this point in the history
closes: #18629
  • Loading branch information
jsteenb2 committed Jul 23, 2020
1 parent 1247e74 commit 57f1841
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
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
1 change: 0 additions & 1 deletion cmd/influx/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ 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)
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

0 comments on commit 57f1841

Please sign in to comment.