Skip to content

Commit

Permalink
chore(influx): update usage and soften comparisons for kind matching …
Browse files Browse the repository at this point in the history
…on export

closes: #18550
  • Loading branch information
jsteenb2 committed Jun 16, 2020
1 parent 18eff15 commit 61cd72b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
1. [18392](https://github.com/influxdata/influxdb/pull/18392): Consolidate pkg influx commands under templates. This removes some nesting of the CLI commands as part of that.
1. [18400](https://github.com/influxdata/influxdb/pull/18400): Dashboards maintain sort order after navigating away
1. [18480](https://github.com/influxdata/influxdb/pull/18480): Allows tasks to open in new tabs
1. [18553](https://github.com/influxdata/influxdb/pull/18553): Update usage and soften comparisons for kind matching on 'influx export --resourceType' cmd

### Bug Fixes

Expand Down
20 changes: 14 additions & 6 deletions cmd/influx/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error
return err
}

opts := []pkger.CreatePkgSetFn{}

resTypes := []struct {
kind pkger.Kind
idStrs []string
Expand All @@ -331,6 +329,8 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error
{kind: pkger.KindTelegraf, idStrs: strings.Split(b.exportOpts.telegrafs, ",")},
{kind: pkger.KindVariable, idStrs: strings.Split(b.exportOpts.variables, ",")},
}

var opts []pkger.CreatePkgSetFn
for _, rt := range resTypes {
newOpt, err := newResourcesToClone(rt.kind, rt.idStrs)
if err != nil {
Expand All @@ -343,9 +343,17 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error
return b.exportPkg(cmd.OutOrStdout(), pkgSVC, b.file, opts...)
}

kind := pkger.Kind(b.exportOpts.resourceType)
if err := kind.OK(); err != nil {
return errors.New("resource type must be one of bucket|dashboard|label|variable; got: " + b.exportOpts.resourceType)
resType := strings.ToLower(b.exportOpts.resourceType)
resKind := pkger.KindUnknown
for _, k := range pkger.Kinds() {
if strings.ToLower(string(k)) == resType {
resKind = k
break
}
}

if err := resKind.OK(); err != nil {
return errors.New("resource type is invalid; got: " + b.exportOpts.resourceType)
}

if stdin, err := b.inStdIn(); err == nil {
Expand All @@ -355,7 +363,7 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error
}
}

resTypeOpt, err := newResourcesToClone(kind, args)
resTypeOpt, err := newResourcesToClone(resKind, args)
if err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ const (
KindVariable Kind = "Variable"
)

// Kinds is a list of known pkger kinds.
func Kinds() []Kind {
var out []Kind
for k := range kinds {
out = append(out, k)
}
return out
}

var kinds = map[Kind]bool{
KindBucket: true,
KindCheck: true,
Expand Down

0 comments on commit 61cd72b

Please sign in to comment.