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

chore(influx): update usage and soften comparisons for kind matching on export #18553

Merged
merged 1 commit into from
Jun 16, 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
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