From a029bf287123d70236c3ccefe1e8423ac9d76fc4 Mon Sep 17 00:00:00 2001 From: Daniel Moran Date: Tue, 22 Jun 2021 09:10:03 -0400 Subject: [PATCH] refactor: remove resource-type enums from `export` commands (#137) --- api/contract/cli.yml | 6 +- .../overrides/paths/templates_export.yml | 2 +- api/contract/overrides/schemas/Template.yml | 3 + .../overrides/schemas/TemplateEntry.yml | 13 ++ .../overrides/schemas/TemplateExport.yml | 4 +- api/model_template_entry.gen.go | 12 +- ...el_template_export_resource_filters.gen.go | 14 +- api/model_template_export_resources.gen.go | 16 +-- api/model_template_kind.gen.go | 95 -------------- clients/export/export.go | 113 ++-------------- clients/export/resource.go | 99 -------------- cmd/influx/export.go | 121 ++++++------------ 12 files changed, 91 insertions(+), 407 deletions(-) create mode 100644 api/contract/overrides/schemas/Template.yml create mode 100644 api/contract/overrides/schemas/TemplateEntry.yml delete mode 100644 api/model_template_kind.gen.go delete mode 100644 clients/export/resource.go diff --git a/api/contract/cli.yml b/api/contract/cli.yml index 1c83ab7..557d78c 100644 --- a/api/contract/cli.yml +++ b/api/contract/cli.yml @@ -262,11 +262,9 @@ components: TemplateExport: $ref: "./overrides/schemas/TemplateExport.yml" Template: - $ref: "./openapi/src/common/schemas/Template.yml" - TemplateKind: - $ref: "./openapi/src/common/schemas/TemplateKind.yml" + $ref: "./overrides/schemas/Template.yml" TemplateEntry: - $ref: "./openapi/src/common/schemas/TemplateEntry.yml" + $ref: "./overrides/schemas/TemplateEntry.yml" SecretKeysResponse: $ref: "./openapi/src/common/schemas/SecretKeysResponse.yml" SecretKeys: diff --git a/api/contract/overrides/paths/templates_export.yml b/api/contract/overrides/paths/templates_export.yml index 7501f0f..6b6a16b 100644 --- a/api/contract/overrides/paths/templates_export.yml +++ b/api/contract/overrides/paths/templates_export.yml @@ -16,7 +16,7 @@ post: content: application/json: schema: - $ref: "../../openapi/src/common/schemas/Template.yml" + $ref: "../schemas/Template.yml" default: description: Unexpected error content: diff --git a/api/contract/overrides/schemas/Template.yml b/api/contract/overrides/schemas/Template.yml new file mode 100644 index 0000000..43650ba --- /dev/null +++ b/api/contract/overrides/schemas/Template.yml @@ -0,0 +1,3 @@ +type: array +items: + $ref: "./TemplateEntry.yml" diff --git a/api/contract/overrides/schemas/TemplateEntry.yml b/api/contract/overrides/schemas/TemplateEntry.yml new file mode 100644 index 0000000..59022a1 --- /dev/null +++ b/api/contract/overrides/schemas/TemplateEntry.yml @@ -0,0 +1,13 @@ +type: object +properties: + apiVersion: + type: string + kind: + type: string + meta: + type: object + properties: + name: + type: string + spec: + type: object diff --git a/api/contract/overrides/schemas/TemplateExport.yml b/api/contract/overrides/schemas/TemplateExport.yml index e47e21f..e7475bc 100644 --- a/api/contract/overrides/schemas/TemplateExport.yml +++ b/api/contract/overrides/schemas/TemplateExport.yml @@ -19,7 +19,7 @@ properties: byResourceKind: type: array items: - $ref: "../../openapi/src/common/schemas/TemplateKind.yml" + type: string resources: type: array items: @@ -28,7 +28,7 @@ properties: id: type: string kind: - $ref: "../../openapi/src/common/schemas/TemplateKind.yml" + type: string name: type: string required: [kind] diff --git a/api/model_template_entry.gen.go b/api/model_template_entry.gen.go index 60fcb07..60e1045 100644 --- a/api/model_template_entry.gen.go +++ b/api/model_template_entry.gen.go @@ -17,7 +17,7 @@ import ( // TemplateEntry struct for TemplateEntry type TemplateEntry struct { ApiVersion *string `json:"apiVersion,omitempty"` - Kind *TemplateKind `json:"kind,omitempty"` + Kind *string `json:"kind,omitempty"` Meta *TemplateEntryMeta `json:"meta,omitempty"` Spec *map[string]interface{} `json:"spec,omitempty"` } @@ -72,9 +72,9 @@ func (o *TemplateEntry) SetApiVersion(v string) { } // GetKind returns the Kind field value if set, zero value otherwise. -func (o *TemplateEntry) GetKind() TemplateKind { +func (o *TemplateEntry) GetKind() string { if o == nil || o.Kind == nil { - var ret TemplateKind + var ret string return ret } return *o.Kind @@ -82,7 +82,7 @@ func (o *TemplateEntry) GetKind() TemplateKind { // GetKindOk returns a tuple with the Kind field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *TemplateEntry) GetKindOk() (*TemplateKind, bool) { +func (o *TemplateEntry) GetKindOk() (*string, bool) { if o == nil || o.Kind == nil { return nil, false } @@ -98,8 +98,8 @@ func (o *TemplateEntry) HasKind() bool { return false } -// SetKind gets a reference to the given TemplateKind and assigns it to the Kind field. -func (o *TemplateEntry) SetKind(v TemplateKind) { +// SetKind gets a reference to the given string and assigns it to the Kind field. +func (o *TemplateEntry) SetKind(v string) { o.Kind = &v } diff --git a/api/model_template_export_resource_filters.gen.go b/api/model_template_export_resource_filters.gen.go index 85d9c05..71c4354 100644 --- a/api/model_template_export_resource_filters.gen.go +++ b/api/model_template_export_resource_filters.gen.go @@ -16,8 +16,8 @@ import ( // TemplateExportResourceFilters struct for TemplateExportResourceFilters type TemplateExportResourceFilters struct { - ByLabel *[]string `json:"byLabel,omitempty"` - ByResourceKind *[]TemplateKind `json:"byResourceKind,omitempty"` + ByLabel *[]string `json:"byLabel,omitempty"` + ByResourceKind *[]string `json:"byResourceKind,omitempty"` } // NewTemplateExportResourceFilters instantiates a new TemplateExportResourceFilters object @@ -70,9 +70,9 @@ func (o *TemplateExportResourceFilters) SetByLabel(v []string) { } // GetByResourceKind returns the ByResourceKind field value if set, zero value otherwise. -func (o *TemplateExportResourceFilters) GetByResourceKind() []TemplateKind { +func (o *TemplateExportResourceFilters) GetByResourceKind() []string { if o == nil || o.ByResourceKind == nil { - var ret []TemplateKind + var ret []string return ret } return *o.ByResourceKind @@ -80,7 +80,7 @@ func (o *TemplateExportResourceFilters) GetByResourceKind() []TemplateKind { // GetByResourceKindOk returns a tuple with the ByResourceKind field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *TemplateExportResourceFilters) GetByResourceKindOk() (*[]TemplateKind, bool) { +func (o *TemplateExportResourceFilters) GetByResourceKindOk() (*[]string, bool) { if o == nil || o.ByResourceKind == nil { return nil, false } @@ -96,8 +96,8 @@ func (o *TemplateExportResourceFilters) HasByResourceKind() bool { return false } -// SetByResourceKind gets a reference to the given []TemplateKind and assigns it to the ByResourceKind field. -func (o *TemplateExportResourceFilters) SetByResourceKind(v []TemplateKind) { +// SetByResourceKind gets a reference to the given []string and assigns it to the ByResourceKind field. +func (o *TemplateExportResourceFilters) SetByResourceKind(v []string) { o.ByResourceKind = &v } diff --git a/api/model_template_export_resources.gen.go b/api/model_template_export_resources.gen.go index cc60fa8..da9c17c 100644 --- a/api/model_template_export_resources.gen.go +++ b/api/model_template_export_resources.gen.go @@ -16,16 +16,16 @@ import ( // TemplateExportResources struct for TemplateExportResources type TemplateExportResources struct { - Id *string `json:"id,omitempty"` - Kind TemplateKind `json:"kind"` - Name *string `json:"name,omitempty"` + Id *string `json:"id,omitempty"` + Kind string `json:"kind"` + Name *string `json:"name,omitempty"` } // NewTemplateExportResources instantiates a new TemplateExportResources object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func NewTemplateExportResources(kind TemplateKind) *TemplateExportResources { +func NewTemplateExportResources(kind string) *TemplateExportResources { this := TemplateExportResources{} this.Kind = kind return &this @@ -72,9 +72,9 @@ func (o *TemplateExportResources) SetId(v string) { } // GetKind returns the Kind field value -func (o *TemplateExportResources) GetKind() TemplateKind { +func (o *TemplateExportResources) GetKind() string { if o == nil { - var ret TemplateKind + var ret string return ret } @@ -83,7 +83,7 @@ func (o *TemplateExportResources) GetKind() TemplateKind { // GetKindOk returns a tuple with the Kind field value // and a boolean to check if the value has been set. -func (o *TemplateExportResources) GetKindOk() (*TemplateKind, bool) { +func (o *TemplateExportResources) GetKindOk() (*string, bool) { if o == nil { return nil, false } @@ -91,7 +91,7 @@ func (o *TemplateExportResources) GetKindOk() (*TemplateKind, bool) { } // SetKind sets field value -func (o *TemplateExportResources) SetKind(v TemplateKind) { +func (o *TemplateExportResources) SetKind(v string) { o.Kind = v } diff --git a/api/model_template_kind.gen.go b/api/model_template_kind.gen.go deleted file mode 100644 index 47adf98..0000000 --- a/api/model_template_kind.gen.go +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Subset of Influx API covered by Influx CLI - * - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * API version: 2.0.0 - */ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package api - -import ( - "encoding/json" - "fmt" -) - -// TemplateKind the model 'TemplateKind' -type TemplateKind string - -// List of TemplateKind -const ( - TEMPLATEKIND_BUCKET TemplateKind = "Bucket" - TEMPLATEKIND_CHECK TemplateKind = "Check" - TEMPLATEKIND_CHECK_DEADMAN TemplateKind = "CheckDeadman" - TEMPLATEKIND_CHECK_THRESHOLD TemplateKind = "CheckThreshold" - TEMPLATEKIND_DASHBOARD TemplateKind = "Dashboard" - TEMPLATEKIND_LABEL TemplateKind = "Label" - TEMPLATEKIND_NOTIFICATION_ENDPOINT TemplateKind = "NotificationEndpoint" - TEMPLATEKIND_NOTIFICATION_ENDPOINT_HTTP TemplateKind = "NotificationEndpointHTTP" - TEMPLATEKIND_NOTIFICATION_ENDPOINT_PAGER_DUTY TemplateKind = "NotificationEndpointPagerDuty" - TEMPLATEKIND_NOTIFICATION_ENDPOINT_SLACK TemplateKind = "NotificationEndpointSlack" - TEMPLATEKIND_NOTIFICATION_RULE TemplateKind = "NotificationRule" - TEMPLATEKIND_TASK TemplateKind = "Task" - TEMPLATEKIND_TELEGRAF TemplateKind = "Telegraf" - TEMPLATEKIND_VARIABLE TemplateKind = "Variable" -) - -func (v *TemplateKind) UnmarshalJSON(src []byte) error { - var value string - err := json.Unmarshal(src, &value) - if err != nil { - return err - } - enumTypeValue := TemplateKind(value) - for _, existing := range []TemplateKind{"Bucket", "Check", "CheckDeadman", "CheckThreshold", "Dashboard", "Label", "NotificationEndpoint", "NotificationEndpointHTTP", "NotificationEndpointPagerDuty", "NotificationEndpointSlack", "NotificationRule", "Task", "Telegraf", "Variable"} { - if existing == enumTypeValue { - *v = enumTypeValue - return nil - } - } - - return fmt.Errorf("%+v is not a valid TemplateKind", value) -} - -// Ptr returns reference to TemplateKind value -func (v TemplateKind) Ptr() *TemplateKind { - return &v -} - -type NullableTemplateKind struct { - value *TemplateKind - isSet bool -} - -func (v NullableTemplateKind) Get() *TemplateKind { - return v.value -} - -func (v *NullableTemplateKind) Set(val *TemplateKind) { - v.value = val - v.isSet = true -} - -func (v NullableTemplateKind) IsSet() bool { - return v.isSet -} - -func (v *NullableTemplateKind) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTemplateKind(val *TemplateKind) *NullableTemplateKind { - return &NullableTemplateKind{value: val, isSet: true} -} - -func (v NullableTemplateKind) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableTemplateKind) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} diff --git a/clients/export/export.go b/clients/export/export.go index 210fd2e..0ea22dd 100644 --- a/clients/export/export.go +++ b/clients/export/export.go @@ -18,24 +18,8 @@ type Params struct { OutParams StackId string - BucketIds []string - BucketNames []string - CheckIds []string - CheckNames []string - DashboardIds []string - DashboardNames []string - EndpointIds []string - EndpointNames []string - LabelIds []string - LabelNames []string - RuleIds []string - RuleNames []string - TaskIds []string - TaskNames []string - TelegrafIds []string - TelegrafNames []string - VariableIds []string - VariableNames []string + IdsPerType map[string][]string + NamesPerType map[string][]string } func (c Client) Export(ctx context.Context, params *Params) error { @@ -45,70 +29,20 @@ func (c Client) Export(ctx context.Context, params *Params) error { exportReq.StackID = ¶ms.StackId } - filters := []struct { - kind api.TemplateKind - ids []string - names []string - }{ - { - kind: api.TEMPLATEKIND_BUCKET, - ids: params.BucketIds, - names: params.BucketNames, - }, - { - kind: api.TEMPLATEKIND_CHECK, - ids: params.CheckIds, - names: params.CheckNames, - }, - { - kind: api.TEMPLATEKIND_DASHBOARD, - ids: params.DashboardIds, - names: params.DashboardNames, - }, - { - kind: api.TEMPLATEKIND_LABEL, - ids: params.LabelIds, - names: params.LabelNames, - }, - { - kind: api.TEMPLATEKIND_NOTIFICATION_ENDPOINT, - ids: params.EndpointIds, - names: params.EndpointNames, - }, - { - kind: api.TEMPLATEKIND_NOTIFICATION_RULE, - ids: params.RuleIds, - names: params.RuleNames, - }, - { - kind: api.TEMPLATEKIND_TASK, - ids: params.TaskIds, - names: params.TaskNames, - }, - { - kind: api.TEMPLATEKIND_TELEGRAF, - ids: params.TelegrafIds, - names: params.TelegrafNames, - }, - { - kind: api.TEMPLATEKIND_VARIABLE, - ids: params.VariableIds, - names: params.VariableNames, - }, - } - - for _, filter := range filters { - for _, id := range filter.ids { + for typ, ids := range params.IdsPerType { + for _, id := range ids { id := id exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{ - Kind: filter.kind, + Kind: typ, Id: &id, }) } - for _, name := range filter.names { + } + for typ, names := range params.NamesPerType { + for _, name := range names { name := name exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{ - Kind: filter.kind, + Kind: typ, Name: &name, }) } @@ -131,7 +65,7 @@ type AllParams struct { OrgName string LabelFilters []string - KindFilters []ResourceType + KindFilters []string } func (c Client) ExportAll(ctx context.Context, params *AllParams) error { @@ -162,32 +96,7 @@ func (c Client) ExportAll(ctx context.Context, params *AllParams) error { orgExport.ResourceFilters.ByLabel = ¶ms.LabelFilters } if len(params.KindFilters) > 0 { - kinds := make([]api.TemplateKind, len(params.KindFilters)) - for i, kf := range params.KindFilters { - switch kf { - case TypeBucket: - kinds[i] = api.TEMPLATEKIND_BUCKET - case TypeCheck: - kinds[i] = api.TEMPLATEKIND_CHECK - case TypeDashboard: - kinds[i] = api.TEMPLATEKIND_DASHBOARD - case TypeLabel: - kinds[i] = api.TEMPLATEKIND_LABEL - case TypeNotificationEndpoint: - kinds[i] = api.TEMPLATEKIND_NOTIFICATION_ENDPOINT - case TypeNotificationRule: - kinds[i] = api.TEMPLATEKIND_NOTIFICATION_RULE - case TypeTask: - kinds[i] = api.TEMPLATEKIND_TASK - case TypeTelegraf: - kinds[i] = api.TEMPLATEKIND_TELEGRAF - case TypeVariable: - kinds[i] = api.TEMPLATEKIND_VARIABLE - default: - return fmt.Errorf("unsupported resourceKind filter %q", kf) - } - } - orgExport.ResourceFilters.ByResourceKind = &kinds + orgExport.ResourceFilters.ByResourceKind = ¶ms.KindFilters } } diff --git a/clients/export/resource.go b/clients/export/resource.go deleted file mode 100644 index c0c9559..0000000 --- a/clients/export/resource.go +++ /dev/null @@ -1,99 +0,0 @@ -package export - -import ( - "fmt" - "strings" -) - -type ResourceType int - -const ( - TypeUnset ResourceType = iota - TypeBucket - TypeCheck - TypeCheckDeadman - TypeCheckThreshold - TypeDashboard - TypeLabel - TypeNotificationEndpoint - TypeNotificationEndpointHTTP - TypeNotificationEndpointPagerDuty - TypeNotificationEndpointSlack - TypeNotificationRule - TypeTask - TypeTelegraf - TypeVariable -) - -func (r ResourceType) String() string { - switch r { - case TypeBucket: - return "bucket" - case TypeCheck: - return "check" - case TypeCheckDeadman: - return "checkDeadman" - case TypeCheckThreshold: - return "checkThreshold" - case TypeDashboard: - return "dashboard" - case TypeLabel: - return "label" - case TypeNotificationEndpoint: - return "notificationEndpoint" - case TypeNotificationEndpointHTTP: - return "notificationEndpointHTTP" - case TypeNotificationEndpointPagerDuty: - return "notificationEndpointPagerDuty" - case TypeNotificationEndpointSlack: - return "notificationEndpointSlack" - case TypeNotificationRule: - return "notificationRule" - case TypeTask: - return "task" - case TypeTelegraf: - return "telegraf" - case TypeVariable: - return "variable" - case TypeUnset: - fallthrough - default: - return "unset" - } -} - -func (r *ResourceType) Set(v string) error { - switch strings.ToLower(v) { - case "bucket": - *r = TypeBucket - case "check": - *r = TypeCheck - case "checkdeadman": - *r = TypeCheckDeadman - case "checkthreshold": - *r = TypeCheckThreshold - case "dashboard": - *r = TypeDashboard - case "label": - *r = TypeLabel - case "notificationendpoint": - *r = TypeNotificationEndpoint - case "notificationendpointhttp": - *r = TypeNotificationEndpointHTTP - case "notificationendpointpagerduty": - *r = TypeNotificationEndpointPagerDuty - case "notificationendpointslack": - *r = TypeNotificationEndpointSlack - case "notificationrule": - *r = TypeNotificationRule - case "task": - *r = TypeTask - case "telegraf": - *r = TypeTelegraf - case "variable": - *r = TypeVariable - default: - return fmt.Errorf("unknown resource type: %s", v) - } - return nil -} diff --git a/cmd/influx/export.go b/cmd/influx/export.go index 85ba91c..f9bbf60 100644 --- a/cmd/influx/export.go +++ b/cmd/influx/export.go @@ -17,7 +17,7 @@ func newExportCmd() *cli.Command { var params struct { out string stackId string - resourceType export.ResourceType + resourceType string bucketIds string bucketNames string checkIds string @@ -80,10 +80,10 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`, Usage: "ID for stack to include in export", Destination: ¶ms.stackId, }, - &cli.GenericFlag{ - Name: "resource-type", - Usage: "If specified, strings on stdin/positional args will be treated as IDs of the given type", - Value: ¶ms.resourceType, + &cli.StringFlag{ + Name: "resource-type", + Usage: "If specified, strings on stdin/positional args will be treated as IDs of the given type", + Destination: ¶ms.resourceType, }, &cli.StringFlag{ Name: "buckets", @@ -180,25 +180,29 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`, Before: middleware.WithBeforeFns(withCli(), withApi(true)), Action: func(ctx *cli.Context) error { parsedParams := export.Params{ - StackId: params.stackId, - BucketIds: splitNonEmpty(params.bucketIds), - BucketNames: splitNonEmpty(params.bucketNames), - CheckIds: splitNonEmpty(params.checkIds), - CheckNames: splitNonEmpty(params.checkNames), - DashboardIds: splitNonEmpty(params.dashboardIds), - DashboardNames: splitNonEmpty(params.dashboardNames), - EndpointIds: splitNonEmpty(params.endpointIds), - EndpointNames: splitNonEmpty(params.endpointNames), - LabelIds: splitNonEmpty(params.labelIds), - LabelNames: splitNonEmpty(params.labelNames), - RuleIds: splitNonEmpty(params.ruleIds), - RuleNames: splitNonEmpty(params.ruleNames), - TaskIds: splitNonEmpty(params.taskIds), - TaskNames: splitNonEmpty(params.taskNames), - TelegrafIds: splitNonEmpty(params.telegrafIds), - TelegrafNames: splitNonEmpty(params.telegrafNames), - VariableIds: splitNonEmpty(params.variableIds), - VariableNames: splitNonEmpty(params.variableNames), + StackId: params.stackId, + IdsPerType: map[string][]string{ + "Bucket": splitNonEmpty(params.bucketIds), + "Check": splitNonEmpty(params.checkIds), + "Dashboard": splitNonEmpty(params.dashboardIds), + "NotificationEndpoint": splitNonEmpty(params.endpointIds), + "Label": splitNonEmpty(params.labelIds), + "NotificationRule": splitNonEmpty(params.ruleIds), + "Task": splitNonEmpty(params.taskIds), + "Telegraf": splitNonEmpty(params.telegrafIds), + "Variable": splitNonEmpty(params.variableIds), + }, + NamesPerType: map[string][]string{ + "Bucket": splitNonEmpty(params.bucketNames), + "Check": splitNonEmpty(params.checkNames), + "Dashboard": splitNonEmpty(params.dashboardNames), + "NotificationEndpoint": splitNonEmpty(params.endpointNames), + "Label": splitNonEmpty(params.labelNames), + "NotificationRule": splitNonEmpty(params.ruleNames), + "Task": splitNonEmpty(params.taskNames), + "Telegraf": splitNonEmpty(params.telegrafNames), + "Variable": splitNonEmpty(params.variableNames), + }, } outParams, closer, err := parseOutParams(params.out) @@ -210,7 +214,7 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`, } parsedParams.OutParams = outParams - if params.resourceType != export.TypeUnset { + if params.resourceType != "" { ids := ctx.Args().Slice() // Read any IDs from stdin. @@ -223,43 +227,15 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`, ids = append(ids, strings.Fields(string(inBytes))...) } - switch params.resourceType { - case export.TypeBucket: - parsedParams.BucketIds = append(parsedParams.BucketIds, ids...) - case export.TypeCheck: - parsedParams.CheckIds = append(parsedParams.CheckIds, ids...) - case export.TypeDashboard: - parsedParams.DashboardIds = append(parsedParams.DashboardIds, ids...) - case export.TypeLabel: - parsedParams.LabelIds = append(parsedParams.LabelIds, ids...) - case export.TypeNotificationEndpoint: - parsedParams.EndpointIds = append(parsedParams.EndpointIds, ids...) - case export.TypeNotificationRule: - parsedParams.RuleIds = append(parsedParams.RuleIds, ids...) - case export.TypeTask: - parsedParams.TaskIds = append(parsedParams.TaskIds, ids...) - case export.TypeTelegraf: - parsedParams.TelegrafIds = append(parsedParams.TelegrafIds, ids...) - case export.TypeVariable: - parsedParams.VariableIds = append(parsedParams.VariableIds, ids...) - - // NOTE: The API doesn't support filtering by these resource subtypes, - // and instead converts them to the parent type. For example, - // `--resource-type notificationEndpointHTTP` gets translated to a filter - // on all notification endpoints on the server-side. I think this was - // intentional since the 2.0.x CLI didn't expose flags to filter on subtypes, - // but a bug/oversight in its parsing still allowed the subtypes through - // when passing IDs over stdin. - // Instead of allowing the type-filter to be silently converted by the server, - // we catch the previously-allowed subtypes here and return a (hopefully) useful - // error suggesting the correct flag to use. - case export.TypeCheckDeadman, export.TypeCheckThreshold: - return fmt.Errorf("filtering on resource-type %q is not supported by the API. Use resource-type %q instead", params.resourceType, export.TypeCheck) - case export.TypeNotificationEndpointHTTP, export.TypeNotificationEndpointPagerDuty, export.TypeNotificationEndpointSlack: - return fmt.Errorf("filtering on resource-type %q is not supported by the API. Use resource-type %q instead", params.resourceType, export.TypeNotificationEndpoint) - - default: + if _, ok := parsedParams.IdsPerType[params.resourceType]; !ok { + parsedParams.IdsPerType[params.resourceType] = []string{} } + parsedParams.IdsPerType[params.resourceType] = append(parsedParams.IdsPerType[params.resourceType], ids...) + + if _, ok := parsedParams.NamesPerType[params.resourceType]; !ok { + parsedParams.NamesPerType[params.resourceType] = []string{} + } + parsedParams.NamesPerType[params.resourceType] = append(parsedParams.NamesPerType[params.resourceType], ids...) } else if ctx.NArg() > 0 { return fmt.Errorf("must specify --resource-type when passing IDs as args") } @@ -358,28 +334,7 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/all/ case "labelName": parsedParams.LabelFilters = append(parsedParams.LabelFilters, val) case "kind", "resourceKind": - var resType export.ResourceType - if err := resType.Set(val); err != nil { - return err - } - switch resType { - // NOTE: The API doesn't support filtering by these resource subtypes, - // and instead converts them to the parent type. For example, - // `--resource-type notificationEndpointHTTP` gets translated to a filter - // on all notification endpoints on the server-side. I think this was - // intentional since the 2.0.x CLI didn't expose flags to filter on subtypes, - // but a bug/oversight in its parsing still allowed the subtypes through - // when passing IDs over stdin. - // Instead of allowing the type-filter to be silently converted by the server, - // we catch the previously-allowed subtypes here and return a (hopefully) useful - // error suggesting the correct flag to use. - case export.TypeCheckDeadman, export.TypeCheckThreshold: - return fmt.Errorf("filtering on resourceKind=%s is not supported by the API. Use resourceKind=%s instead", resType, export.TypeCheck) - case export.TypeNotificationEndpointSlack, export.TypeNotificationEndpointPagerDuty, export.TypeNotificationEndpointHTTP: - return fmt.Errorf("filtering on resourceKind=%s is not supported by the API. Use resourceKind=%s instead", resType, export.TypeNotificationEndpoint) - default: - } - parsedParams.KindFilters = append(parsedParams.KindFilters, resType) + parsedParams.KindFilters = append(parsedParams.KindFilters, val) default: return fmt.Errorf("invalid filter provided %q; filter must be 1 in [labelName, resourceKind]", filter) }