refactor: remove resource-type enums from export
commands (#137)
This commit is contained in:
@ -262,11 +262,9 @@ components:
|
|||||||
TemplateExport:
|
TemplateExport:
|
||||||
$ref: "./overrides/schemas/TemplateExport.yml"
|
$ref: "./overrides/schemas/TemplateExport.yml"
|
||||||
Template:
|
Template:
|
||||||
$ref: "./openapi/src/common/schemas/Template.yml"
|
$ref: "./overrides/schemas/Template.yml"
|
||||||
TemplateKind:
|
|
||||||
$ref: "./openapi/src/common/schemas/TemplateKind.yml"
|
|
||||||
TemplateEntry:
|
TemplateEntry:
|
||||||
$ref: "./openapi/src/common/schemas/TemplateEntry.yml"
|
$ref: "./overrides/schemas/TemplateEntry.yml"
|
||||||
SecretKeysResponse:
|
SecretKeysResponse:
|
||||||
$ref: "./openapi/src/common/schemas/SecretKeysResponse.yml"
|
$ref: "./openapi/src/common/schemas/SecretKeysResponse.yml"
|
||||||
SecretKeys:
|
SecretKeys:
|
||||||
|
@ -16,7 +16,7 @@ post:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "../../openapi/src/common/schemas/Template.yml"
|
$ref: "../schemas/Template.yml"
|
||||||
default:
|
default:
|
||||||
description: Unexpected error
|
description: Unexpected error
|
||||||
content:
|
content:
|
||||||
|
3
api/contract/overrides/schemas/Template.yml
Normal file
3
api/contract/overrides/schemas/Template.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "./TemplateEntry.yml"
|
13
api/contract/overrides/schemas/TemplateEntry.yml
Normal file
13
api/contract/overrides/schemas/TemplateEntry.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
apiVersion:
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
type: string
|
||||||
|
meta:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
spec:
|
||||||
|
type: object
|
@ -19,7 +19,7 @@ properties:
|
|||||||
byResourceKind:
|
byResourceKind:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "../../openapi/src/common/schemas/TemplateKind.yml"
|
type: string
|
||||||
resources:
|
resources:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
@ -28,7 +28,7 @@ properties:
|
|||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
kind:
|
kind:
|
||||||
$ref: "../../openapi/src/common/schemas/TemplateKind.yml"
|
type: string
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
required: [kind]
|
required: [kind]
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
// TemplateEntry struct for TemplateEntry
|
// TemplateEntry struct for TemplateEntry
|
||||||
type TemplateEntry struct {
|
type TemplateEntry struct {
|
||||||
ApiVersion *string `json:"apiVersion,omitempty"`
|
ApiVersion *string `json:"apiVersion,omitempty"`
|
||||||
Kind *TemplateKind `json:"kind,omitempty"`
|
Kind *string `json:"kind,omitempty"`
|
||||||
Meta *TemplateEntryMeta `json:"meta,omitempty"`
|
Meta *TemplateEntryMeta `json:"meta,omitempty"`
|
||||||
Spec *map[string]interface{} `json:"spec,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.
|
// 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 {
|
if o == nil || o.Kind == nil {
|
||||||
var ret TemplateKind
|
var ret string
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
return *o.Kind
|
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
|
// GetKindOk returns a tuple with the Kind field value if set, nil otherwise
|
||||||
// and a boolean to check if the value has been set.
|
// 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 {
|
if o == nil || o.Kind == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -98,8 +98,8 @@ func (o *TemplateEntry) HasKind() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetKind gets a reference to the given TemplateKind and assigns it to the Kind field.
|
// SetKind gets a reference to the given string and assigns it to the Kind field.
|
||||||
func (o *TemplateEntry) SetKind(v TemplateKind) {
|
func (o *TemplateEntry) SetKind(v string) {
|
||||||
o.Kind = &v
|
o.Kind = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
// TemplateExportResourceFilters struct for TemplateExportResourceFilters
|
// TemplateExportResourceFilters struct for TemplateExportResourceFilters
|
||||||
type TemplateExportResourceFilters struct {
|
type TemplateExportResourceFilters struct {
|
||||||
ByLabel *[]string `json:"byLabel,omitempty"`
|
ByLabel *[]string `json:"byLabel,omitempty"`
|
||||||
ByResourceKind *[]TemplateKind `json:"byResourceKind,omitempty"`
|
ByResourceKind *[]string `json:"byResourceKind,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTemplateExportResourceFilters instantiates a new TemplateExportResourceFilters object
|
// 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.
|
// 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 {
|
if o == nil || o.ByResourceKind == nil {
|
||||||
var ret []TemplateKind
|
var ret []string
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
return *o.ByResourceKind
|
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
|
// GetByResourceKindOk returns a tuple with the ByResourceKind field value if set, nil otherwise
|
||||||
// and a boolean to check if the value has been set.
|
// 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 {
|
if o == nil || o.ByResourceKind == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -96,8 +96,8 @@ func (o *TemplateExportResourceFilters) HasByResourceKind() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetByResourceKind gets a reference to the given []TemplateKind and assigns it to the ByResourceKind field.
|
// SetByResourceKind gets a reference to the given []string and assigns it to the ByResourceKind field.
|
||||||
func (o *TemplateExportResourceFilters) SetByResourceKind(v []TemplateKind) {
|
func (o *TemplateExportResourceFilters) SetByResourceKind(v []string) {
|
||||||
o.ByResourceKind = &v
|
o.ByResourceKind = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
// TemplateExportResources struct for TemplateExportResources
|
// TemplateExportResources struct for TemplateExportResources
|
||||||
type TemplateExportResources struct {
|
type TemplateExportResources struct {
|
||||||
Id *string `json:"id,omitempty"`
|
Id *string `json:"id,omitempty"`
|
||||||
Kind TemplateKind `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
Name *string `json:"name,omitempty"`
|
Name *string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ type TemplateExportResources struct {
|
|||||||
// This constructor will assign default values to properties that have it defined,
|
// 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
|
// and makes sure properties required by API are set, but the set of arguments
|
||||||
// will change when the set of required properties is changed
|
// will change when the set of required properties is changed
|
||||||
func NewTemplateExportResources(kind TemplateKind) *TemplateExportResources {
|
func NewTemplateExportResources(kind string) *TemplateExportResources {
|
||||||
this := TemplateExportResources{}
|
this := TemplateExportResources{}
|
||||||
this.Kind = kind
|
this.Kind = kind
|
||||||
return &this
|
return &this
|
||||||
@ -72,9 +72,9 @@ func (o *TemplateExportResources) SetId(v string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetKind returns the Kind field value
|
// GetKind returns the Kind field value
|
||||||
func (o *TemplateExportResources) GetKind() TemplateKind {
|
func (o *TemplateExportResources) GetKind() string {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
var ret TemplateKind
|
var ret string
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ func (o *TemplateExportResources) GetKind() TemplateKind {
|
|||||||
|
|
||||||
// GetKindOk returns a tuple with the Kind field value
|
// GetKindOk returns a tuple with the Kind field value
|
||||||
// and a boolean to check if the value has been set.
|
// 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 {
|
if o == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func (o *TemplateExportResources) GetKindOk() (*TemplateKind, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetKind sets field value
|
// SetKind sets field value
|
||||||
func (o *TemplateExportResources) SetKind(v TemplateKind) {
|
func (o *TemplateExportResources) SetKind(v string) {
|
||||||
o.Kind = v
|
o.Kind = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
}
|
|
@ -18,24 +18,8 @@ type Params struct {
|
|||||||
OutParams
|
OutParams
|
||||||
StackId string
|
StackId string
|
||||||
|
|
||||||
BucketIds []string
|
IdsPerType map[string][]string
|
||||||
BucketNames []string
|
NamesPerType map[string][]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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Export(ctx context.Context, params *Params) error {
|
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
|
exportReq.StackID = ¶ms.StackId
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := []struct {
|
for typ, ids := range params.IdsPerType {
|
||||||
kind api.TemplateKind
|
for _, id := range ids {
|
||||||
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 {
|
|
||||||
id := id
|
id := id
|
||||||
exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{
|
exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{
|
||||||
Kind: filter.kind,
|
Kind: typ,
|
||||||
Id: &id,
|
Id: &id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, name := range filter.names {
|
}
|
||||||
|
for typ, names := range params.NamesPerType {
|
||||||
|
for _, name := range names {
|
||||||
name := name
|
name := name
|
||||||
exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{
|
exportReq.Resources = append(exportReq.Resources, api.TemplateExportResources{
|
||||||
Kind: filter.kind,
|
Kind: typ,
|
||||||
Name: &name,
|
Name: &name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -131,7 +65,7 @@ type AllParams struct {
|
|||||||
OrgName string
|
OrgName string
|
||||||
|
|
||||||
LabelFilters []string
|
LabelFilters []string
|
||||||
KindFilters []ResourceType
|
KindFilters []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) ExportAll(ctx context.Context, params *AllParams) error {
|
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
|
orgExport.ResourceFilters.ByLabel = ¶ms.LabelFilters
|
||||||
}
|
}
|
||||||
if len(params.KindFilters) > 0 {
|
if len(params.KindFilters) > 0 {
|
||||||
kinds := make([]api.TemplateKind, len(params.KindFilters))
|
orgExport.ResourceFilters.ByResourceKind = ¶ms.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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -17,7 +17,7 @@ func newExportCmd() *cli.Command {
|
|||||||
var params struct {
|
var params struct {
|
||||||
out string
|
out string
|
||||||
stackId string
|
stackId string
|
||||||
resourceType export.ResourceType
|
resourceType string
|
||||||
bucketIds string
|
bucketIds string
|
||||||
bucketNames string
|
bucketNames string
|
||||||
checkIds 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",
|
Usage: "ID for stack to include in export",
|
||||||
Destination: ¶ms.stackId,
|
Destination: ¶ms.stackId,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "resource-type",
|
Name: "resource-type",
|
||||||
Usage: "If specified, strings on stdin/positional args will be treated as IDs of the given type",
|
Usage: "If specified, strings on stdin/positional args will be treated as IDs of the given type",
|
||||||
Value: ¶ms.resourceType,
|
Destination: ¶ms.resourceType,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "buckets",
|
Name: "buckets",
|
||||||
@ -181,24 +181,28 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`,
|
|||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
parsedParams := export.Params{
|
parsedParams := export.Params{
|
||||||
StackId: params.stackId,
|
StackId: params.stackId,
|
||||||
BucketIds: splitNonEmpty(params.bucketIds),
|
IdsPerType: map[string][]string{
|
||||||
BucketNames: splitNonEmpty(params.bucketNames),
|
"Bucket": splitNonEmpty(params.bucketIds),
|
||||||
CheckIds: splitNonEmpty(params.checkIds),
|
"Check": splitNonEmpty(params.checkIds),
|
||||||
CheckNames: splitNonEmpty(params.checkNames),
|
"Dashboard": splitNonEmpty(params.dashboardIds),
|
||||||
DashboardIds: splitNonEmpty(params.dashboardIds),
|
"NotificationEndpoint": splitNonEmpty(params.endpointIds),
|
||||||
DashboardNames: splitNonEmpty(params.dashboardNames),
|
"Label": splitNonEmpty(params.labelIds),
|
||||||
EndpointIds: splitNonEmpty(params.endpointIds),
|
"NotificationRule": splitNonEmpty(params.ruleIds),
|
||||||
EndpointNames: splitNonEmpty(params.endpointNames),
|
"Task": splitNonEmpty(params.taskIds),
|
||||||
LabelIds: splitNonEmpty(params.labelIds),
|
"Telegraf": splitNonEmpty(params.telegrafIds),
|
||||||
LabelNames: splitNonEmpty(params.labelNames),
|
"Variable": splitNonEmpty(params.variableIds),
|
||||||
RuleIds: splitNonEmpty(params.ruleIds),
|
},
|
||||||
RuleNames: splitNonEmpty(params.ruleNames),
|
NamesPerType: map[string][]string{
|
||||||
TaskIds: splitNonEmpty(params.taskIds),
|
"Bucket": splitNonEmpty(params.bucketNames),
|
||||||
TaskNames: splitNonEmpty(params.taskNames),
|
"Check": splitNonEmpty(params.checkNames),
|
||||||
TelegrafIds: splitNonEmpty(params.telegrafIds),
|
"Dashboard": splitNonEmpty(params.dashboardNames),
|
||||||
TelegrafNames: splitNonEmpty(params.telegrafNames),
|
"NotificationEndpoint": splitNonEmpty(params.endpointNames),
|
||||||
VariableIds: splitNonEmpty(params.variableIds),
|
"Label": splitNonEmpty(params.labelNames),
|
||||||
VariableNames: splitNonEmpty(params.variableNames),
|
"NotificationRule": splitNonEmpty(params.ruleNames),
|
||||||
|
"Task": splitNonEmpty(params.taskNames),
|
||||||
|
"Telegraf": splitNonEmpty(params.telegrafNames),
|
||||||
|
"Variable": splitNonEmpty(params.variableNames),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
outParams, closer, err := parseOutParams(params.out)
|
outParams, closer, err := parseOutParams(params.out)
|
||||||
@ -210,7 +214,7 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`,
|
|||||||
}
|
}
|
||||||
parsedParams.OutParams = outParams
|
parsedParams.OutParams = outParams
|
||||||
|
|
||||||
if params.resourceType != export.TypeUnset {
|
if params.resourceType != "" {
|
||||||
ids := ctx.Args().Slice()
|
ids := ctx.Args().Slice()
|
||||||
|
|
||||||
// Read any IDs from stdin.
|
// 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))...)
|
ids = append(ids, strings.Fields(string(inBytes))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch params.resourceType {
|
if _, ok := parsedParams.IdsPerType[params.resourceType]; !ok {
|
||||||
case export.TypeBucket:
|
parsedParams.IdsPerType[params.resourceType] = []string{}
|
||||||
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:
|
|
||||||
}
|
}
|
||||||
|
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 {
|
} else if ctx.NArg() > 0 {
|
||||||
return fmt.Errorf("must specify --resource-type when passing IDs as args")
|
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":
|
case "labelName":
|
||||||
parsedParams.LabelFilters = append(parsedParams.LabelFilters, val)
|
parsedParams.LabelFilters = append(parsedParams.LabelFilters, val)
|
||||||
case "kind", "resourceKind":
|
case "kind", "resourceKind":
|
||||||
var resType export.ResourceType
|
parsedParams.KindFilters = append(parsedParams.KindFilters, val)
|
||||||
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)
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid filter provided %q; filter must be 1 in [labelName, resourceKind]", filter)
|
return fmt.Errorf("invalid filter provided %q; filter must be 1 in [labelName, resourceKind]", filter)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user