chore: refactor influxid.ID
, cleanup organization checking (#326)
This commit is contained in:
@ -21,8 +21,7 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Params struct {
|
type Params struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
StackId string
|
StackId string
|
||||||
Sources []template.Source
|
Sources []template.Source
|
||||||
@ -46,7 +45,7 @@ type ResourceFilter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Apply(ctx context.Context, params *Params) error {
|
func (c Client) Apply(ctx context.Context, params *Params) error {
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -164,7 +163,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(l.Id).String()
|
hexId := influxid.Encode(l.Id)
|
||||||
if l.Old != nil {
|
if l.Old != nil {
|
||||||
oldRow = buildRow(l.TemplateMetaName, hexId, *l.Old)
|
oldRow = buildRow(l.TemplateMetaName, hexId, *l.Old)
|
||||||
}
|
}
|
||||||
@ -196,7 +195,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, b := range bkts {
|
for _, b := range bkts {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(b.Id).String()
|
hexId := influxid.Encode(b.Id)
|
||||||
if b.Old != nil {
|
if b.Old != nil {
|
||||||
oldRow = buildRow(b.TemplateMetaName, hexId, *b.Old)
|
oldRow = buildRow(b.TemplateMetaName, hexId, *b.Old)
|
||||||
}
|
}
|
||||||
@ -220,7 +219,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(c.Id).String()
|
hexId := influxid.Encode(c.Id)
|
||||||
if c.Old != nil {
|
if c.Old != nil {
|
||||||
oldRow = buildRow(c.TemplateMetaName, hexId, *c.Old)
|
oldRow = buildRow(c.TemplateMetaName, hexId, *c.Old)
|
||||||
}
|
}
|
||||||
@ -244,7 +243,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, d := range dashboards {
|
for _, d := range dashboards {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(d.Id).String()
|
hexId := influxid.Encode(d.Id)
|
||||||
if d.Old != nil {
|
if d.Old != nil {
|
||||||
oldRow = buildRow(d.TemplateMetaName, hexId, *d.Old)
|
oldRow = buildRow(d.TemplateMetaName, hexId, *d.Old)
|
||||||
}
|
}
|
||||||
@ -264,7 +263,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, e := range endpoints {
|
for _, e := range endpoints {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(e.Id).String()
|
hexId := influxid.Encode(e.Id)
|
||||||
if e.Old != nil {
|
if e.Old != nil {
|
||||||
oldRow = buildRow(e.TemplateMetaName, hexId, *e.Old)
|
oldRow = buildRow(e.TemplateMetaName, hexId, *e.Old)
|
||||||
}
|
}
|
||||||
@ -284,12 +283,12 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
if nrf.Description != nil {
|
if nrf.Description != nil {
|
||||||
desc = *nrf.Description
|
desc = *nrf.Description
|
||||||
}
|
}
|
||||||
eid := influxid.ID(nrf.EndpointID).String()
|
eid := influxid.Encode(nrf.EndpointID)
|
||||||
return []string{metaName, id, nrf.Name, desc, nrf.Every, nrf.Offset, nrf.EndpointName, eid, nrf.EndpointType}
|
return []string{metaName, id, nrf.Name, desc, nrf.Every, nrf.Offset, nrf.EndpointName, eid, nrf.EndpointType}
|
||||||
}
|
}
|
||||||
for _, r := range rules {
|
for _, r := range rules {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(r.Id).String()
|
hexId := influxid.Encode(r.Id)
|
||||||
if r.Old != nil {
|
if r.Old != nil {
|
||||||
oldRow = buildRow(r.TemplateMetaName, hexId, *r.Old)
|
oldRow = buildRow(r.TemplateMetaName, hexId, *r.Old)
|
||||||
}
|
}
|
||||||
@ -313,7 +312,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, t := range teles {
|
for _, t := range teles {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(t.Id).String()
|
hexId := influxid.Encode(t.Id)
|
||||||
if t.Old != nil {
|
if t.Old != nil {
|
||||||
oldRow = buildRow(t.TemplateMetaName, hexId, *t.Old)
|
oldRow = buildRow(t.TemplateMetaName, hexId, *t.Old)
|
||||||
}
|
}
|
||||||
@ -348,7 +347,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(t.Id).String()
|
hexId := influxid.Encode(t.Id)
|
||||||
if t.Old != nil {
|
if t.Old != nil {
|
||||||
oldRow = buildRow(t.TemplateMetaName, hexId, *t.Old)
|
oldRow = buildRow(t.TemplateMetaName, hexId, *t.Old)
|
||||||
}
|
}
|
||||||
@ -375,7 +374,7 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
}
|
}
|
||||||
for _, v := range vars {
|
for _, v := range vars {
|
||||||
var oldRow, newRow []string
|
var oldRow, newRow []string
|
||||||
hexId := influxid.ID(v.Id).String()
|
hexId := influxid.Encode(v.Id)
|
||||||
if v.Old != nil {
|
if v.Old != nil {
|
||||||
oldRow = buildRow(v.TemplateMetaName, hexId, *v.Old)
|
oldRow = buildRow(v.TemplateMetaName, hexId, *v.Old)
|
||||||
}
|
}
|
||||||
@ -394,8 +393,8 @@ func (c Client) printDiff(diff api.TemplateSummaryDiff, params *Params) error {
|
|||||||
SetHeaders("Resource Type", "Resource Meta Name", "Resource Name", "Resource ID", "Label Package Name", "Label Name", "Label ID")
|
SetHeaders("Resource Type", "Resource Meta Name", "Resource Name", "Resource ID", "Label Package Name", "Label Name", "Label ID")
|
||||||
|
|
||||||
for _, m := range mappings {
|
for _, m := range mappings {
|
||||||
resId := influxid.ID(m.ResourceID).String()
|
resId := influxid.Encode(m.ResourceID)
|
||||||
labelId := influxid.ID(m.LabelID).String()
|
labelId := influxid.Encode(m.LabelID)
|
||||||
row := []string{m.ResourceType, m.ResourceName, resId, m.LabelTemplateMetaName, m.LabelName, labelId}
|
row := []string{m.ResourceType, m.ResourceName, resId, m.LabelTemplateMetaName, m.LabelName, labelId}
|
||||||
switch m.StateStatus {
|
switch m.StateStatus {
|
||||||
case "new":
|
case "new":
|
||||||
|
@ -107,8 +107,7 @@ func BuildResourcePermissions() []*ResourcePermission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||||
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgParams)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -131,7 +130,7 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
for _, bp := range bucketPerms {
|
for _, bp := range bucketPerms {
|
||||||
for _, p := range bp.perms {
|
for _, p := range bp.perms {
|
||||||
// verify the input ID
|
// verify the input ID
|
||||||
if _, err := influxid.IDFromString(p); err != nil {
|
if err := influxid.Validate(p); err != nil {
|
||||||
return fmt.Errorf("invalid bucket ID '%s': %w (did you pass a bucket name instead of an ID?)", p, err)
|
return fmt.Errorf("invalid bucket ID '%s': %w (did you pass a bucket name instead of an ID?)", p, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,8 +306,8 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
req.Org(params.OrgName)
|
req.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req.OrgID(params.OrgID.String())
|
req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
auths, err := req.Execute()
|
auths, err := req.Execute()
|
||||||
@ -454,7 +453,3 @@ func makePermResource(permType string, id string, orgId string) api.PermissionRe
|
|||||||
}
|
}
|
||||||
return pr
|
return pr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrgID(ctx context.Context, params clients.OrgParams) (string, error) {
|
|
||||||
return c.GetOrgIdI(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
|
||||||
}
|
|
||||||
|
@ -32,13 +32,11 @@ type Client struct {
|
|||||||
type Params struct {
|
type Params struct {
|
||||||
// Organization containing TSM data to back up.
|
// Organization containing TSM data to back up.
|
||||||
// If not set, all orgs will be included.
|
// If not set, all orgs will be included.
|
||||||
OrgID string
|
clients.OrgParams
|
||||||
Org string
|
|
||||||
|
|
||||||
// Bucket containing TSM data to back up.
|
// Bucket containing TSM data to back up.
|
||||||
// If not set, all buckets within the org filter will be included.
|
// If not set, all buckets within the org filter will be included.
|
||||||
BucketID string
|
clients.BucketParams
|
||||||
Bucket string
|
|
||||||
|
|
||||||
// Path to the directory where backup files should be written.
|
// Path to the directory where backup files should be written.
|
||||||
Path string
|
Path string
|
||||||
@ -51,13 +49,13 @@ func (p *Params) matches(bkt api.BucketMetadataManifest) bool {
|
|||||||
if p.OrgID != "" && bkt.OrganizationID != p.OrgID {
|
if p.OrgID != "" && bkt.OrganizationID != p.OrgID {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.Org != "" && bkt.OrganizationName != p.Org {
|
if p.OrgName != "" && bkt.OrganizationName != p.OrgName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.BucketID != "" && bkt.BucketID != p.BucketID {
|
if p.BucketID != "" && bkt.BucketID != p.BucketID {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.Bucket != "" && bkt.BucketName != p.Bucket {
|
if p.BucketName != "" && bkt.BucketName != p.BucketName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -11,8 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BucketsCreateParams struct {
|
type BucketsCreateParams struct {
|
||||||
OrgID string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Retention string
|
Retention string
|
||||||
@ -21,8 +20,9 @@ type BucketsCreateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
|
func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
|
||||||
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rp, err := duration.RawDurationToTimeDuration(params.Retention)
|
rp, err := duration.RawDurationToTimeDuration(params.Retention)
|
||||||
@ -35,7 +35,7 @@ func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reqBody := api.PostBucketRequest{
|
reqBody := api.PostBucketRequest{
|
||||||
OrgID: params.OrgID,
|
OrgID: orgId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
RetentionRules: []api.RetentionRule{},
|
RetentionRules: []api.RetentionRule{},
|
||||||
SchemaType: ¶ms.SchemaType,
|
SchemaType: ¶ms.SchemaType,
|
||||||
@ -59,21 +59,6 @@ func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
|
|||||||
}
|
}
|
||||||
reqBody.RetentionRules = append(reqBody.RetentionRules, *rule)
|
reqBody.RetentionRules = append(reqBody.RetentionRules, *rule)
|
||||||
}
|
}
|
||||||
if reqBody.OrgID == "" {
|
|
||||||
name := params.OrgName
|
|
||||||
if name == "" {
|
|
||||||
name = c.ActiveConfig.Org
|
|
||||||
}
|
|
||||||
resp, err := c.GetOrgs(ctx).Org(name).Execute()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to lookup ID of org %q: %w", name, err)
|
|
||||||
}
|
|
||||||
orgs := resp.GetOrgs()
|
|
||||||
if len(orgs) == 0 {
|
|
||||||
return fmt.Errorf("no organization found with name %q", name)
|
|
||||||
}
|
|
||||||
reqBody.OrgID = orgs[0].GetId()
|
|
||||||
}
|
|
||||||
|
|
||||||
bucket, err := c.PostBuckets(ctx).PostBucketRequest(reqBody).Execute()
|
bucket, err := c.PostBuckets(ctx).PostBucketRequest(reqBody).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,8 +33,8 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "minimal",
|
name: "minimal",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
OrgID: "123",
|
OrgParams: clients.OrgParams{OrgID: "123"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().PostBuckets(gomock.Any()).Return(api.ApiPostBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().PostBuckets(gomock.Any()).Return(api.ApiPostBucketsRequest{ApiService: bucketsApi})
|
||||||
@ -59,7 +59,7 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "fully specified",
|
name: "fully specified",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
OrgID: "123",
|
OrgParams: clients.OrgParams{OrgID: "123"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
Description: "my cool bucket",
|
Description: "my cool bucket",
|
||||||
Retention: "24h",
|
Retention: "24h",
|
||||||
@ -92,7 +92,7 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "retention but not shard-group duration",
|
name: "retention but not shard-group duration",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
OrgID: "123",
|
OrgParams: clients.OrgParams{OrgID: "123"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
Retention: "24h",
|
Retention: "24h",
|
||||||
},
|
},
|
||||||
@ -120,7 +120,7 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "create bucket with explicit schema",
|
name: "create bucket with explicit schema",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
OrgID: "123",
|
OrgParams: clients.OrgParams{OrgID: "123"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
SchemaType: api.SCHEMATYPE_EXPLICIT,
|
SchemaType: api.SCHEMATYPE_EXPLICIT,
|
||||||
},
|
},
|
||||||
@ -148,7 +148,7 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "look up org by name",
|
name: "look up org by name",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
OrgName: "my-org",
|
OrgParams: clients.OrgParams{OrgName: "my-org"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
Description: "my cool bucket",
|
Description: "my cool bucket",
|
||||||
Retention: "24h",
|
Retention: "24h",
|
||||||
@ -242,8 +242,8 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no such org",
|
name: "no such org",
|
||||||
params: bucket.BucketsCreateParams{
|
params: bucket.BucketsCreateParams{
|
||||||
|
OrgParams: clients.OrgParams{OrgName: "fake-org"},
|
||||||
Name: "my-bucket",
|
Name: "my-bucket",
|
||||||
OrgName: "fake-org",
|
|
||||||
Description: "my cool bucket",
|
Description: "my cool bucket",
|
||||||
Retention: "24h",
|
Retention: "24h",
|
||||||
ShardGroupDuration: "1h",
|
ShardGroupDuration: "1h",
|
||||||
@ -252,7 +252,7 @@ func TestBucketsCreate(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
||||||
orgApi.EXPECT().GetOrgsExecute(gomock.Any()).Return(api.Organizations{}, nil)
|
orgApi.EXPECT().GetOrgsExecute(gomock.Any()).Return(api.Organizations{}, nil)
|
||||||
},
|
},
|
||||||
expectedInErr: "no organization found",
|
expectedInErr: "no organization with name \"fake-org\"",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,27 +9,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BucketsDeleteParams struct {
|
type BucketsDeleteParams struct {
|
||||||
ID string
|
clients.OrgBucketParams
|
||||||
Name string
|
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, params *BucketsDeleteParams) error {
|
func (c Client) Delete(ctx context.Context, params *BucketsDeleteParams) error {
|
||||||
if params.ID == "" && params.Name == "" {
|
if params.BucketID == "" && params.BucketName == "" {
|
||||||
return clients.ErrMustSpecifyBucket
|
return clients.ErrMustSpecifyBucket
|
||||||
}
|
}
|
||||||
|
|
||||||
var bucket api.Bucket
|
var bucket api.Bucket
|
||||||
var getReq api.ApiGetBucketsRequest
|
var getReq api.ApiGetBucketsRequest
|
||||||
if params.ID != "" {
|
if params.BucketID != "" {
|
||||||
getReq = c.GetBuckets(ctx).Id(params.ID)
|
getReq = c.GetBuckets(ctx).Id(params.BucketID)
|
||||||
} else {
|
} else {
|
||||||
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return ErrMustSpecifyOrgDeleteByName
|
return ErrMustSpecifyOrgDeleteByName
|
||||||
}
|
}
|
||||||
getReq = c.GetBuckets(ctx)
|
getReq = c.GetBuckets(ctx)
|
||||||
getReq = getReq.Name(params.Name)
|
getReq = getReq.Name(params.BucketName)
|
||||||
if params.OrgID != "" {
|
if params.OrgID != "" {
|
||||||
getReq = getReq.OrgID(params.OrgID)
|
getReq = getReq.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
@ -41,9 +38,9 @@ func (c Client) Delete(ctx context.Context, params *BucketsDeleteParams) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
displayId := params.ID
|
displayId := params.BucketID
|
||||||
if displayId == "" {
|
if displayId == "" {
|
||||||
displayId = params.Name
|
displayId = params.BucketName
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := getReq.Execute()
|
resp, err := getReq.Execute()
|
||||||
|
@ -33,7 +33,9 @@ func TestBucketsDelete(t *testing.T) {
|
|||||||
name: "by ID",
|
name: "by ID",
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
ID: "123",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
||||||
@ -67,8 +69,10 @@ func TestBucketsDelete(t *testing.T) {
|
|||||||
name: "by name and org ID",
|
name: "by name and org ID",
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
Name: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
OrgID: "456",
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
OrgParams: clients.OrgParams{OrgID: "456"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
||||||
@ -102,8 +106,10 @@ func TestBucketsDelete(t *testing.T) {
|
|||||||
name: "by name and org name",
|
name: "by name and org name",
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
Name: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
OrgName: "my-org",
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
OrgParams: clients.OrgParams{OrgName: "my-org"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
||||||
@ -137,7 +143,9 @@ func TestBucketsDelete(t *testing.T) {
|
|||||||
name: "by name in default org",
|
name: "by name in default org",
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
Name: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
||||||
@ -170,14 +178,18 @@ func TestBucketsDelete(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "by name without org",
|
name: "by name without org",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
Name: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedInErr: "must specify org ID or org name",
|
expectedInErr: "must specify org ID or org name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no such bucket",
|
name: "no such bucket",
|
||||||
params: bucket.BucketsDeleteParams{
|
params: bucket.BucketsDeleteParams{
|
||||||
ID: "123",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
bucketsApi.EXPECT().GetBuckets(gomock.Any()).Return(api.ApiGetBucketsRequest{ApiService: bucketsApi})
|
||||||
|
@ -9,10 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BucketsListParams struct {
|
type BucketsListParams struct {
|
||||||
OrgID string
|
clients.OrgBucketParams
|
||||||
OrgName string
|
|
||||||
Name string
|
|
||||||
ID string
|
|
||||||
Limit int
|
Limit int
|
||||||
Offset int
|
Offset int
|
||||||
PageSize int
|
PageSize int
|
||||||
@ -33,7 +30,7 @@ func (c Client) List(ctx context.Context, params *BucketsListParams) error {
|
|||||||
if params.OrgID == "" && params.OrgName == "" {
|
if params.OrgID == "" && params.OrgName == "" {
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
req = req.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
if params.Name != "" || params.ID != "" {
|
if params.BucketName != "" || params.BucketID != "" {
|
||||||
return c.findOneBucket(params, req)
|
return c.findOneBucket(params, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +108,11 @@ func (c Client) List(ctx context.Context, params *BucketsListParams) error {
|
|||||||
// Used to look up buckets by ID or name.
|
// Used to look up buckets by ID or name.
|
||||||
func (c Client) findOneBucket(params *BucketsListParams, req api.ApiGetBucketsRequest) error {
|
func (c Client) findOneBucket(params *BucketsListParams, req api.ApiGetBucketsRequest) error {
|
||||||
var description string
|
var description string
|
||||||
if params.ID != "" {
|
if params.BucketID != "" {
|
||||||
req = req.Id(params.ID)
|
req = req.Id(params.BucketID)
|
||||||
description = " by ID"
|
description = " by ID"
|
||||||
} else if params.Name != "" {
|
} else if params.BucketName != "" {
|
||||||
req = req.Name(params.Name)
|
req = req.Name(params.BucketName)
|
||||||
description = " by name"
|
description = " by name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@ func TestBucketsList(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "by ID",
|
name: "by ID",
|
||||||
params: bucket.BucketsListParams{
|
params: bucket.BucketsListParams{
|
||||||
ID: "123",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
@ -62,7 +64,9 @@ func TestBucketsList(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "by name",
|
name: "by name",
|
||||||
params: bucket.BucketsListParams{
|
params: bucket.BucketsListParams{
|
||||||
Name: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
@ -148,7 +152,9 @@ func TestBucketsList(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "override org by ID",
|
name: "override org by ID",
|
||||||
params: bucket.BucketsListParams{
|
params: bucket.BucketsListParams{
|
||||||
OrgID: "456",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
|
OrgParams: clients.OrgParams{OrgID: "456"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
@ -164,8 +170,10 @@ func TestBucketsList(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "override org by name",
|
name: "override org by name",
|
||||||
params: bucket.BucketsListParams{
|
params: bucket.BucketsListParams{
|
||||||
OrgName: "my-org",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
Limit: 2,
|
OrgParams: clients.OrgParams{OrgName: "my-org"},
|
||||||
|
},
|
||||||
|
Limit: 2,
|
||||||
},
|
},
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
@ -204,8 +212,10 @@ func TestBucketsList(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "list multiple bucket schema types",
|
name: "list multiple bucket schema types",
|
||||||
params: bucket.BucketsListParams{
|
params: bucket.BucketsListParams{
|
||||||
OrgName: "my-org",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
Limit: 3,
|
OrgParams: clients.OrgParams{OrgName: "my-org"},
|
||||||
|
},
|
||||||
|
Limit: 3,
|
||||||
},
|
},
|
||||||
configOrgName: "my-default-org",
|
configOrgName: "my-default-org",
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/duration"
|
"github.com/influxdata/influx-cli/v2/pkg/duration"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BucketsUpdateParams struct {
|
type BucketsUpdateParams struct {
|
||||||
ID string
|
clients.BucketParams
|
||||||
Name string
|
|
||||||
Description string
|
Description string
|
||||||
Retention string
|
Retention string
|
||||||
ShardGroupDuration string
|
ShardGroupDuration string
|
||||||
@ -19,8 +19,8 @@ type BucketsUpdateParams struct {
|
|||||||
|
|
||||||
func (c Client) Update(ctx context.Context, params *BucketsUpdateParams) error {
|
func (c Client) Update(ctx context.Context, params *BucketsUpdateParams) error {
|
||||||
reqBody := api.PatchBucketRequest{}
|
reqBody := api.PatchBucketRequest{}
|
||||||
if params.Name != "" {
|
if params.BucketName != "" {
|
||||||
reqBody.SetName(params.Name)
|
reqBody.SetName(params.BucketName)
|
||||||
}
|
}
|
||||||
if params.Description != "" {
|
if params.Description != "" {
|
||||||
reqBody.SetDescription(params.Description)
|
reqBody.SetDescription(params.Description)
|
||||||
@ -44,9 +44,9 @@ func (c Client) Update(ctx context.Context, params *BucketsUpdateParams) error {
|
|||||||
reqBody.SetRetentionRules([]api.PatchRetentionRule{*patchRule})
|
reqBody.SetRetentionRules([]api.PatchRetentionRule{*patchRule})
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket, err := c.PatchBucketsID(ctx, params.ID).PatchBucketRequest(reqBody).Execute()
|
bucket, err := c.PatchBucketsID(ctx, params.BucketID).PatchBucketRequest(reqBody).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update bucket %q: %w", params.ID, err)
|
return fmt.Errorf("failed to update bucket %q: %w", params.BucketID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.printBuckets(bucketPrintOptions{bucket: &bucket})
|
return c.printBuckets(bucketPrintOptions{bucket: &bucket})
|
||||||
|
@ -29,8 +29,10 @@ func TestBucketsUpdate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "name",
|
name: "name",
|
||||||
params: bucket.BucketsUpdateParams{
|
params: bucket.BucketsUpdateParams{
|
||||||
ID: "123",
|
BucketParams: clients.BucketParams{
|
||||||
Name: "cold-storage",
|
BucketID: "123",
|
||||||
|
BucketName: "cold-storage",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
||||||
@ -53,8 +55,8 @@ func TestBucketsUpdate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "description",
|
name: "description",
|
||||||
params: bucket.BucketsUpdateParams{
|
params: bucket.BucketsUpdateParams{
|
||||||
ID: "123",
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
Description: "a very useful description",
|
Description: "a very useful description",
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
||||||
@ -78,8 +80,8 @@ func TestBucketsUpdate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "retention",
|
name: "retention",
|
||||||
params: bucket.BucketsUpdateParams{
|
params: bucket.BucketsUpdateParams{
|
||||||
ID: "123",
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
Retention: "3w",
|
Retention: "3w",
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
bucketsApi.EXPECT().PatchBucketsID(gomock.Any(), gomock.Eq("123")).
|
||||||
@ -107,7 +109,7 @@ func TestBucketsUpdate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "shard-group duration",
|
name: "shard-group duration",
|
||||||
params: bucket.BucketsUpdateParams{
|
params: bucket.BucketsUpdateParams{
|
||||||
ID: "123",
|
BucketParams: clients.BucketParams{BucketID: "123"},
|
||||||
ShardGroupDuration: "10h30m",
|
ShardGroupDuration: "10h30m",
|
||||||
},
|
},
|
||||||
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
registerBucketExpectations: func(t *testing.T, bucketsApi *mock.MockBucketsApi) {
|
||||||
|
@ -39,26 +39,27 @@ func (c Client) resolveMeasurement(ctx context.Context, ids orgBucketID, name st
|
|||||||
return res.MeasurementSchemas[0].Id, nil
|
return res.MeasurementSchemas[0].Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo move to params.go
|
||||||
func (c Client) resolveOrgBucketIds(ctx context.Context, params clients.OrgBucketParams) (*orgBucketID, error) {
|
func (c Client) resolveOrgBucketIds(ctx context.Context, params clients.OrgBucketParams) (*orgBucketID, error) {
|
||||||
if params.BucketName == "" && !params.BucketID.Valid() {
|
if params.BucketName == "" && params.BucketID == "" {
|
||||||
return nil, errors.New("bucket missing: specify bucket ID or bucket name")
|
return nil, errors.New("bucket missing: specify bucket ID or bucket name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return nil, errors.New("org missing: specify org ID or org name")
|
return nil, errors.New("org missing: specify org ID or org name")
|
||||||
}
|
}
|
||||||
|
|
||||||
req := c.GetBuckets(ctx)
|
req := c.GetBuckets(ctx)
|
||||||
var nameID string
|
var nameID string
|
||||||
if params.BucketID.Valid() {
|
if params.BucketID != "" {
|
||||||
req = req.Id(params.BucketID.String())
|
req = req.Id(params.BucketID)
|
||||||
nameID = params.BucketID.String()
|
nameID = params.BucketID
|
||||||
} else {
|
} else {
|
||||||
req = req.Name(params.BucketName)
|
req = req.Name(params.BucketName)
|
||||||
nameID = params.BucketName
|
nameID = params.BucketName
|
||||||
}
|
}
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
} else if params.OrgName != "" {
|
} else if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -26,9 +25,9 @@ func TestClient_Create(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
orgID = influxid.MustIDFromString("deadf00dbaadf00d")
|
orgID = "deadf00dbaadf00d"
|
||||||
bucketID = influxid.MustIDFromString("f00ddeadf00dbaad")
|
bucketID = "f00ddeadf00dbaad"
|
||||||
measurementID = influxid.MustIDFromString("1010f00ddeedfeed")
|
measurementID = "1010f00ddeedfeed"
|
||||||
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,9 +44,9 @@ func TestClient_Create(t *testing.T) {
|
|||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
OrgName string
|
OrgName string
|
||||||
OrgID influxid.ID
|
OrgID string
|
||||||
BucketName string
|
BucketName string
|
||||||
BucketID influxid.ID
|
BucketID string
|
||||||
Name string
|
Name string
|
||||||
ColumnsFile string
|
ColumnsFile string
|
||||||
ExtendedOutput bool
|
ExtendedOutput bool
|
||||||
@ -80,8 +79,8 @@ func TestClient_Create(t *testing.T) {
|
|||||||
var buckets []api.Bucket
|
var buckets []api.Bucket
|
||||||
if len(n) == 1 {
|
if len(n) == 1 {
|
||||||
bucket := api.NewBucket(n[0], nil)
|
bucket := api.NewBucket(n[0], nil)
|
||||||
bucket.SetOrgID(orgID.String())
|
bucket.SetOrgID(orgID)
|
||||||
bucket.SetId(bucketID.String())
|
bucket.SetId(bucketID)
|
||||||
bucket.SetName(n[0])
|
bucket.SetName(n[0])
|
||||||
buckets = []api.Bucket{*bucket}
|
buckets = []api.Bucket{*bucket}
|
||||||
}
|
}
|
||||||
@ -95,9 +94,9 @@ func TestClient_Create(t *testing.T) {
|
|||||||
a.buckets.EXPECT().
|
a.buckets.EXPECT().
|
||||||
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
||||||
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
||||||
(in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String())
|
(in.GetOrgID() != nil && *in.GetOrgID() == a.params.OrgID)
|
||||||
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
||||||
(in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String())
|
(in.GetId() != nil && *in.GetId() == a.params.BucketID)
|
||||||
return matchOrg && matchBucket
|
return matchOrg && matchBucket
|
||||||
})).
|
})).
|
||||||
Return(api.Buckets{Buckets: &buckets}, nil)
|
Return(api.Buckets{Buckets: &buckets}, nil)
|
||||||
@ -122,19 +121,19 @@ func TestClient_Create(t *testing.T) {
|
|||||||
return func(t *testing.T, a *setupArgs) {
|
return func(t *testing.T, a *setupArgs) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
req := api.ApiCreateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID.String())
|
req := api.ApiCreateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
CreateMeasurementSchema(gomock.Any(), bucketID.String()).
|
CreateMeasurementSchema(gomock.Any(), bucketID).
|
||||||
Return(req)
|
Return(req)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
CreateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiCreateMeasurementSchemaRequest) bool {
|
CreateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiCreateMeasurementSchemaRequest) bool {
|
||||||
orgIDPtr := orgID.String()
|
orgIDPtr := orgID
|
||||||
return assert.Equal(t, in.GetOrgID(), &orgIDPtr) && assert.Equal(t, in.GetBucketID(), bucketID.String())
|
return assert.Equal(t, in.GetOrgID(), &orgIDPtr) && assert.Equal(t, in.GetBucketID(), bucketID)
|
||||||
})).
|
})).
|
||||||
Return(api.MeasurementSchema{
|
Return(api.MeasurementSchema{
|
||||||
Id: measurementID.String(),
|
Id: measurementID,
|
||||||
Name: a.params.Name,
|
Name: a.params.Name,
|
||||||
Columns: a.cols,
|
Columns: a.cols,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -26,9 +25,9 @@ func TestClient_List(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
orgID = influxid.MustIDFromString("deadf00dbaadf00d")
|
orgID = "deadf00dbaadf00d"
|
||||||
bucketID = influxid.MustIDFromString("f00ddeadf00dbaad")
|
bucketID = "f00ddeadf00dbaad"
|
||||||
measurementID = influxid.MustIDFromString("1010f00ddeedfeed")
|
measurementID = "1010f00ddeedfeed"
|
||||||
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
||||||
updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC)
|
updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC)
|
||||||
)
|
)
|
||||||
@ -46,9 +45,9 @@ func TestClient_List(t *testing.T) {
|
|||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
OrgName string
|
OrgName string
|
||||||
OrgID influxid.ID
|
OrgID string
|
||||||
BucketName string
|
BucketName string
|
||||||
BucketID influxid.ID
|
BucketID string
|
||||||
Name string
|
Name string
|
||||||
ExtendedOutput bool
|
ExtendedOutput bool
|
||||||
}
|
}
|
||||||
@ -74,8 +73,8 @@ func TestClient_List(t *testing.T) {
|
|||||||
var buckets []api.Bucket
|
var buckets []api.Bucket
|
||||||
if len(n) == 1 {
|
if len(n) == 1 {
|
||||||
bucket := api.NewBucket(n[0], nil)
|
bucket := api.NewBucket(n[0], nil)
|
||||||
bucket.SetOrgID(orgID.String())
|
bucket.SetOrgID(orgID)
|
||||||
bucket.SetId(bucketID.String())
|
bucket.SetId(bucketID)
|
||||||
bucket.SetName(n[0])
|
bucket.SetName(n[0])
|
||||||
buckets = []api.Bucket{*bucket}
|
buckets = []api.Bucket{*bucket}
|
||||||
}
|
}
|
||||||
@ -89,9 +88,9 @@ func TestClient_List(t *testing.T) {
|
|||||||
a.buckets.EXPECT().
|
a.buckets.EXPECT().
|
||||||
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
||||||
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
||||||
(in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String())
|
(in.GetOrgID() != nil && *in.GetOrgID() == a.params.OrgID)
|
||||||
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
||||||
(in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String())
|
(in.GetId() != nil && *in.GetId() == a.params.BucketID)
|
||||||
return matchOrg && matchBucket
|
return matchOrg && matchBucket
|
||||||
})).
|
})).
|
||||||
Return(api.Buckets{Buckets: &buckets}, nil)
|
Return(api.Buckets{Buckets: &buckets}, nil)
|
||||||
@ -116,22 +115,22 @@ func TestClient_List(t *testing.T) {
|
|||||||
return func(t *testing.T, a *setupArgs) {
|
return func(t *testing.T, a *setupArgs) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID.String())
|
req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
GetMeasurementSchemas(gomock.Any(), bucketID.String()).
|
GetMeasurementSchemas(gomock.Any(), bucketID).
|
||||||
Return(req)
|
Return(req)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool {
|
GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool {
|
||||||
return (in.GetOrgID() != nil && *in.GetOrgID() == orgID.String()) &&
|
return (in.GetOrgID() != nil && *in.GetOrgID() == orgID) &&
|
||||||
in.GetBucketID() == bucketID.String() &&
|
in.GetBucketID() == bucketID &&
|
||||||
(in.GetName() != nil && *in.GetName() == a.params.Name)
|
(in.GetName() != nil && *in.GetName() == a.params.Name)
|
||||||
})).
|
})).
|
||||||
Return(api.MeasurementSchemaList{
|
Return(api.MeasurementSchemaList{
|
||||||
MeasurementSchemas: []api.MeasurementSchema{
|
MeasurementSchemas: []api.MeasurementSchema{
|
||||||
{
|
{
|
||||||
Id: measurementID.String(),
|
Id: measurementID,
|
||||||
Name: a.params.Name,
|
Name: a.params.Name,
|
||||||
Columns: a.cols,
|
Columns: a.cols,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
@ -177,7 +176,7 @@ func TestClient_List(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "bucket not found by id",
|
name: "bucket not found by id",
|
||||||
opts: opts(
|
opts: opts(
|
||||||
withArgs(args{OrgName: "my-org", BucketID: influxid.MustIDFromString("baadf00d7777deed")}),
|
withArgs(args{OrgName: "my-org", BucketID: "baadf00d7777deed"}),
|
||||||
expGetBuckets(),
|
expGetBuckets(),
|
||||||
),
|
),
|
||||||
expErr: `bucket "baadf00d7777deed" not found`,
|
expErr: `bucket "baadf00d7777deed" not found`,
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -26,9 +25,9 @@ func TestClient_Update(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
orgID = influxid.MustIDFromString("deadf00dbaadf00d")
|
orgID = "deadf00dbaadf00d"
|
||||||
bucketID = influxid.MustIDFromString("f00ddeadf00dbaad")
|
bucketID = "f00ddeadf00dbaad"
|
||||||
measurementID = influxid.MustIDFromString("1010f00ddeedfeed")
|
measurementID = "1010f00ddeedfeed"
|
||||||
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC)
|
||||||
updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC)
|
updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC)
|
||||||
)
|
)
|
||||||
@ -46,9 +45,9 @@ func TestClient_Update(t *testing.T) {
|
|||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
OrgName string
|
OrgName string
|
||||||
OrgID influxid.ID
|
OrgID string
|
||||||
BucketName string
|
BucketName string
|
||||||
BucketID influxid.ID
|
BucketID string
|
||||||
Name string
|
Name string
|
||||||
ColumnsFile string
|
ColumnsFile string
|
||||||
ExtendedOutput bool
|
ExtendedOutput bool
|
||||||
@ -81,8 +80,8 @@ func TestClient_Update(t *testing.T) {
|
|||||||
var buckets []api.Bucket
|
var buckets []api.Bucket
|
||||||
if len(n) == 1 {
|
if len(n) == 1 {
|
||||||
bucket := api.NewBucket(n[0], nil)
|
bucket := api.NewBucket(n[0], nil)
|
||||||
bucket.SetOrgID(orgID.String())
|
bucket.SetOrgID(orgID)
|
||||||
bucket.SetId(bucketID.String())
|
bucket.SetId(bucketID)
|
||||||
bucket.SetName(n[0])
|
bucket.SetName(n[0])
|
||||||
buckets = []api.Bucket{*bucket}
|
buckets = []api.Bucket{*bucket}
|
||||||
}
|
}
|
||||||
@ -96,9 +95,9 @@ func TestClient_Update(t *testing.T) {
|
|||||||
a.buckets.EXPECT().
|
a.buckets.EXPECT().
|
||||||
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool {
|
||||||
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) ||
|
||||||
(in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String())
|
(in.GetOrgID() != nil && *in.GetOrgID() == a.params.OrgID)
|
||||||
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) ||
|
||||||
(in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String())
|
(in.GetId() != nil && *in.GetId() == a.params.BucketID)
|
||||||
return matchOrg && matchBucket
|
return matchOrg && matchBucket
|
||||||
})).
|
})).
|
||||||
Return(api.Buckets{Buckets: &buckets}, nil)
|
Return(api.Buckets{Buckets: &buckets}, nil)
|
||||||
@ -123,22 +122,22 @@ func TestClient_Update(t *testing.T) {
|
|||||||
return func(t *testing.T, a *setupArgs) {
|
return func(t *testing.T, a *setupArgs) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID.String())
|
req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
GetMeasurementSchemas(gomock.Any(), bucketID.String()).
|
GetMeasurementSchemas(gomock.Any(), bucketID).
|
||||||
Return(req)
|
Return(req)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool {
|
GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool {
|
||||||
return (in.GetOrgID() != nil && *in.GetOrgID() == orgID.String()) &&
|
return (in.GetOrgID() != nil && *in.GetOrgID() == orgID) &&
|
||||||
in.GetBucketID() == bucketID.String() &&
|
in.GetBucketID() == bucketID &&
|
||||||
(in.GetName() != nil && *in.GetName() == a.params.Name)
|
(in.GetName() != nil && *in.GetName() == a.params.Name)
|
||||||
})).
|
})).
|
||||||
Return(api.MeasurementSchemaList{
|
Return(api.MeasurementSchemaList{
|
||||||
MeasurementSchemas: []api.MeasurementSchema{
|
MeasurementSchemas: []api.MeasurementSchema{
|
||||||
{
|
{
|
||||||
Id: measurementID.String(),
|
Id: measurementID,
|
||||||
Name: a.params.Name,
|
Name: a.params.Name,
|
||||||
Columns: a.cols,
|
Columns: a.cols,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
@ -153,22 +152,22 @@ func TestClient_Update(t *testing.T) {
|
|||||||
return func(t *testing.T, a *setupArgs) {
|
return func(t *testing.T, a *setupArgs) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
req := api.ApiUpdateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID.String()).MeasurementID(measurementID.String())
|
req := api.ApiUpdateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID).MeasurementID(measurementID)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
UpdateMeasurementSchema(gomock.Any(), bucketID.String(), measurementID.String()).
|
UpdateMeasurementSchema(gomock.Any(), bucketID, measurementID).
|
||||||
Return(req)
|
Return(req)
|
||||||
|
|
||||||
a.schemas.EXPECT().
|
a.schemas.EXPECT().
|
||||||
UpdateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiUpdateMeasurementSchemaRequest) bool {
|
UpdateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiUpdateMeasurementSchemaRequest) bool {
|
||||||
orgIDPtr := orgID.String()
|
orgIDPtr := orgID
|
||||||
return assert.Equal(t, in.GetOrgID(), &orgIDPtr) &&
|
return assert.Equal(t, in.GetOrgID(), &orgIDPtr) &&
|
||||||
assert.Equal(t, in.GetBucketID(), bucketID.String()) &&
|
assert.Equal(t, in.GetBucketID(), bucketID) &&
|
||||||
assert.Equal(t, in.GetMeasurementID(), measurementID.String()) &&
|
assert.Equal(t, in.GetMeasurementID(), measurementID) &&
|
||||||
assert.Equal(t, in.GetMeasurementSchemaUpdateRequest().Columns, a.cols)
|
assert.Equal(t, in.GetMeasurementSchemaUpdateRequest().Columns, a.cols)
|
||||||
})).
|
})).
|
||||||
Return(api.MeasurementSchema{
|
Return(api.MeasurementSchema{
|
||||||
Id: measurementID.String(),
|
Id: measurementID,
|
||||||
Name: a.params.Name,
|
Name: a.params.Name,
|
||||||
Columns: a.cols,
|
Columns: a.cols,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package clients
|
package clients
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
|
||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/stdio"
|
"github.com/influxdata/influx-cli/v2/pkg/stdio"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/tabwriter"
|
"github.com/influxdata/influx-cli/v2/pkg/tabwriter"
|
||||||
)
|
)
|
||||||
@ -42,32 +38,3 @@ func (c *CLI) PrintTable(headers []string, rows ...map[string]interface{}) error
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CLI) GetOrgId(ctx context.Context, paramOrgId, paramOrgName string, orgApi api.OrganizationsApi) (string, error) {
|
|
||||||
if paramOrgId != "" {
|
|
||||||
return paramOrgId, nil
|
|
||||||
}
|
|
||||||
orgName := paramOrgName
|
|
||||||
if orgName == "" {
|
|
||||||
orgName = c.ActiveConfig.Org
|
|
||||||
}
|
|
||||||
if orgName == "" {
|
|
||||||
return "", ErrMustSpecifyOrg
|
|
||||||
}
|
|
||||||
res, err := orgApi.GetOrgs(ctx).Org(orgName).Execute()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to lookup org with name %q: %w", orgName, err)
|
|
||||||
}
|
|
||||||
if len(res.GetOrgs()) == 0 {
|
|
||||||
return "", fmt.Errorf("no organization with name %q", orgName)
|
|
||||||
}
|
|
||||||
return res.GetOrgs()[0].GetId(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CLI) GetOrgIdI(ctx context.Context, paramOrgId influxid.ID, paramOrgName string, orgApi api.OrganizationsApi) (string, error) {
|
|
||||||
orgId := ""
|
|
||||||
if paramOrgId.Valid() {
|
|
||||||
orgId = paramOrgId.String()
|
|
||||||
}
|
|
||||||
return c.GetOrgId(ctx, orgId, paramOrgName, orgApi)
|
|
||||||
}
|
|
||||||
|
@ -19,20 +19,20 @@ type Params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *Params) error {
|
func (c Client) List(ctx context.Context, params *Params) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" && len(params.Ids) == 0 {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" && len(params.Ids) == 0 {
|
||||||
return fmt.Errorf("at least one of org, org-id, or id must be provided")
|
return fmt.Errorf("at least one of org, org-id, or id must be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = 100
|
const limit = 100
|
||||||
req := c.GetDashboards(ctx)
|
req := c.GetDashboards(ctx)
|
||||||
req = req.Limit(limit)
|
req = req.Limit(limit)
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" {
|
if params.OrgID == "" && params.OrgName == "" {
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
req = req.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
dashboards, err := req.Id(params.Ids).Execute()
|
dashboards, err := req.Id(params.Ids).Execute()
|
||||||
|
@ -2,7 +2,6 @@ package delete
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -22,14 +21,12 @@ type Params struct {
|
|||||||
Stop string
|
Stop string
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrMustSpecifyBucket = errors.New("must specify bucket ID or bucket name")
|
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, params *Params) error {
|
func (c Client) Delete(ctx context.Context, params *Params) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return clients.ErrMustSpecifyOrg
|
return clients.ErrMustSpecifyOrg
|
||||||
}
|
}
|
||||||
if !params.BucketID.Valid() && params.BucketName == "" {
|
if params.BucketID == "" && params.BucketName == "" {
|
||||||
return ErrMustSpecifyBucket
|
return clients.ErrMustSpecifyBucket
|
||||||
}
|
}
|
||||||
start, err := time.Parse(time.RFC3339Nano, params.Start)
|
start, err := time.Parse(time.RFC3339Nano, params.Start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -46,15 +43,15 @@ func (c Client) Delete(ctx context.Context, params *Params) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := c.PostDelete(ctx).DeletePredicateRequest(*reqBody)
|
req := c.PostDelete(ctx).DeletePredicateRequest(*reqBody)
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
} else if params.OrgName != "" {
|
} else if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
} else {
|
} else {
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
req = req.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
if params.BucketID.Valid() {
|
if params.BucketID != "" {
|
||||||
req = req.BucketID(params.BucketID.String())
|
req = req.BucketID(params.BucketID)
|
||||||
} else {
|
} else {
|
||||||
req = req.Bucket(params.BucketName)
|
req = req.Bucket(params.BucketName)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/delete"
|
"github.com/influxdata/influx-cli/v2/clients/delete"
|
||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -20,8 +19,8 @@ import (
|
|||||||
func TestClient_Delete(t *testing.T) {
|
func TestClient_Delete(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
id1, _ := influxid.IDFromString("1111111111111111")
|
id1 := "1111111111111111"
|
||||||
id2, _ := influxid.IDFromString("2222222222222222")
|
id2 := "2222222222222222"
|
||||||
|
|
||||||
start, _ := time.Parse(time.RFC3339Nano, "2020-01-01T00:00:00Z")
|
start, _ := time.Parse(time.RFC3339Nano, "2020-01-01T00:00:00Z")
|
||||||
stop, _ := time.Parse(time.RFC3339Nano, "2021-01-01T00:00:00Z")
|
stop, _ := time.Parse(time.RFC3339Nano, "2021-01-01T00:00:00Z")
|
||||||
@ -53,9 +52,9 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
delApi.EXPECT().PostDeleteExecute(tmock.MatchedBy(func(in api.ApiPostDeleteRequest) bool {
|
delApi.EXPECT().PostDeleteExecute(tmock.MatchedBy(func(in api.ApiPostDeleteRequest) bool {
|
||||||
body := in.GetDeletePredicateRequest()
|
body := in.GetDeletePredicateRequest()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), *in.GetOrgID()) &&
|
assert.Equal(t, id1, *in.GetOrgID()) &&
|
||||||
assert.Nil(t, in.GetOrg()) &&
|
assert.Nil(t, in.GetOrg()) &&
|
||||||
assert.Equal(t, id2.String(), *in.GetBucketID()) &&
|
assert.Equal(t, id2, *in.GetBucketID()) &&
|
||||||
assert.Nil(t, in.GetBucket()) &&
|
assert.Nil(t, in.GetBucket()) &&
|
||||||
assert.Equal(t, start, body.GetStart()) &&
|
assert.Equal(t, start, body.GetStart()) &&
|
||||||
assert.Equal(t, stop, body.GetStop()) &&
|
assert.Equal(t, stop, body.GetStop()) &&
|
||||||
@ -83,7 +82,7 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
delApi.EXPECT().PostDeleteExecute(tmock.MatchedBy(func(in api.ApiPostDeleteRequest) bool {
|
delApi.EXPECT().PostDeleteExecute(tmock.MatchedBy(func(in api.ApiPostDeleteRequest) bool {
|
||||||
body := in.GetDeletePredicateRequest()
|
body := in.GetDeletePredicateRequest()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), *in.GetOrgID()) &&
|
assert.Equal(t, id1, *in.GetOrgID()) &&
|
||||||
assert.Nil(t, in.GetOrg()) &&
|
assert.Nil(t, in.GetOrg()) &&
|
||||||
assert.Equal(t, "my-bucket", *in.GetBucket()) &&
|
assert.Equal(t, "my-bucket", *in.GetBucket()) &&
|
||||||
assert.Nil(t, in.GetBucketID()) &&
|
assert.Nil(t, in.GetBucketID()) &&
|
||||||
@ -116,7 +115,7 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, "my-org", *in.GetOrg()) &&
|
assert.Equal(t, "my-org", *in.GetOrg()) &&
|
||||||
assert.Nil(t, in.GetOrgID()) &&
|
assert.Nil(t, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), *in.GetBucketID()) &&
|
assert.Equal(t, id2, *in.GetBucketID()) &&
|
||||||
assert.Nil(t, in.GetBucket()) &&
|
assert.Nil(t, in.GetBucket()) &&
|
||||||
assert.Equal(t, start, body.GetStart()) &&
|
assert.Equal(t, start, body.GetStart()) &&
|
||||||
assert.Equal(t, stop, body.GetStop()) &&
|
assert.Equal(t, stop, body.GetStop()) &&
|
||||||
@ -160,7 +159,7 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no bucket",
|
name: "no bucket",
|
||||||
defaultOrgName: "my-default-org",
|
defaultOrgName: "my-default-org",
|
||||||
expectedErr: delete.ErrMustSpecifyBucket.Error(),
|
expectedErr: clients.ErrMustSpecifyBucket.Error(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bad start",
|
name: "bad start",
|
||||||
|
@ -62,32 +62,16 @@ func (c Client) Export(ctx context.Context, params *Params) error {
|
|||||||
type AllParams struct {
|
type AllParams struct {
|
||||||
template.OutParams
|
template.OutParams
|
||||||
|
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
LabelFilters []string
|
LabelFilters []string
|
||||||
KindFilters []string
|
KindFilters []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) ExportAll(ctx context.Context, params *AllParams) error {
|
func (c Client) ExportAll(ctx context.Context, params *AllParams) error {
|
||||||
if params.OrgId == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
|
||||||
orgId := params.OrgId
|
|
||||||
if orgId == "" {
|
|
||||||
orgName := params.OrgName
|
|
||||||
if orgName == "" {
|
|
||||||
orgName = c.ActiveConfig.Org
|
|
||||||
}
|
|
||||||
res, err := c.GetOrgs(ctx).Org(orgName).Execute()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to look up ID for org %q: %w", orgName, err)
|
|
||||||
}
|
|
||||||
if len(res.GetOrgs()) == 0 {
|
|
||||||
return fmt.Errorf("no org found with name %q", orgName)
|
|
||||||
}
|
|
||||||
orgId = res.GetOrgs()[0].GetId()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
orgExport := api.TemplateExportOrgIDs{OrgID: &orgId}
|
orgExport := api.TemplateExportOrgIDs{OrgID: &orgId}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateParams struct {
|
type CreateParams struct {
|
||||||
@ -25,30 +25,29 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
return c.printOrgs(printOrgOpts{org: &res})
|
return c.printOrgs(printOrgOpts{org: &res})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, id influxid.ID) error {
|
func (c Client) Delete(ctx context.Context, id string) error {
|
||||||
org, err := c.GetOrgsID(ctx, id.String()).Execute()
|
org, err := c.GetOrgsID(ctx, id).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("org %q not found: %w", id, err)
|
return fmt.Errorf("org %q not found: %w", id, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
if err := c.DeleteOrgsID(ctx, id.String()).Execute(); err != nil {
|
if err := c.DeleteOrgsID(ctx, id).Execute(); err != nil {
|
||||||
return fmt.Errorf("failed to delete org %q: %w", id, err)
|
return fmt.Errorf("failed to delete org %q: %w", id, err)
|
||||||
}
|
}
|
||||||
return c.printOrgs(printOrgOpts{org: &org, deleted: true})
|
return c.printOrgs(printOrgOpts{org: &org, deleted: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListParams struct {
|
type ListParams struct {
|
||||||
Name string
|
clients.OrgParams
|
||||||
ID influxid.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
req := c.GetOrgs(ctx)
|
req := c.GetOrgs(ctx)
|
||||||
if params.Name != "" {
|
if params.OrgName != "" {
|
||||||
req = req.Org(params.Name)
|
req = req.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if params.ID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.ID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
orgs, err := req.Execute()
|
orgs, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -62,23 +61,22 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpdateParams struct {
|
type UpdateParams struct {
|
||||||
ID influxid.ID
|
clients.OrgParams
|
||||||
Name string
|
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
||||||
body := api.PatchOrganizationRequest{}
|
body := api.PatchOrganizationRequest{}
|
||||||
if params.Name != "" {
|
if params.OrgName != "" {
|
||||||
body.Name = ¶ms.Name
|
body.Name = ¶ms.OrgName
|
||||||
}
|
}
|
||||||
if params.Description != "" {
|
if params.Description != "" {
|
||||||
body.Description = ¶ms.Description
|
body.Description = ¶ms.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.PatchOrgsID(ctx, params.ID.String()).PatchOrganizationRequest(body).Execute()
|
res, err := c.PatchOrgsID(ctx, params.OrgID).PatchOrganizationRequest(body).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update org %q: %w", params.ID, err)
|
return fmt.Errorf("failed to update org %q: %w", params.OrgID, err)
|
||||||
}
|
}
|
||||||
return c.printOrgs(printOrgOpts{org: &res})
|
return c.printOrgs(printOrgOpts{org: &res})
|
||||||
}
|
}
|
||||||
|
@ -6,32 +6,24 @@ import (
|
|||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
"github.com/influxdata/influx-cli/v2/clients"
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddMemberParams struct {
|
type AddMemberParams struct {
|
||||||
MemberId influxid.ID
|
clients.OrgParams
|
||||||
OrgName string
|
MemberId string
|
||||||
OrgID influxid.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) AddMember(ctx context.Context, params *AddMemberParams) (err error) {
|
func (c Client) AddMember(ctx context.Context, params *AddMemberParams) (err error) {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
|
||||||
orgID := params.OrgID.String()
|
|
||||||
if !params.OrgID.Valid() {
|
|
||||||
if orgID, err = c.getOrgId(ctx, params.OrgName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
member, err := c.PostOrgsIDMembers(ctx, orgID).
|
member, err := c.PostOrgsIDMembers(ctx, orgID).
|
||||||
AddResourceMemberRequestBody(*api.NewAddResourceMemberRequestBody(params.MemberId.String())).
|
AddResourceMemberRequestBody(*api.NewAddResourceMemberRequestBody(params.MemberId)).
|
||||||
Execute()
|
Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to add user %q to org %q: %w", params.MemberId.String(), orgID, err)
|
return fmt.Errorf("failed to add user %q to org %q: %w", params.MemberId, orgID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been added as a member of org %q\n", *member.Id, orgID)))
|
_, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been added as a member of org %q\n", *member.Id, orgID)))
|
||||||
@ -39,22 +31,15 @@ func (c Client) AddMember(ctx context.Context, params *AddMemberParams) (err err
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListMemberParams struct {
|
type ListMemberParams struct {
|
||||||
OrgName string
|
clients.OrgParams
|
||||||
OrgID influxid.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxConcurrentGetUserRequests = 10
|
const maxConcurrentGetUserRequests = 10
|
||||||
|
|
||||||
func (c Client) ListMembers(ctx context.Context, params *ListMemberParams) (err error) {
|
func (c Client) ListMembers(ctx context.Context, params *ListMemberParams) (err error) {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
|
||||||
orgID := params.OrgID.String()
|
|
||||||
if !params.OrgID.Valid() {
|
|
||||||
if orgID, err = c.getOrgId(ctx, params.OrgName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
members, err := c.GetOrgsIDMembers(ctx, orgID).Execute()
|
members, err := c.GetOrgsIDMembers(ctx, orgID).Execute()
|
||||||
@ -119,44 +104,20 @@ func (c Client) ListMembers(ctx context.Context, params *ListMemberParams) (err
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RemoveMemberParams struct {
|
type RemoveMemberParams struct {
|
||||||
MemberId influxid.ID
|
clients.OrgParams
|
||||||
OrgName string
|
MemberId string
|
||||||
OrgID influxid.ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) RemoveMember(ctx context.Context, params *RemoveMemberParams) (err error) {
|
func (c Client) RemoveMember(ctx context.Context, params *RemoveMemberParams) (err error) {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID := params.OrgID.String()
|
if err = c.DeleteOrgsIDMembersID(ctx, params.MemberId, orgID).Execute(); err != nil {
|
||||||
if !params.OrgID.Valid() {
|
|
||||||
if orgID, err = c.getOrgId(ctx, params.OrgName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = c.DeleteOrgsIDMembersID(ctx, params.MemberId.String(), orgID).Execute(); err != nil {
|
|
||||||
return fmt.Errorf("failed to remove member %q from org %q", params.MemberId, orgID)
|
return fmt.Errorf("failed to remove member %q from org %q", params.MemberId, orgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been removed from org %q\n", params.MemberId, orgID)))
|
_, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been removed from org %q\n", params.MemberId, orgID)))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrgId(ctx context.Context, orgName string) (string, error) {
|
|
||||||
req := c.GetOrgs(ctx)
|
|
||||||
if orgName != "" {
|
|
||||||
req = req.Org(orgName)
|
|
||||||
} else {
|
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
|
||||||
}
|
|
||||||
orgs, err := req.Execute()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to find org %q: %w", orgName, err)
|
|
||||||
}
|
|
||||||
if orgs.Orgs == nil || len(*orgs.Orgs) == 0 {
|
|
||||||
return "", fmt.Errorf("no org found with name %q", orgName)
|
|
||||||
}
|
|
||||||
return *(*orgs.Orgs)[0].Id, nil
|
|
||||||
}
|
|
||||||
|
@ -15,14 +15,13 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var id1, _ = influxid.IDFromString("1111111111111111")
|
var id1 = "1111111111111111"
|
||||||
var id2, _ = influxid.IDFromString("2222222222222222")
|
var id2 = "2222222222222222"
|
||||||
|
|
||||||
func TestClient_AddMember(t *testing.T) {
|
func TestClient_AddMember(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@ -38,27 +37,27 @@ func TestClient_AddMember(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "org by ID",
|
name: "org by ID",
|
||||||
params: org.AddMemberParams{
|
params: org.AddMemberParams{
|
||||||
OrgID: id1,
|
OrgParams: clients.OrgParams{OrgID: id1},
|
||||||
MemberId: id2,
|
MemberId: id2,
|
||||||
},
|
},
|
||||||
defaultOrgName: "my-org",
|
defaultOrgName: "my-org",
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
return assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.NotNil(t, body) &&
|
assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "org by name",
|
name: "org by name",
|
||||||
params: org.AddMemberParams{
|
params: org.AddMemberParams{
|
||||||
OrgName: "org",
|
OrgParams: clients.OrgParams{OrgName: "org"},
|
||||||
MemberId: id2,
|
MemberId: id2,
|
||||||
},
|
},
|
||||||
defaultOrgName: "my-org",
|
defaultOrgName: "my-org",
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
@ -66,17 +65,17 @@ func TestClient_AddMember(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "org", *in.GetOrg())
|
return assert.Equal(t, "org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
return assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.NotNil(t, body) &&
|
assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
||||||
},
|
},
|
||||||
@ -91,17 +90,17 @@ func TestClient_AddMember(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "my-org", *in.GetOrg())
|
return assert.Equal(t, "my-org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
return assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.NotNil(t, body) &&
|
assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been added as a member of org \"1111111111111111\"",
|
||||||
},
|
},
|
||||||
@ -176,18 +175,18 @@ func TestClient_ListMembers(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "my-org", *in.GetOrg())
|
return assert.Equal(t, "my-org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String())
|
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1)
|
||||||
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).Return(req)
|
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).Return(api.ResourceMembers{}, nil)
|
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).Return(api.ResourceMembers{}, nil)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "one member",
|
name: "one member",
|
||||||
params: org.ListMemberParams{
|
params: org.ListMemberParams{
|
||||||
OrgName: "org",
|
OrgParams: clients.OrgParams{OrgName: "org"},
|
||||||
},
|
},
|
||||||
defaultOrgName: "my-org",
|
defaultOrgName: "my-org",
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
@ -195,19 +194,19 @@ func TestClient_ListMembers(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "org", *in.GetOrg())
|
return assert.Equal(t, "org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String())
|
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1)
|
||||||
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).Return(req)
|
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).
|
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).
|
||||||
Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2.String())}}}, nil)
|
Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2)}}}, nil)
|
||||||
},
|
},
|
||||||
registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) {
|
registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) {
|
||||||
req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2.String())
|
req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2)
|
||||||
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2.String())).Return(req)
|
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2)).Return(req)
|
||||||
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{
|
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{
|
||||||
Id: api.PtrString(id2.String()),
|
Id: api.PtrString(id2),
|
||||||
Name: "user1",
|
Name: "user1",
|
||||||
Status: api.PtrString("active"),
|
Status: api.PtrString("active"),
|
||||||
}, nil)
|
}, nil)
|
||||||
@ -217,12 +216,12 @@ func TestClient_ListMembers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "many members",
|
name: "many members",
|
||||||
params: org.ListMemberParams{
|
params: org.ListMemberParams{
|
||||||
OrgID: id1,
|
OrgParams: clients.OrgParams{OrgID: id1},
|
||||||
},
|
},
|
||||||
// NOTE: We previously saw a deadlock when # members was > 10, so test that here.
|
// NOTE: We previously saw a deadlock when # members was > 10, so test that here.
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String())
|
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1)
|
||||||
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).Return(req)
|
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req)
|
||||||
members := make([]api.ResourceMember, 11)
|
members := make([]api.ResourceMember, 11)
|
||||||
for i := 0; i < 11; i++ {
|
for i := 0; i < 11; i++ {
|
||||||
members[i] = api.ResourceMember{Id: api.PtrString(fmt.Sprintf("%016d", i))}
|
members[i] = api.ResourceMember{Id: api.PtrString(fmt.Sprintf("%016d", i))}
|
||||||
@ -273,17 +272,17 @@ func TestClient_ListMembers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no such user",
|
name: "no such user",
|
||||||
params: org.ListMemberParams{
|
params: org.ListMemberParams{
|
||||||
OrgID: id1,
|
OrgParams: clients.OrgParams{OrgID: id1},
|
||||||
},
|
},
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String())
|
req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1)
|
||||||
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).Return(req)
|
orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).
|
orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).
|
||||||
Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2.String())}}}, nil)
|
Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2)}}}, nil)
|
||||||
},
|
},
|
||||||
registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) {
|
registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) {
|
||||||
req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2.String())
|
req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2)
|
||||||
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2.String())).Return(req)
|
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2)).Return(req)
|
||||||
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{}, errors.New("not found"))
|
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{}, errors.New("not found"))
|
||||||
},
|
},
|
||||||
expectedErr: "user \"2222222222222222\": not found",
|
expectedErr: "user \"2222222222222222\": not found",
|
||||||
@ -345,14 +344,14 @@ func TestClient_RemoveMembers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "org by ID",
|
name: "org by ID",
|
||||||
params: org.RemoveMemberParams{
|
params: org.RemoveMemberParams{
|
||||||
OrgID: id1,
|
OrgParams: clients.OrgParams{OrgID: id1},
|
||||||
MemberId: id2,
|
MemberId: id2,
|
||||||
},
|
},
|
||||||
defaultOrgName: "my-org",
|
defaultOrgName: "my-org",
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1.String()).UserID(id2.String())
|
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1).UserID(id2)
|
||||||
orgApi.EXPECT().
|
orgApi.EXPECT().
|
||||||
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2.String()), gomock.Eq(id1.String())).Return(req)
|
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
||||||
@ -360,8 +359,8 @@ func TestClient_RemoveMembers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "org by name",
|
name: "org by name",
|
||||||
params: org.RemoveMemberParams{
|
params: org.RemoveMemberParams{
|
||||||
OrgName: "org",
|
OrgParams: clients.OrgParams{OrgName: "org"},
|
||||||
MemberId: id2,
|
MemberId: id2,
|
||||||
},
|
},
|
||||||
defaultOrgName: "my-org",
|
defaultOrgName: "my-org",
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
@ -369,12 +368,12 @@ func TestClient_RemoveMembers(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "org", *in.GetOrg())
|
return assert.Equal(t, "org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1.String()).UserID(id2.String())
|
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1).UserID(id2)
|
||||||
orgApi.EXPECT().
|
orgApi.EXPECT().
|
||||||
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2.String()), gomock.Eq(id1.String())).Return(req)
|
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
||||||
@ -390,12 +389,12 @@ func TestClient_RemoveMembers(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "my-org", *in.GetOrg())
|
return assert.Equal(t, "my-org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}},
|
Orgs: &[]api.Organization{{Id: api.PtrString(id1)}},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1.String()).UserID(id2.String())
|
req := api.ApiDeleteOrgsIDMembersIDRequest{ApiService: orgApi}.OrgID(id1).UserID(id2)
|
||||||
orgApi.EXPECT().
|
orgApi.EXPECT().
|
||||||
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2.String()), gomock.Eq(id1.String())).Return(req)
|
DeleteOrgsIDMembersID(gomock.Any(), gomock.Eq(id2), gomock.Eq(id1)).Return(req)
|
||||||
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
orgApi.EXPECT().DeleteOrgsIDMembersIDExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
expectedOut: "user \"2222222222222222\" has been removed from org \"1111111111111111\"",
|
||||||
|
@ -13,13 +13,12 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/org"
|
"github.com/influxdata/influx-cli/v2/clients/org"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var id, _ = influxid.IDFromString("1111111111111111")
|
var id = "1111111111111111"
|
||||||
|
|
||||||
func TestClient_Create(t *testing.T) {
|
func TestClient_Create(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@ -121,14 +120,14 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
|
|
||||||
cli := org.Client{CLI: clients.CLI{StdIO: stdio}, OrganizationsApi: orgApi}
|
cli := org.Client{CLI: clients.CLI{StdIO: stdio}, OrganizationsApi: orgApi}
|
||||||
|
|
||||||
getReq := api.ApiGetOrgsIDRequest{ApiService: orgApi}.OrgID(id.String())
|
getReq := api.ApiGetOrgsIDRequest{ApiService: orgApi}.OrgID(id)
|
||||||
orgApi.EXPECT().GetOrgsID(gomock.Any(), gomock.Eq(id.String())).Return(getReq)
|
orgApi.EXPECT().GetOrgsID(gomock.Any(), gomock.Eq(id)).Return(getReq)
|
||||||
orgApi.EXPECT().GetOrgsIDExecute(gomock.Eq(getReq)).
|
orgApi.EXPECT().GetOrgsIDExecute(gomock.Eq(getReq)).
|
||||||
DoAndReturn(func(request api.ApiGetOrgsIDRequest) (api.Organization, error) {
|
DoAndReturn(func(request api.ApiGetOrgsIDRequest) (api.Organization, error) {
|
||||||
if tc.notFound {
|
if tc.notFound {
|
||||||
return api.Organization{}, &api.Error{Code: api.ERRORCODE_NOT_FOUND}
|
return api.Organization{}, &api.Error{Code: api.ERRORCODE_NOT_FOUND}
|
||||||
}
|
}
|
||||||
return api.Organization{Id: api.PtrString(id.String()), Name: "my-org"}, nil
|
return api.Organization{Id: api.PtrString(id), Name: "my-org"}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if tc.notFound {
|
if tc.notFound {
|
||||||
@ -137,8 +136,8 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
delReq := api.ApiDeleteOrgsIDRequest{ApiService: orgApi}.OrgID(id.String())
|
delReq := api.ApiDeleteOrgsIDRequest{ApiService: orgApi}.OrgID(id)
|
||||||
orgApi.EXPECT().DeleteOrgsID(gomock.Any(), gomock.Eq(id.String())).Return(delReq)
|
orgApi.EXPECT().DeleteOrgsID(gomock.Any(), gomock.Eq(id)).Return(delReq)
|
||||||
orgApi.EXPECT().DeleteOrgsIDExecute(gomock.Eq(delReq)).Return(nil)
|
orgApi.EXPECT().DeleteOrgsIDExecute(gomock.Eq(delReq)).Return(nil)
|
||||||
|
|
||||||
require.NoError(t, cli.Delete(context.Background(), id))
|
require.NoError(t, cli.Delete(context.Background(), id))
|
||||||
@ -180,8 +179,10 @@ func TestClient_List(t *testing.T) {
|
|||||||
outLines: []string{`123\s+org1`, `456\s+org2`},
|
outLines: []string{`123\s+org1`, `456\s+org2`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "by name",
|
name: "by name",
|
||||||
params: org.ListParams{Name: "org1"},
|
params: org.ListParams{
|
||||||
|
OrgParams: clients.OrgParams{OrgName: "org1"},
|
||||||
|
},
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
@ -195,15 +196,17 @@ func TestClient_List(t *testing.T) {
|
|||||||
outLines: []string{`123\s+org1`},
|
outLines: []string{`123\s+org1`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "by ID",
|
name: "by ID",
|
||||||
params: org.ListParams{ID: id},
|
params: org.ListParams{
|
||||||
|
OrgParams: clients.OrgParams{OrgID: id},
|
||||||
|
},
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Nil(t, in.GetOrg()) && assert.Equal(t, id.String(), *in.GetOrgID())
|
return assert.Nil(t, in.GetOrg()) && assert.Equal(t, id, *in.GetOrgID())
|
||||||
})).Return(api.Organizations{
|
})).Return(api.Organizations{
|
||||||
Orgs: &[]api.Organization{
|
Orgs: &[]api.Organization{
|
||||||
{Id: api.PtrString(id.String()), Name: "org3"},
|
{Id: api.PtrString(id), Name: "org3"},
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
},
|
},
|
||||||
@ -242,36 +245,44 @@ func TestClient_Update(t *testing.T) {
|
|||||||
outLine string
|
outLine string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "name",
|
name: "name",
|
||||||
params: org.UpdateParams{ID: id, Name: "my-org"},
|
params: org.UpdateParams{
|
||||||
|
OrgParams: clients.OrgParams{
|
||||||
|
OrgID: id,
|
||||||
|
OrgName: "my-org",
|
||||||
|
},
|
||||||
|
},
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PatchOrgsID(gomock.Any(), gomock.Eq(id.String())).
|
orgApi.EXPECT().PatchOrgsID(gomock.Any(), gomock.Eq(id)).
|
||||||
Return(api.ApiPatchOrgsIDRequest{ApiService: orgApi}.OrgID(id.String()))
|
Return(api.ApiPatchOrgsIDRequest{ApiService: orgApi}.OrgID(id))
|
||||||
orgApi.EXPECT().PatchOrgsIDExecute(tmock.MatchedBy(func(in api.ApiPatchOrgsIDRequest) bool {
|
orgApi.EXPECT().PatchOrgsIDExecute(tmock.MatchedBy(func(in api.ApiPatchOrgsIDRequest) bool {
|
||||||
body := in.GetPatchOrganizationRequest()
|
body := in.GetPatchOrganizationRequest()
|
||||||
return assert.Equal(t, id.String(), in.GetOrgID()) &&
|
return assert.Equal(t, id, in.GetOrgID()) &&
|
||||||
assert.NotNil(t, body) &&
|
assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, "my-org", body.GetName()) &&
|
assert.Equal(t, "my-org", body.GetName()) &&
|
||||||
assert.Nil(t, body.Description)
|
assert.Nil(t, body.Description)
|
||||||
})).Return(api.Organization{Id: api.PtrString(id.String()), Name: "my-org"}, nil)
|
})).Return(api.Organization{Id: api.PtrString(id), Name: "my-org"}, nil)
|
||||||
},
|
},
|
||||||
outLine: fmt.Sprintf(`%s\s+my-org`, id.String()),
|
outLine: fmt.Sprintf(`%s\s+my-org`, id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "description",
|
name: "description",
|
||||||
params: org.UpdateParams{ID: id, Description: "my cool org"},
|
params: org.UpdateParams{
|
||||||
|
OrgParams: clients.OrgParams{OrgID: id},
|
||||||
|
Description: "my cool org",
|
||||||
|
},
|
||||||
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PatchOrgsID(gomock.Any(), gomock.Eq(id.String())).
|
orgApi.EXPECT().PatchOrgsID(gomock.Any(), gomock.Eq(id)).
|
||||||
Return(api.ApiPatchOrgsIDRequest{ApiService: orgApi}.OrgID(id.String()))
|
Return(api.ApiPatchOrgsIDRequest{ApiService: orgApi}.OrgID(id))
|
||||||
orgApi.EXPECT().PatchOrgsIDExecute(tmock.MatchedBy(func(in api.ApiPatchOrgsIDRequest) bool {
|
orgApi.EXPECT().PatchOrgsIDExecute(tmock.MatchedBy(func(in api.ApiPatchOrgsIDRequest) bool {
|
||||||
body := in.GetPatchOrganizationRequest()
|
body := in.GetPatchOrganizationRequest()
|
||||||
return assert.Equal(t, id.String(), in.GetOrgID()) &&
|
return assert.Equal(t, id, in.GetOrgID()) &&
|
||||||
assert.NotNil(t, body) &&
|
assert.NotNil(t, body) &&
|
||||||
assert.Nil(t, body.Name) &&
|
assert.Nil(t, body.Name) &&
|
||||||
assert.Equal(t, "my cool org", body.GetDescription())
|
assert.Equal(t, "my cool org", body.GetDescription())
|
||||||
})).Return(api.Organization{Id: api.PtrString(id.String()), Name: "my-org"}, nil)
|
})).Return(api.Organization{Id: api.PtrString(id), Name: "my-org"}, nil)
|
||||||
},
|
},
|
||||||
outLine: fmt.Sprintf(`%s\s+my-org`, id.String()),
|
outLine: fmt.Sprintf(`%s\s+my-org`, id),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,41 @@
|
|||||||
package clients
|
package clients
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OrgParams struct {
|
type OrgParams struct {
|
||||||
OrgID influxid.ID
|
OrgID string
|
||||||
OrgName string
|
OrgName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p OrgParams) GetOrgID(ctx context.Context, activeConfig config.Config, orgApi api.OrganizationsApi) (string, error) {
|
||||||
|
if p.OrgID != "" {
|
||||||
|
return p.OrgID, nil
|
||||||
|
}
|
||||||
|
orgName := p.OrgName
|
||||||
|
if orgName == "" {
|
||||||
|
orgName = activeConfig.Org
|
||||||
|
}
|
||||||
|
if orgName == "" {
|
||||||
|
return "", ErrMustSpecifyOrg
|
||||||
|
}
|
||||||
|
res, err := orgApi.GetOrgs(ctx).Org(orgName).Execute()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to lookup org with name %q: %w", orgName, err)
|
||||||
|
}
|
||||||
|
if len(res.GetOrgs()) == 0 {
|
||||||
|
return "", fmt.Errorf("no organization with name %q", orgName)
|
||||||
|
}
|
||||||
|
return res.GetOrgs()[0].GetId(), nil
|
||||||
|
}
|
||||||
|
|
||||||
type BucketParams struct {
|
type BucketParams struct {
|
||||||
BucketID influxid.ID
|
BucketID string
|
||||||
BucketName string
|
BucketName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ func BuildExternAST(profilers []string) *api.Extern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Query(ctx context.Context, params *Params) error {
|
func (c Client) Query(ctx context.Context, params *Params) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return clients.ErrMustSpecifyOrg
|
return clients.ErrMustSpecifyOrg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +130,8 @@ func (c Client) Query(ctx context.Context, params *Params) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := c.PostQuery(ctx).Query(query).AcceptEncoding("gzip")
|
req := c.PostQuery(ctx).Query(query).AcceptEncoding("gzip")
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
} else if params.OrgName != "" {
|
} else if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/query"
|
"github.com/influxdata/influx-cli/v2/clients/query"
|
||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -92,8 +91,7 @@ func TestQuery(t *testing.T) {
|
|||||||
fakeQuery := query.BuildDefaultAST("I'm a query!")
|
fakeQuery := query.BuildDefaultAST("I'm a query!")
|
||||||
fakeResults := "data data data"
|
fakeResults := "data data data"
|
||||||
|
|
||||||
orgID, err := influxid.IDFromString("1111111111111111")
|
orgID := "1111111111111111"
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -117,7 +115,7 @@ func TestQuery(t *testing.T) {
|
|||||||
body := in.GetQuery()
|
body := in.GetQuery()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, fakeQuery, *body) &&
|
assert.Equal(t, fakeQuery, *body) &&
|
||||||
assert.Equal(t, orgID.String(), *in.GetOrgID()) &&
|
assert.Equal(t, orgID, *in.GetOrgID()) &&
|
||||||
assert.Nil(t, in.GetOrg())
|
assert.Nil(t, in.GetOrg())
|
||||||
})).Return(&http.Response{Body: io.NopCloser(strings.NewReader(fakeResults))}, nil)
|
})).Return(&http.Response{Body: io.NopCloser(strings.NewReader(fakeResults))}, nil)
|
||||||
},
|
},
|
||||||
@ -206,7 +204,7 @@ func TestQuery(t *testing.T) {
|
|||||||
body := in.GetQuery()
|
body := in.GetQuery()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, fakeQuery, *body) &&
|
assert.Equal(t, fakeQuery, *body) &&
|
||||||
assert.Equal(t, orgID.String(), *in.GetOrgID()) &&
|
assert.Equal(t, orgID, *in.GetOrgID()) &&
|
||||||
assert.Nil(t, in.GetOrg())
|
assert.Nil(t, in.GetOrg())
|
||||||
})).DoAndReturn(func(api.ApiPostQueryRequest) (*http.Response, error) {
|
})).DoAndReturn(func(api.ApiPostQueryRequest) (*http.Response, error) {
|
||||||
pr, pw := io.Pipe()
|
pr, pw := io.Pipe()
|
||||||
|
@ -16,10 +16,9 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateParams struct {
|
type CreateParams struct {
|
||||||
|
clients.OrgParams
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
RemoteURL string
|
RemoteURL string
|
||||||
RemoteAPIToken string
|
RemoteAPIToken string
|
||||||
RemoteOrgID string
|
RemoteOrgID string
|
||||||
@ -28,7 +27,7 @@ type CreateParams struct {
|
|||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||||
|
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -106,15 +105,14 @@ func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListParams struct {
|
type ListParams struct {
|
||||||
|
clients.OrgParams
|
||||||
Name string
|
Name string
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
RemoteURL string
|
RemoteURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
|
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,9 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateParams struct {
|
type CreateParams struct {
|
||||||
|
clients.OrgParams
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
RemoteID string
|
RemoteID string
|
||||||
LocalBucketID string
|
LocalBucketID string
|
||||||
RemoteBucketID string
|
RemoteBucketID string
|
||||||
@ -27,7 +26,7 @@ type CreateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -58,16 +57,14 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListParams struct {
|
type ListParams struct {
|
||||||
|
clients.OrgParams
|
||||||
Name string
|
Name string
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
RemoteID string
|
RemoteID string
|
||||||
LocalBucketID string
|
LocalBucketID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ type Params struct {
|
|||||||
|
|
||||||
// Original ID/name of the organization to restore.
|
// Original ID/name of the organization to restore.
|
||||||
// If not set, all orgs will be restored.
|
// If not set, all orgs will be restored.
|
||||||
OrgID string
|
clients.OrgParams
|
||||||
Org string
|
|
||||||
|
|
||||||
// New name to use for the restored organization.
|
// New name to use for the restored organization.
|
||||||
// If not set, the org will be restored using its backed-up name.
|
// If not set, the org will be restored using its backed-up name.
|
||||||
@ -49,8 +48,7 @@ type Params struct {
|
|||||||
|
|
||||||
// Original ID/name of the bucket to restore.
|
// Original ID/name of the bucket to restore.
|
||||||
// If not set, all buckets within the org filter will be restored.
|
// If not set, all buckets within the org filter will be restored.
|
||||||
BucketID string
|
clients.BucketParams
|
||||||
Bucket string
|
|
||||||
|
|
||||||
// New name to use for the restored bucket.
|
// New name to use for the restored bucket.
|
||||||
// If not set, the bucket will be restored using its backed-up name.
|
// If not set, the bucket will be restored using its backed-up name.
|
||||||
@ -65,13 +63,13 @@ func (p *Params) matches(bkt br.ManifestBucketEntry) bool {
|
|||||||
if p.OrgID != "" && bkt.OrganizationID != p.OrgID {
|
if p.OrgID != "" && bkt.OrganizationID != p.OrgID {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.Org != "" && bkt.OrganizationName != p.Org {
|
if p.OrgName != "" && bkt.OrganizationName != p.OrgName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.BucketID != "" && bkt.BucketID != p.BucketID {
|
if p.BucketID != "" && bkt.BucketID != p.BucketID {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if p.Bucket != "" && bkt.BucketName != p.Bucket {
|
if p.BucketName != "" && bkt.BucketName != p.BucketName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -31,7 +31,7 @@ type DeleteParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, params *DeleteParams) error {
|
func (c Client) Delete(ctx context.Context, params *DeleteParams) error {
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgParams)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -60,8 +60,7 @@ type ListParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgParams)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ type UpdateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgParams)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -149,7 +148,3 @@ func (c Client) printSecrets(opts secretPrintOpt) error {
|
|||||||
}
|
}
|
||||||
return c.PrintTable(headers, rows...)
|
return c.PrintTable(headers, rows...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrgID(ctx context.Context, params clients.OrgParams) (string, error) {
|
|
||||||
return c.GetOrgIdI(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
|
||||||
}
|
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients/secret"
|
"github.com/influxdata/influx-cli/v2/clients/secret"
|
||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,8 +24,7 @@ func TestSecret_List(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
printHeader := "Key\t\tOrganization ID\n"
|
printHeader := "Key\t\tOrganization ID\n"
|
||||||
id, err := influxid.IDFromString("1111111111111111")
|
id := "1111111111111111"
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -45,12 +43,12 @@ func TestSecret_List(t *testing.T) {
|
|||||||
},
|
},
|
||||||
defaultOrgName: defaultOrgName,
|
defaultOrgName: defaultOrgName,
|
||||||
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, orgApi *mock.MockOrganizationsApi) {
|
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, orgApi *mock.MockOrganizationsApi) {
|
||||||
req := api.ApiGetOrgsIDSecretsRequest{ApiService: secretApi}.OrgID(id.String())
|
req := api.ApiGetOrgsIDSecretsRequest{ApiService: secretApi}.OrgID(id)
|
||||||
secretApi.EXPECT().GetOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().GetOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().GetOrgsIDSecretsExecute(gomock.Eq(req)).
|
secretApi.EXPECT().GetOrgsIDSecretsExecute(gomock.Eq(req)).
|
||||||
Return(api.SecretKeysResponse{Secrets: &[]string{fakeResults}}, nil)
|
Return(api.SecretKeysResponse{Secrets: &[]string{fakeResults}}, nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + fakeResults + "\t" + id.String() + "\n",
|
expectMatcher: printHeader + fakeResults + "\t" + id + "\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default org",
|
name: "default org",
|
||||||
@ -122,8 +120,7 @@ func TestSecret_Delete(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
printHeader := "Key\tOrganization ID\t\tDeleted\n"
|
printHeader := "Key\tOrganization ID\t\tDeleted\n"
|
||||||
id, err := influxid.IDFromString("1111111111111111")
|
id := "1111111111111111"
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -144,12 +141,12 @@ func TestSecret_Delete(t *testing.T) {
|
|||||||
defaultOrgName: defaultOrgName,
|
defaultOrgName: defaultOrgName,
|
||||||
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi) {
|
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi) {
|
||||||
req := api.ApiPostOrgsIDSecretsRequest{ApiService: secretApi}.
|
req := api.ApiPostOrgsIDSecretsRequest{ApiService: secretApi}.
|
||||||
OrgID(id.String()).
|
OrgID(id).
|
||||||
SecretKeys(api.SecretKeys{Secrets: &[]string{"key1"}})
|
SecretKeys(api.SecretKeys{Secrets: &[]string{"key1"}})
|
||||||
secretApi.EXPECT().PostOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().PostOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().PostOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
secretApi.EXPECT().PostOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + fakeKey + "\t" + id.String() + "\ttrue\n",
|
expectMatcher: printHeader + fakeKey + "\t" + id + "\ttrue\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// This situation cannot happen since the CLI will stop it.
|
// This situation cannot happen since the CLI will stop it.
|
||||||
@ -163,12 +160,12 @@ func TestSecret_Delete(t *testing.T) {
|
|||||||
defaultOrgName: defaultOrgName,
|
defaultOrgName: defaultOrgName,
|
||||||
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi) {
|
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi) {
|
||||||
req := api.ApiPostOrgsIDSecretsRequest{ApiService: secretApi}.
|
req := api.ApiPostOrgsIDSecretsRequest{ApiService: secretApi}.
|
||||||
OrgID(id.String()).
|
OrgID(id).
|
||||||
SecretKeys(api.SecretKeys{Secrets: &[]string{""}})
|
SecretKeys(api.SecretKeys{Secrets: &[]string{""}})
|
||||||
secretApi.EXPECT().PostOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().PostOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().PostOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
secretApi.EXPECT().PostOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + "\t" + id.String() + "\ttrue\n",
|
expectMatcher: printHeader + "\t" + id + "\ttrue\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "delete no org",
|
name: "delete no org",
|
||||||
@ -220,8 +217,7 @@ func TestSecret_Update(t *testing.T) {
|
|||||||
|
|
||||||
printHeader := "Key\tOrganization ID\n"
|
printHeader := "Key\tOrganization ID\n"
|
||||||
fakeValue := "someValue"
|
fakeValue := "someValue"
|
||||||
id, err := influxid.IDFromString("1111111111111111")
|
id := "1111111111111111"
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -243,12 +239,12 @@ func TestSecret_Update(t *testing.T) {
|
|||||||
defaultOrgName: defaultOrgName,
|
defaultOrgName: defaultOrgName,
|
||||||
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, stdio *mock.MockStdIO) {
|
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, stdio *mock.MockStdIO) {
|
||||||
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
||||||
OrgID(id.String()).
|
OrgID(id).
|
||||||
RequestBody(map[string]string{fakeKey: fakeValue})
|
RequestBody(map[string]string{fakeKey: fakeValue})
|
||||||
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + fakeKey + "\t" + id.String() + "\n",
|
expectMatcher: printHeader + fakeKey + "\t" + id + "\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update no key",
|
name: "update no key",
|
||||||
@ -261,12 +257,12 @@ func TestSecret_Update(t *testing.T) {
|
|||||||
defaultOrgName: defaultOrgName,
|
defaultOrgName: defaultOrgName,
|
||||||
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, stdio *mock.MockStdIO) {
|
registerExpectations: func(t *testing.T, secretApi *mock.MockSecretsApi, stdio *mock.MockStdIO) {
|
||||||
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
||||||
OrgID(id.String()).
|
OrgID(id).
|
||||||
RequestBody(map[string]string{"": fakeValue})
|
RequestBody(map[string]string{"": fakeValue})
|
||||||
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + "\t" + id.String() + "\n",
|
expectMatcher: printHeader + "\t" + id + "\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update no value",
|
name: "update no value",
|
||||||
@ -281,12 +277,12 @@ func TestSecret_Update(t *testing.T) {
|
|||||||
stdio.EXPECT().GetSecret(gomock.Eq("Please type your secret"), gomock.Eq(0)).Return(fakeValue, nil)
|
stdio.EXPECT().GetSecret(gomock.Eq("Please type your secret"), gomock.Eq(0)).Return(fakeValue, nil)
|
||||||
|
|
||||||
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
req := api.ApiPatchOrgsIDSecretsRequest{ApiService: secretApi}.
|
||||||
OrgID(id.String()).
|
OrgID(id).
|
||||||
RequestBody(map[string]string{fakeKey: fakeValue})
|
RequestBody(map[string]string{fakeKey: fakeValue})
|
||||||
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id.String())).Return(req)
|
secretApi.EXPECT().PatchOrgsIDSecrets(gomock.Any(), gomock.Eq(id)).Return(req)
|
||||||
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
secretApi.EXPECT().PatchOrgsIDSecretsExecute(gomock.Eq(req)).Return(nil)
|
||||||
},
|
},
|
||||||
expectMatcher: printHeader + fakeKey + "\t" + id.String() + "\n",
|
expectMatcher: printHeader + fakeKey + "\t" + id + "\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update no org",
|
name: "update no org",
|
||||||
|
@ -18,19 +18,14 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListParams struct {
|
type ListParams struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
StackIds []string
|
StackIds []string
|
||||||
StackNames []string
|
StackNames []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
if params.OrgId == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
|
||||||
}
|
|
||||||
|
|
||||||
orgId, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -44,8 +39,7 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InitParams struct {
|
type InitParams struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
@ -53,11 +47,7 @@ type InitParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Init(ctx context.Context, params *InitParams) error {
|
func (c Client) Init(ctx context.Context, params *InitParams) error {
|
||||||
if params.OrgId == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
|
||||||
}
|
|
||||||
|
|
||||||
orgId, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -80,19 +70,14 @@ func (c Client) Init(ctx context.Context, params *InitParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RemoveParams struct {
|
type RemoveParams struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
Ids []string
|
Ids []string
|
||||||
Force bool
|
Force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Remove(ctx context.Context, params *RemoveParams) error {
|
func (c Client) Remove(ctx context.Context, params *RemoveParams) error {
|
||||||
if params.OrgId == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
|
||||||
}
|
|
||||||
|
|
||||||
orgId, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ func addOrg(n NameOrID, g api.ApiGetTasksRequest) api.ApiGetTasksRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrg(params *clients.OrgParams) (NameOrID, error) {
|
func (c Client) getOrg(params *clients.OrgParams) (NameOrID, error) {
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
return NameOrID{ID: params.OrgID.String()}, nil
|
return NameOrID{ID: params.OrgID}, nil
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
return NameOrID{Name: params.OrgName}, nil
|
return NameOrID{Name: params.OrgName}, nil
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
"github.com/influxdata/influx-cli/v2/clients"
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -27,7 +26,7 @@ type ListParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
if params.Id == "" && !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.Id == "" && params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return errors.New("at least one of org, org-id, or id must be provided")
|
return errors.New("at least one of org, org-id, or id must be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
return c.printTelegrafs(telegrafPrintOpts{graf: &telegraf})
|
return c.printTelegrafs(telegrafPrintOpts{graf: &telegraf})
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgID, params.OrgName)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,7 +60,7 @@ type CreateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgID, params.OrgName)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -154,7 +153,3 @@ func (c Client) printTelegrafs(opts telegrafPrintOpts) error {
|
|||||||
|
|
||||||
return c.PrintTable(headers, rows...)
|
return c.PrintTable(headers, rows...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrgID(ctx context.Context, orgID influxid.ID, orgName string) (string, error) {
|
|
||||||
return c.GetOrgIdI(ctx, orgID, orgName, c.OrganizationsApi)
|
|
||||||
}
|
|
||||||
|
@ -16,8 +16,7 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SummarizeParams struct {
|
type SummarizeParams struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
Sources []template.Source
|
Sources []template.Source
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ type SummarizeParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Summarize(ctx context.Context, params *SummarizeParams) error {
|
func (c Client) Summarize(ctx context.Context, params *SummarizeParams) error {
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -54,14 +53,13 @@ func (c Client) Summarize(ctx context.Context, params *SummarizeParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ValidateParams struct {
|
type ValidateParams struct {
|
||||||
OrgId string
|
clients.OrgParams
|
||||||
OrgName string
|
|
||||||
|
|
||||||
Sources []template.Source
|
Sources []template.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Validate(ctx context.Context, params *ValidateParams) error {
|
func (c Client) Validate(ctx context.Context, params *ValidateParams) error {
|
||||||
orgID, err := c.GetOrgId(ctx, params.OrgId, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
"github.com/influxdata/influx-cli/v2/clients"
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/stdio"
|
"github.com/influxdata/influx-cli/v2/pkg/stdio"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
return clients.ErrPasswordIsTooShort
|
return clients.ErrPasswordIsTooShort
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID, err := c.GetOrgIdI(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -61,26 +60,26 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, id influxid.ID) error {
|
func (c Client) Delete(ctx context.Context, id string) error {
|
||||||
user, err := c.GetUsersID(ctx, id.String()).Execute()
|
user, err := c.GetUsersID(ctx, id).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("user %q not found: %w", id, err)
|
return fmt.Errorf("user %q not found: %w", id, err)
|
||||||
}
|
}
|
||||||
if err := c.DeleteUsersID(ctx, id.String()).Execute(); err != nil {
|
if err := c.DeleteUsersID(ctx, id).Execute(); err != nil {
|
||||||
return fmt.Errorf("failed to delete user %q: %w", id, err)
|
return fmt.Errorf("failed to delete user %q: %w", id, err)
|
||||||
}
|
}
|
||||||
return c.printUsers(printUserOpts{user: &user, deleted: true})
|
return c.printUsers(printUserOpts{user: &user, deleted: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListParams struct {
|
type ListParams struct {
|
||||||
Id influxid.ID
|
Id string
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
req := c.GetUsers(ctx)
|
req := c.GetUsers(ctx)
|
||||||
if params.Id.Valid() {
|
if params.Id != "" {
|
||||||
req = req.Id(params.Id.String())
|
req = req.Id(params.Id)
|
||||||
}
|
}
|
||||||
if params.Name != "" {
|
if params.Name != "" {
|
||||||
req = req.Name(params.Name)
|
req = req.Name(params.Name)
|
||||||
@ -96,17 +95,17 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
return c.printUsers(printOpts)
|
return c.printUsers(printOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateParmas struct {
|
type UpdateParams struct {
|
||||||
Id influxid.ID
|
Id string
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Update(ctx context.Context, params *UpdateParmas) error {
|
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
||||||
update := api.User{}
|
update := api.User{}
|
||||||
if params.Name != "" {
|
if params.Name != "" {
|
||||||
update.SetName(params.Name)
|
update.SetName(params.Name)
|
||||||
}
|
}
|
||||||
user, err := c.PatchUsersID(ctx, params.Id.String()).User(update).Execute()
|
user, err := c.PatchUsersID(ctx, params.Id).User(update).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update user %q: %w", params.Id, err)
|
return fmt.Errorf("failed to update user %q: %w", params.Id, err)
|
||||||
}
|
}
|
||||||
@ -114,18 +113,18 @@ func (c Client) Update(ctx context.Context, params *UpdateParmas) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SetPasswordParams struct {
|
type SetPasswordParams struct {
|
||||||
Id influxid.ID
|
Id string
|
||||||
Name string
|
Name string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) SetPassword(ctx context.Context, params *SetPasswordParams) (err error) {
|
func (c Client) SetPassword(ctx context.Context, params *SetPasswordParams) (err error) {
|
||||||
if !params.Id.Valid() && params.Name == "" {
|
if params.Id == "" && params.Name == "" {
|
||||||
return ErrMustSpecifyUser
|
return ErrMustSpecifyUser
|
||||||
}
|
}
|
||||||
id := params.Id.String()
|
id := params.Id
|
||||||
displayName := id
|
displayName := id
|
||||||
if !params.Id.Valid() {
|
if params.Id == "" {
|
||||||
displayName = params.Name
|
displayName = params.Name
|
||||||
users, err := c.GetUsers(ctx).Name(params.Name).Execute()
|
users, err := c.GetUsers(ctx).Name(params.Name).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,7 +146,7 @@ func (c Client) SetPassword(ctx context.Context, params *SetPasswordParams) (err
|
|||||||
|
|
||||||
body := api.PasswordResetBody{Password: password}
|
body := api.PasswordResetBody{Password: password}
|
||||||
if err := c.PostUsersIDPassword(ctx, id).PasswordResetBody(body).Execute(); err != nil {
|
if err := c.PostUsersIDPassword(ctx, id).PasswordResetBody(body).Execute(); err != nil {
|
||||||
return fmt.Errorf("failed to set password for user %q: %w", params.Id.String(), err)
|
return fmt.Errorf("failed to set password for user %q: %w", params.Id, err)
|
||||||
}
|
}
|
||||||
_, err = c.StdIO.Write([]byte(fmt.Sprintf("Successfully updated password for user %q\n", displayName)))
|
_, err = c.StdIO.Write([]byte(fmt.Sprintf("Successfully updated password for user %q\n", displayName)))
|
||||||
return err
|
return err
|
||||||
|
@ -14,14 +14,13 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/config"
|
"github.com/influxdata/influx-cli/v2/config"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
tmock "github.com/stretchr/testify/mock"
|
tmock "github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var id1, _ = influxid.IDFromString("1111111111111111")
|
var id1 = "1111111111111111"
|
||||||
var id2, _ = influxid.IDFromString("2222222222222222")
|
var id2 = "2222222222222222"
|
||||||
|
|
||||||
func TestClient_Create(t *testing.T) {
|
func TestClient_Create(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@ -52,27 +51,27 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
|
|
||||||
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2))
|
||||||
userApi.EXPECT().
|
userApi.EXPECT().
|
||||||
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "my-password", body.GetPassword())
|
assert.Equal(t, "my-password", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
},
|
},
|
||||||
@ -91,15 +90,15 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
|
|
||||||
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2))
|
||||||
userApi.EXPECT().
|
userApi.EXPECT().
|
||||||
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "my-password", body.GetPassword())
|
assert.Equal(t, "my-password", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
@ -107,16 +106,16 @@ func TestClient_Create(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "my-org", *in.GetOrg())
|
return assert.Equal(t, "my-org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}}}, nil)
|
})).Return(api.Organizations{Orgs: &[]api.Organization{{Id: api.PtrString(id1)}}}, nil)
|
||||||
|
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
},
|
},
|
||||||
@ -132,15 +131,15 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
|
|
||||||
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2))
|
||||||
userApi.EXPECT().
|
userApi.EXPECT().
|
||||||
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "my-password", body.GetPassword())
|
assert.Equal(t, "my-password", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
@ -148,16 +147,16 @@ func TestClient_Create(t *testing.T) {
|
|||||||
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi})
|
||||||
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool {
|
||||||
return assert.Equal(t, "my-default-org", *in.GetOrg())
|
return assert.Equal(t, "my-default-org", *in.GetOrg())
|
||||||
})).Return(api.Organizations{Orgs: &[]api.Organization{{Id: api.PtrString(id1.String())}}}, nil)
|
})).Return(api.Organizations{Orgs: &[]api.Organization{{Id: api.PtrString(id1)}}}, nil)
|
||||||
|
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
},
|
},
|
||||||
@ -175,17 +174,17 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
},
|
},
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
expectedStderr: `initial password not set`,
|
expectedStderr: `initial password not set`,
|
||||||
@ -228,16 +227,16 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
},
|
},
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{}, errors.New("I broke"))
|
})).Return(api.ResourceMember{}, errors.New("I broke"))
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
@ -259,27 +258,27 @@ func TestClient_Create(t *testing.T) {
|
|||||||
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
userApi.EXPECT().PostUsersExecute(tmock.MatchedBy(func(in api.ApiPostUsersRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
return assert.NotNil(t, body) && assert.Equal(t, "my-user", body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil)
|
||||||
|
|
||||||
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
userApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: userApi}.UserID(id2))
|
||||||
userApi.EXPECT().
|
userApi.EXPECT().
|
||||||
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "my-password", body.GetPassword())
|
assert.Equal(t, "my-password", body.GetPassword())
|
||||||
})).Return(errors.New("I broke"))
|
})).Return(errors.New("I broke"))
|
||||||
},
|
},
|
||||||
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) {
|
||||||
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1.String())).
|
orgApi.EXPECT().PostOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).
|
||||||
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1.String()))
|
Return(api.ApiPostOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1))
|
||||||
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
orgApi.EXPECT().PostOrgsIDMembersExecute(tmock.MatchedBy(func(in api.ApiPostOrgsIDMembersRequest) bool {
|
||||||
body := in.GetAddResourceMemberRequestBody()
|
body := in.GetAddResourceMemberRequestBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id1.String(), in.GetOrgID()) &&
|
assert.Equal(t, id1, in.GetOrgID()) &&
|
||||||
assert.Equal(t, id2.String(), body.GetId())
|
assert.Equal(t, id2, body.GetId())
|
||||||
})).Return(api.ResourceMember{Id: api.PtrString(id2.String())}, nil)
|
})).Return(api.ResourceMember{Id: api.PtrString(id2)}, nil)
|
||||||
},
|
},
|
||||||
expectedOut: `2222222222222222\s+my-user`,
|
expectedOut: `2222222222222222\s+my-user`,
|
||||||
expectedErr: "I broke",
|
expectedErr: "I broke",
|
||||||
@ -358,14 +357,14 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
|
|
||||||
cli := user.Client{CLI: clients.CLI{StdIO: stdio}, UsersApi: userApi}
|
cli := user.Client{CLI: clients.CLI{StdIO: stdio}, UsersApi: userApi}
|
||||||
|
|
||||||
getReq := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2.String())
|
getReq := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2)
|
||||||
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2.String())).Return(getReq)
|
userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2)).Return(getReq)
|
||||||
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(getReq)).
|
userApi.EXPECT().GetUsersIDExecute(gomock.Eq(getReq)).
|
||||||
DoAndReturn(func(api.ApiGetUsersIDRequest) (api.UserResponse, error) {
|
DoAndReturn(func(api.ApiGetUsersIDRequest) (api.UserResponse, error) {
|
||||||
if tc.notFound {
|
if tc.notFound {
|
||||||
return api.UserResponse{}, &api.Error{Code: api.ERRORCODE_NOT_FOUND}
|
return api.UserResponse{}, &api.Error{Code: api.ERRORCODE_NOT_FOUND}
|
||||||
}
|
}
|
||||||
return api.UserResponse{Id: api.PtrString(id2.String()), Name: "my-user"}, nil
|
return api.UserResponse{Id: api.PtrString(id2), Name: "my-user"}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if tc.notFound {
|
if tc.notFound {
|
||||||
@ -374,8 +373,8 @@ func TestClient_Delete(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
delReq := api.ApiDeleteUsersIDRequest{ApiService: userApi}.UserID(id2.String())
|
delReq := api.ApiDeleteUsersIDRequest{ApiService: userApi}.UserID(id2)
|
||||||
userApi.EXPECT().DeleteUsersID(gomock.Any(), gomock.Eq(id2.String())).Return(delReq)
|
userApi.EXPECT().DeleteUsersID(gomock.Any(), gomock.Eq(id2)).Return(delReq)
|
||||||
userApi.EXPECT().DeleteUsersIDExecute(delReq).Return(nil)
|
userApi.EXPECT().DeleteUsersIDExecute(delReq).Return(nil)
|
||||||
|
|
||||||
err := cli.Delete(context.Background(), id2)
|
err := cli.Delete(context.Background(), id2)
|
||||||
@ -438,10 +437,10 @@ func TestClient_List(t *testing.T) {
|
|||||||
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
||||||
usersApi.EXPECT().GetUsers(gomock.Any()).Return(api.ApiGetUsersRequest{ApiService: usersApi})
|
usersApi.EXPECT().GetUsers(gomock.Any()).Return(api.ApiGetUsersRequest{ApiService: usersApi})
|
||||||
usersApi.EXPECT().GetUsersExecute(tmock.MatchedBy(func(in api.ApiGetUsersRequest) bool {
|
usersApi.EXPECT().GetUsersExecute(tmock.MatchedBy(func(in api.ApiGetUsersRequest) bool {
|
||||||
return assert.Equal(t, id2.String(), *in.GetId()) && assert.Nil(t, in.GetName())
|
return assert.Equal(t, id2, *in.GetId()) && assert.Nil(t, in.GetName())
|
||||||
})).Return(api.Users{
|
})).Return(api.Users{
|
||||||
Users: &[]api.UserResponse{
|
Users: &[]api.UserResponse{
|
||||||
{Id: api.PtrString(id2.String()), Name: "user11"},
|
{Id: api.PtrString(id2), Name: "user11"},
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
},
|
},
|
||||||
@ -477,21 +476,21 @@ func TestClient_Update(t *testing.T) {
|
|||||||
|
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
userApi := mock.NewMockUsersApi(ctrl)
|
userApi := mock.NewMockUsersApi(ctrl)
|
||||||
userApi.EXPECT().PatchUsersID(gomock.Any(), gomock.Eq(id2.String())).
|
userApi.EXPECT().PatchUsersID(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPatchUsersIDRequest{ApiService: userApi}.UserID(id2.String()))
|
Return(api.ApiPatchUsersIDRequest{ApiService: userApi}.UserID(id2))
|
||||||
userApi.EXPECT().PatchUsersIDExecute(tmock.MatchedBy(func(in api.ApiPatchUsersIDRequest) bool {
|
userApi.EXPECT().PatchUsersIDExecute(tmock.MatchedBy(func(in api.ApiPatchUsersIDRequest) bool {
|
||||||
body := in.GetUser()
|
body := in.GetUser()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, newName, body.GetName())
|
assert.Equal(t, newName, body.GetName())
|
||||||
})).Return(api.UserResponse{Id: api.PtrString(id2.String()), Name: newName}, nil)
|
})).Return(api.UserResponse{Id: api.PtrString(id2), Name: newName}, nil)
|
||||||
|
|
||||||
stdout := bytes.Buffer{}
|
stdout := bytes.Buffer{}
|
||||||
stdio := mock.NewMockStdIO(ctrl)
|
stdio := mock.NewMockStdIO(ctrl)
|
||||||
stdio.EXPECT().Write(gomock.Any()).DoAndReturn(stdout.Write).AnyTimes()
|
stdio.EXPECT().Write(gomock.Any()).DoAndReturn(stdout.Write).AnyTimes()
|
||||||
|
|
||||||
cli := user.Client{CLI: clients.CLI{StdIO: stdio}, UsersApi: userApi}
|
cli := user.Client{CLI: clients.CLI{StdIO: stdio}, UsersApi: userApi}
|
||||||
require.NoError(t, cli.Update(context.Background(), &user.UpdateParmas{Id: id2, Name: newName}))
|
require.NoError(t, cli.Update(context.Background(), &user.UpdateParams{Id: id2, Name: newName}))
|
||||||
testutils.MatchLines(t, []string{`ID\s+Name`, `2222222222222222\s+my-new-name`}, strings.Split(stdout.String(), "\n"))
|
testutils.MatchLines(t, []string{`ID\s+Name`, `2222222222222222\s+my-new-name`}, strings.Split(stdout.String(), "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,12 +510,12 @@ func TestClient_SetPassword(t *testing.T) {
|
|||||||
Id: id2,
|
Id: id2,
|
||||||
},
|
},
|
||||||
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
||||||
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2))
|
||||||
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "mypassword", body.GetPassword())
|
assert.Equal(t, "mypassword", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
@ -530,14 +529,14 @@ func TestClient_SetPassword(t *testing.T) {
|
|||||||
usersApi.EXPECT().GetUsers(gomock.Any()).Return(api.ApiGetUsersRequest{ApiService: usersApi})
|
usersApi.EXPECT().GetUsers(gomock.Any()).Return(api.ApiGetUsersRequest{ApiService: usersApi})
|
||||||
usersApi.EXPECT().GetUsersExecute(tmock.MatchedBy(func(in api.ApiGetUsersRequest) bool {
|
usersApi.EXPECT().GetUsersExecute(tmock.MatchedBy(func(in api.ApiGetUsersRequest) bool {
|
||||||
return assert.Equal(t, "my-user", *in.GetName())
|
return assert.Equal(t, "my-user", *in.GetName())
|
||||||
})).Return(api.Users{Users: &[]api.UserResponse{{Id: api.PtrString(id2.String())}}}, nil)
|
})).Return(api.Users{Users: &[]api.UserResponse{{Id: api.PtrString(id2)}}}, nil)
|
||||||
|
|
||||||
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2))
|
||||||
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "mypassword", body.GetPassword())
|
assert.Equal(t, "mypassword", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
@ -550,12 +549,12 @@ func TestClient_SetPassword(t *testing.T) {
|
|||||||
},
|
},
|
||||||
noExpectAsk: true,
|
noExpectAsk: true,
|
||||||
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
registerExpectations: func(t *testing.T, usersApi *mock.MockUsersApi) {
|
||||||
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2.String())).
|
usersApi.EXPECT().PostUsersIDPassword(gomock.Any(), gomock.Eq(id2)).
|
||||||
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2.String()))
|
Return(api.ApiPostUsersIDPasswordRequest{ApiService: usersApi}.UserID(id2))
|
||||||
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
usersApi.EXPECT().PostUsersIDPasswordExecute(tmock.MatchedBy(func(in api.ApiPostUsersIDPasswordRequest) bool {
|
||||||
body := in.GetPasswordResetBody()
|
body := in.GetPasswordResetBody()
|
||||||
return assert.NotNil(t, body) &&
|
return assert.NotNil(t, body) &&
|
||||||
assert.Equal(t, id2.String(), in.GetUserID()) &&
|
assert.Equal(t, id2, in.GetUserID()) &&
|
||||||
assert.Equal(t, "mypassword", body.GetPassword())
|
assert.Equal(t, "mypassword", body.GetPassword())
|
||||||
})).Return(nil)
|
})).Return(nil)
|
||||||
},
|
},
|
||||||
|
@ -17,21 +17,21 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AuthLookupParams struct {
|
type AuthLookupParams struct {
|
||||||
ID influxid.ID
|
ID string
|
||||||
Username string
|
Username string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p AuthLookupParams) Validate() (err error) {
|
func (p AuthLookupParams) Validate() (err error) {
|
||||||
if p.Username == "" && !p.ID.Valid() {
|
if p.Username == "" && p.ID == "" {
|
||||||
err = fmt.Errorf("id or username required")
|
err = fmt.Errorf("id or username required")
|
||||||
} else if p.Username != "" && p.ID.Valid() {
|
} else if p.Username != "" && p.ID != "" {
|
||||||
err = fmt.Errorf("specify id or username, not both")
|
err = fmt.Errorf("specify id or username, not both")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p AuthLookupParams) IsSet() bool {
|
func (p AuthLookupParams) IsSet() bool {
|
||||||
return p.ID.Valid() || p.Username != ""
|
return p.ID != "" || p.Username != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type v1PrintOpts struct {
|
type v1PrintOpts struct {
|
||||||
@ -65,7 +65,7 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
return fmt.Errorf("only one of --password and --no-password may be specified")
|
return fmt.Errorf("only one of --password and --no-password may be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID, err := c.getOrgID(ctx, params.OrgParams)
|
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
for _, bp := range bucketPerms {
|
for _, bp := range bucketPerms {
|
||||||
for _, p := range bp.perms {
|
for _, p := range bp.perms {
|
||||||
// verify the input ID
|
// verify the input ID
|
||||||
if _, err := influxid.IDFromString(p); err != nil {
|
if err := influxid.Validate(p); err != nil {
|
||||||
return fmt.Errorf("invalid bucket ID '%s': %w (did you pass a bucket name instead of an ID?)", p, err)
|
return fmt.Errorf("invalid bucket ID '%s': %w (did you pass a bucket name instead of an ID?)", p, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +220,8 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
if params.UserID != "" {
|
if params.UserID != "" {
|
||||||
req = req.UserID(params.UserID)
|
req = req.UserID(params.UserID)
|
||||||
}
|
}
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
@ -229,8 +229,8 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
if params.Username != "" {
|
if params.Username != "" {
|
||||||
req = req.Token(params.Username)
|
req = req.Token(params.Username)
|
||||||
}
|
}
|
||||||
if params.ID.Valid() {
|
if params.ID != "" {
|
||||||
req = req.AuthID(params.ID.String())
|
req = req.AuthID(params.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
auths, err := req.Execute()
|
auths, err := req.Execute()
|
||||||
@ -388,8 +388,8 @@ func (c Client) printV1Tokens(params *v1PrintOpts) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getAuthReqID(ctx context.Context, params *AuthLookupParams) (id string, err error) {
|
func (c Client) getAuthReqID(ctx context.Context, params *AuthLookupParams) (id string, err error) {
|
||||||
if params.ID.Valid() {
|
if params.ID != "" {
|
||||||
id = params.ID.String()
|
id = params.ID
|
||||||
} else {
|
} else {
|
||||||
var auths api.Authorizations
|
var auths api.Authorizations
|
||||||
auths, err = c.LegacyAuthorizationsApi.GetLegacyAuthorizations(ctx).Token(params.Username).Execute()
|
auths, err = c.LegacyAuthorizationsApi.GetLegacyAuthorizations(ctx).Token(params.Username).Execute()
|
||||||
@ -401,7 +401,3 @@ func (c Client) getAuthReqID(ctx context.Context, params *AuthLookupParams) (id
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) getOrgID(ctx context.Context, params clients.OrgParams) (string, error) {
|
|
||||||
return c.GetOrgIdI(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
|
||||||
}
|
|
||||||
|
@ -29,18 +29,18 @@ type ListParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) List(ctx context.Context, params *ListParams) error {
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return clients.ErrMustSpecifyOrg
|
return clients.ErrMustSpecifyOrg
|
||||||
}
|
}
|
||||||
|
|
||||||
req := c.GetDBRPs(ctx)
|
req := c.GetDBRPs(ctx)
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" {
|
if params.OrgID == "" && params.OrgName == "" {
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
req = req.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,36 +83,18 @@ type CreateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
orgId, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
|
||||||
return clients.ErrMustSpecifyOrg
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
reqBody := api.DBRPCreate{
|
reqBody := api.DBRPCreate{
|
||||||
|
OrgID: &orgId,
|
||||||
BucketID: params.BucketID,
|
BucketID: params.BucketID,
|
||||||
Database: params.DB,
|
Database: params.DB,
|
||||||
RetentionPolicy: params.RP,
|
RetentionPolicy: params.RP,
|
||||||
}
|
}
|
||||||
|
|
||||||
// For compatibility with the cloud API for creating a DBRP, an org ID must be
|
|
||||||
// provided. The ID will be obtained based on the org name if an
|
|
||||||
// org name is provided but no ID is.
|
|
||||||
if params.OrgID.Valid() {
|
|
||||||
reqBody.OrgID = api.PtrString(params.OrgID.String())
|
|
||||||
} else {
|
|
||||||
orgName := params.OrgName
|
|
||||||
if orgName == "" {
|
|
||||||
orgName = c.ActiveConfig.Org
|
|
||||||
}
|
|
||||||
res, err := c.GetOrgs(ctx).Org(orgName).Execute()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to look up ID for org %q: %w", orgName, err)
|
|
||||||
}
|
|
||||||
if len(res.GetOrgs()) == 0 {
|
|
||||||
return fmt.Errorf("no org found with name %q", orgName)
|
|
||||||
}
|
|
||||||
reqBody.OrgID = api.PtrString(res.GetOrgs()[0].GetId())
|
|
||||||
}
|
|
||||||
|
|
||||||
dbrp, err := c.PostDBRP(ctx).DBRPCreate(reqBody).Execute()
|
dbrp, err := c.PostDBRP(ctx).DBRPCreate(reqBody).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create dbrp for bucket %q: %w", params.BucketID, err)
|
return fmt.Errorf("failed to create dbrp for bucket %q: %w", params.BucketID, err)
|
||||||
@ -131,7 +113,7 @@ type UpdateParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return clients.ErrMustSpecifyOrg
|
return clients.ErrMustSpecifyOrg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,13 +126,13 @@ func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := c.PatchDBRPID(ctx, params.ID)
|
req := c.PatchDBRPID(ctx, params.ID)
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
req = req.OrgID(params.OrgID.String())
|
req = req.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
req = req.Org(params.OrgName)
|
req = req.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" {
|
if params.OrgID == "" && params.OrgName == "" {
|
||||||
req = req.Org(c.ActiveConfig.Org)
|
req = req.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +153,7 @@ type DeleteParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Delete(ctx context.Context, params *DeleteParams) error {
|
func (c Client) Delete(ctx context.Context, params *DeleteParams) error {
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
|
||||||
return clients.ErrMustSpecifyOrg
|
return clients.ErrMustSpecifyOrg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,15 +164,15 @@ func (c Client) Delete(ctx context.Context, params *DeleteParams) error {
|
|||||||
|
|
||||||
// The org name or ID must be set on requests for OSS because of how the OSS
|
// The org name or ID must be set on requests for OSS because of how the OSS
|
||||||
// authorization mechanism currently works.
|
// authorization mechanism currently works.
|
||||||
if params.OrgID.Valid() {
|
if params.OrgID != "" {
|
||||||
getReq = getReq.OrgID(params.OrgID.String())
|
getReq = getReq.OrgID(params.OrgID)
|
||||||
deleteReq = deleteReq.OrgID(params.OrgID.String())
|
deleteReq = deleteReq.OrgID(params.OrgID)
|
||||||
}
|
}
|
||||||
if params.OrgName != "" {
|
if params.OrgName != "" {
|
||||||
getReq = getReq.Org(params.OrgName)
|
getReq = getReq.Org(params.OrgName)
|
||||||
deleteReq = deleteReq.Org(params.OrgName)
|
deleteReq = deleteReq.Org(params.OrgName)
|
||||||
}
|
}
|
||||||
if !params.OrgID.Valid() && params.OrgName == "" {
|
if params.OrgID == "" && params.OrgName == "" {
|
||||||
getReq = getReq.Org(c.ActiveConfig.Org)
|
getReq = getReq.Org(c.ActiveConfig.Org)
|
||||||
deleteReq = deleteReq.Org(c.ActiveConfig.Org)
|
deleteReq = deleteReq.Org(c.ActiveConfig.Org)
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,11 @@ import (
|
|||||||
v1dbrps "github.com/influxdata/influx-cli/v2/clients/v1_dbrps"
|
v1dbrps "github.com/influxdata/influx-cli/v2/clients/v1_dbrps"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/mock"
|
"github.com/influxdata/influx-cli/v2/internal/mock"
|
||||||
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
"github.com/influxdata/influx-cli/v2/internal/testutils"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
id1, _ = influxid.IDFromString("1111111111111111")
|
id1 = "1111111111111111"
|
||||||
errApiTest = errors.New("api error for testing")
|
errApiTest = errors.New("api error for testing")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,11 +33,8 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Params struct {
|
type Params struct {
|
||||||
BucketID string
|
clients.OrgBucketParams
|
||||||
BucketName string
|
Precision api.WritePrecision
|
||||||
OrgID string
|
|
||||||
OrgName string
|
|
||||||
Precision api.WritePrecision
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrWriteCanceled = errors.New("write canceled")
|
var ErrWriteCanceled = errors.New("write canceled")
|
||||||
|
@ -66,8 +66,10 @@ func TestWriteByIDs(t *testing.T) {
|
|||||||
mockBatcher := lineBatcher{}
|
mockBatcher := lineBatcher{}
|
||||||
|
|
||||||
params := write.Params{
|
params := write.Params{
|
||||||
OrgID: "12345",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
BucketID: "98765",
|
OrgParams: clients.OrgParams{OrgID: "12345"},
|
||||||
|
BucketParams: clients.BucketParams{BucketID: "98765"},
|
||||||
|
},
|
||||||
Precision: api.WRITEPRECISION_S,
|
Precision: api.WRITEPRECISION_S,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +120,11 @@ func TestWriteByNames(t *testing.T) {
|
|||||||
mockBatcher := lineBatcher{}
|
mockBatcher := lineBatcher{}
|
||||||
|
|
||||||
params := write.Params{
|
params := write.Params{
|
||||||
OrgName: "my-org",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
BucketName: "my-bucket",
|
OrgParams: clients.OrgParams{OrgName: "my-org"},
|
||||||
Precision: api.WRITEPRECISION_US,
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
},
|
||||||
|
Precision: api.WRITEPRECISION_US,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
@ -170,8 +174,10 @@ func TestWriteOrgFromConfig(t *testing.T) {
|
|||||||
mockBatcher := lineBatcher{}
|
mockBatcher := lineBatcher{}
|
||||||
|
|
||||||
params := write.Params{
|
params := write.Params{
|
||||||
BucketName: "my-bucket",
|
OrgBucketParams: clients.OrgBucketParams{
|
||||||
Precision: api.WRITEPRECISION_US,
|
BucketParams: clients.BucketParams{BucketName: "my-bucket"},
|
||||||
|
},
|
||||||
|
Precision: api.WRITEPRECISION_US,
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultOrg := "my-default-org"
|
defaultOrg := "my-default-org"
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/clients/apply"
|
"github.com/influxdata/influx-cli/v2/clients/apply"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/template"
|
"github.com/influxdata/influx-cli/v2/pkg/template"
|
||||||
@ -16,8 +17,7 @@ import (
|
|||||||
|
|
||||||
func newApplyCmd() cli.Command {
|
func newApplyCmd() cli.Command {
|
||||||
var params struct {
|
var params struct {
|
||||||
orgId string
|
orgParams clients.OrgParams
|
||||||
orgName string
|
|
||||||
stackId string
|
stackId string
|
||||||
inPaths cli.StringSlice
|
inPaths cli.StringSlice
|
||||||
inUrls cli.StringSlice
|
inUrls cli.StringSlice
|
||||||
@ -89,19 +89,7 @@ For more templates created by the community, see
|
|||||||
https://github.com/influxdata/community-templates.
|
https://github.com/influxdata/community-templates.
|
||||||
`,
|
`,
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.orgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.orgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.orgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "stack-id",
|
Name: "stack-id",
|
||||||
Usage: "Stack ID to associate with template application",
|
Usage: "Stack ID to associate with template application",
|
||||||
@ -167,8 +155,7 @@ https://github.com/influxdata/community-templates.
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
parsedParams := apply.Params{
|
parsedParams := apply.Params{
|
||||||
OrgId: params.orgId,
|
OrgParams: params.orgParams,
|
||||||
OrgName: params.orgName,
|
|
||||||
StackId: params.stackId,
|
StackId: params.stackId,
|
||||||
Recursive: params.recursive,
|
Recursive: params.recursive,
|
||||||
Quiet: params.quiet,
|
Quiet: params.quiet,
|
||||||
|
@ -26,19 +26,7 @@ Examples:
|
|||||||
ArgsUsage: "path",
|
ArgsUsage: "path",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
append(commonFlagsNoPrint(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.Org,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket-id",
|
Name: "bucket-id",
|
||||||
Usage: "The ID of the bucket to backup",
|
Usage: "The ID of the bucket to backup",
|
||||||
@ -47,7 +35,7 @@ Examples:
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket, b",
|
Name: "bucket, b",
|
||||||
Usage: "The name of the bucket to backup",
|
Usage: "The name of the bucket to backup",
|
||||||
Destination: ¶ms.Bucket,
|
Destination: ¶ms.BucketName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.GenericFlag{
|
||||||
Name: "compression",
|
Name: "compression",
|
||||||
|
@ -30,7 +30,7 @@ func newBucketCreateCmd() cli.Command {
|
|||||||
Usage: "Create bucket",
|
Usage: "Create bucket",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "New bucket name",
|
Usage: "New bucket name",
|
||||||
@ -53,18 +53,6 @@ func newBucketCreateCmd() cli.Command {
|
|||||||
Usage: "Shard group duration used internally by the storage engine",
|
Usage: "Shard group duration used internally by the storage engine",
|
||||||
Destination: ¶ms.ShardGroupDuration,
|
Destination: ¶ms.ShardGroupDuration,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.GenericFlag{
|
&cli.GenericFlag{
|
||||||
Name: "schema-type",
|
Name: "schema-type",
|
||||||
Usage: "The schema type (implicit, explicit)",
|
Usage: "The schema type (implicit, explicit)",
|
||||||
@ -90,28 +78,16 @@ func newBucketDeleteCmd() cli.Command {
|
|||||||
Usage: "Delete bucket",
|
Usage: "Delete bucket",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The bucket ID, required if name isn't provided",
|
Usage: "The bucket ID, required if name isn't provided",
|
||||||
Destination: ¶ms.ID,
|
Destination: ¶ms.BucketID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "The bucket name, org or org-id will be required by choosing this",
|
Usage: "The bucket name, org or org-id will be required by choosing this",
|
||||||
Destination: ¶ms.Name,
|
Destination: ¶ms.BucketName,
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
@ -134,28 +110,16 @@ func newBucketListCmd() cli.Command {
|
|||||||
Aliases: []string{"find", "ls"},
|
Aliases: []string{"find", "ls"},
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The bucket ID, required if name isn't provided",
|
Usage: "The bucket ID, required if name isn't provided",
|
||||||
Destination: ¶ms.ID,
|
Destination: ¶ms.BucketID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "The bucket name, org or org-id will be required by choosing this",
|
Usage: "The bucket name, org or org-id will be required by choosing this",
|
||||||
Destination: ¶ms.Name,
|
Destination: ¶ms.BucketName,
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "limit",
|
Name: "limit",
|
||||||
@ -199,13 +163,13 @@ func newBucketUpdateCmd() cli.Command {
|
|||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "New name to set on the bucket",
|
Usage: "New name to set on the bucket",
|
||||||
EnvVar: "INFLUX_BUCKET_NAME",
|
EnvVar: "INFLUX_BUCKET_NAME",
|
||||||
Destination: ¶ms.Name,
|
Destination: ¶ms.BucketName,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The bucket ID",
|
Usage: "The bucket ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Destination: ¶ms.ID,
|
Destination: ¶ms.BucketID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "description, d",
|
Name: "description, d",
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/influxdata/influx-cli/v2/clients"
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
"github.com/influxdata/influx-cli/v2/clients/bucket_schema"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ func newBucketSchemaCreateCmd() cli.Command {
|
|||||||
func newBucketSchemaUpdateCmd() cli.Command {
|
func newBucketSchemaUpdateCmd() cli.Command {
|
||||||
var params struct {
|
var params struct {
|
||||||
clients.OrgBucketParams
|
clients.OrgBucketParams
|
||||||
ID influxid.ID
|
ID string
|
||||||
Name string
|
Name string
|
||||||
ColumnsFile string
|
ColumnsFile string
|
||||||
ColumnsFormat bucket_schema.ColumnsFormat
|
ColumnsFormat bucket_schema.ColumnsFormat
|
||||||
@ -116,10 +115,10 @@ func newBucketSchemaUpdateCmd() cli.Command {
|
|||||||
commonFlags(),
|
commonFlags(),
|
||||||
append(
|
append(
|
||||||
getOrgBucketFlags(¶ms.OrgBucketParams),
|
getOrgBucketFlags(¶ms.OrgBucketParams),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id",
|
Name: "id",
|
||||||
Usage: "ID of the measurement",
|
Usage: "ID of the measurement",
|
||||||
Value: ¶ms.ID,
|
Destination: ¶ms.ID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name",
|
Name: "name",
|
||||||
@ -147,7 +146,7 @@ func newBucketSchemaUpdateCmd() cli.Command {
|
|||||||
return getBucketSchemaClient(ctx).
|
return getBucketSchemaClient(ctx).
|
||||||
Update(getContext(ctx), bucket_schema.UpdateParams{
|
Update(getContext(ctx), bucket_schema.UpdateParams{
|
||||||
OrgBucketParams: params.OrgBucketParams,
|
OrgBucketParams: params.OrgBucketParams,
|
||||||
ID: params.ID.String(),
|
ID: params.ID,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Stdin: os.Stdin,
|
Stdin: os.Stdin,
|
||||||
ColumnsFile: params.ColumnsFile,
|
ColumnsFile: params.ColumnsFile,
|
||||||
|
@ -14,11 +14,11 @@ func newDeleteCmd() cli.Command {
|
|||||||
Description: "Delete points from InfluxDB, by specify start, end time and a sql like predicate string",
|
Description: "Delete points from InfluxDB, by specify start, end time and a sql like predicate string",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
commonFlagsNoPrint(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "org-id",
|
Name: "org-id",
|
||||||
Usage: "The ID of the organization that owns the bucket",
|
Usage: "The ID of the organization that owns the bucket",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.OrgID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "org, o",
|
Name: "org, o",
|
||||||
@ -26,11 +26,11 @@ func newDeleteCmd() cli.Command {
|
|||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.OrgName,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket-id",
|
Name: "bucket-id",
|
||||||
Usage: "The ID of the bucket to delete from",
|
Usage: "The ID of the bucket to delete from",
|
||||||
EnvVar: "INFLUX_BUCKET_ID",
|
EnvVar: "INFLUX_BUCKET_ID",
|
||||||
Value: ¶ms.BucketID,
|
Destination: ¶ms.BucketID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket, b",
|
Name: "bucket, b",
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/clients/export"
|
"github.com/influxdata/influx-cli/v2/clients/export"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/template"
|
"github.com/influxdata/influx-cli/v2/pkg/template"
|
||||||
@ -252,10 +253,9 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/`,
|
|||||||
|
|
||||||
func newExportAllCmd() cli.Command {
|
func newExportAllCmd() cli.Command {
|
||||||
var params struct {
|
var params struct {
|
||||||
out string
|
orgParams clients.OrgParams
|
||||||
orgId string
|
out string
|
||||||
orgName string
|
filters cli.StringSlice
|
||||||
filters cli.StringSlice
|
|
||||||
}
|
}
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "all",
|
Name: "all",
|
||||||
@ -293,19 +293,7 @@ and
|
|||||||
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/all/
|
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/all/
|
||||||
`,
|
`,
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
append(commonFlagsNoPrint(), getOrgFlags(¶ms.orgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.orgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.orgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "file, f",
|
Name: "file, f",
|
||||||
Usage: "Output file for created template; defaults to std out if no file provided; the extension of provided file (.yml/.json) will dictate encoding",
|
Usage: "Output file for created template; defaults to std out if no file provided; the extension of provided file (.yml/.json) will dictate encoding",
|
||||||
@ -320,8 +308,7 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/export/all/
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
parsedParams := export.AllParams{
|
parsedParams := export.AllParams{
|
||||||
OrgId: params.orgId,
|
OrgParams: params.orgParams,
|
||||||
OrgName: params.orgName,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, filter := range params.filters.Value() {
|
for _, filter := range params.filters.Value() {
|
||||||
|
@ -302,11 +302,11 @@ func commonFlags() []cli.Flag {
|
|||||||
// the flags to the given params container.
|
// the flags to the given params container.
|
||||||
func getOrgFlags(params *clients.OrgParams) []cli.Flag {
|
func getOrgFlags(params *clients.OrgParams) []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "org-id",
|
Name: "org-id",
|
||||||
Usage: "The ID of the organization",
|
Usage: "The ID of the organization",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.OrgID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "org, o",
|
Name: "org, o",
|
||||||
@ -321,10 +321,10 @@ func getOrgFlags(params *clients.OrgParams) []cli.Flag {
|
|||||||
// the flags to the given params container.
|
// the flags to the given params container.
|
||||||
func getBucketFlags(params *clients.BucketParams) []cli.Flag {
|
func getBucketFlags(params *clients.BucketParams) []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket-id, i",
|
Name: "bucket-id, i",
|
||||||
Usage: "The bucket ID, required if name isn't provided",
|
Usage: "The bucket ID, required if name isn't provided",
|
||||||
Value: ¶ms.BucketID,
|
Destination: ¶ms.BucketID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket, n",
|
Name: "bucket, n",
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/influxdata/influx-cli/v2/clients/org"
|
"github.com/influxdata/influx-cli/v2/clients/org"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,18 +53,18 @@ func newOrgCreateCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newOrgDeleteCmd() cli.Command {
|
func newOrgDeleteCmd() cli.Command {
|
||||||
var id influxid.ID
|
var id string
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "Delete organization",
|
Usage: "Delete organization",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: &id,
|
Destination: &id,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
@ -91,13 +90,13 @@ func newOrgListCmd() cli.Command {
|
|||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "The organization name",
|
Usage: "The organization name",
|
||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.Name,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.ID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
@ -118,18 +117,18 @@ func newOrgUpdateCmd() cli.Command {
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Value: ¶ms.ID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "New name to set on the organization",
|
Usage: "New name to set on the organization",
|
||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.Name,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "description, d",
|
Name: "description, d",
|
||||||
|
@ -27,11 +27,11 @@ func newOrgMembersAddCmd() cli.Command {
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
commonFlagsNoPrint(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "member, m",
|
Name: "member, m",
|
||||||
Usage: "The member ID",
|
Usage: "The member ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Value: ¶ms.MemberId,
|
Destination: ¶ms.MemberId,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
@ -39,11 +39,11 @@ func newOrgMembersAddCmd() cli.Command {
|
|||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.OrgName,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.OrgID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
@ -71,11 +71,11 @@ func newOrgMembersListCmd() cli.Command {
|
|||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.OrgName,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.OrgID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
@ -97,11 +97,11 @@ func newOrgMembersRemoveCmd() cli.Command {
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
commonFlagsNoPrint(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "member, m",
|
Name: "member, m",
|
||||||
Usage: "The member ID",
|
Usage: "The member ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Value: ¶ms.MemberId,
|
Destination: ¶ms.MemberId,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
@ -109,11 +109,11 @@ func newOrgMembersRemoveCmd() cli.Command {
|
|||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.OrgName,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The organization ID",
|
Usage: "The organization ID",
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
Value: ¶ms.OrgID,
|
Destination: ¶ms.OrgID,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
|
@ -19,19 +19,7 @@ func newQueryCmd() cli.Command {
|
|||||||
ArgsUsage: "[query literal or '-' for stdin]",
|
ArgsUsage: "[query literal or '-' for stdin]",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
append(commonFlagsNoPrint(), getOrgFlags(&orgParams)...),
|
||||||
&cli.GenericFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Value: &orgParams.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: &orgParams.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "file, f",
|
Name: "file, f",
|
||||||
Usage: "Path to Flux query file",
|
Usage: "Path to Flux query file",
|
||||||
|
@ -28,7 +28,7 @@ func newRemoteCreateCmd() cli.Command {
|
|||||||
Usage: "Create a new remote connection",
|
Usage: "Create a new remote connection",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "Name for the new remote connection",
|
Usage: "Name for the new remote connection",
|
||||||
@ -40,18 +40,6 @@ func newRemoteCreateCmd() cli.Command {
|
|||||||
Usage: "Description for the new remote connection",
|
Usage: "Description for the new remote connection",
|
||||||
Destination: ¶ms.Description,
|
Destination: ¶ms.Description,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the local organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "remote-url",
|
Name: "remote-url",
|
||||||
Usage: "The url for the remote database",
|
Usage: "The url for the remote database",
|
||||||
|
@ -39,7 +39,7 @@ Examples:
|
|||||||
Name: "org, o",
|
Name: "org, o",
|
||||||
Usage: "The original name of the organization to restore",
|
Usage: "The original name of the organization to restore",
|
||||||
EnvVar: "INFLUX_ORG",
|
EnvVar: "INFLUX_ORG",
|
||||||
Destination: ¶ms.Org,
|
Destination: ¶ms.OrgName,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket-id",
|
Name: "bucket-id",
|
||||||
@ -49,7 +49,7 @@ Examples:
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket, b",
|
Name: "bucket, b",
|
||||||
Usage: "The original name of the bucket to restore",
|
Usage: "The original name of the bucket to restore",
|
||||||
Destination: ¶ms.Bucket,
|
Destination: ¶ms.BucketName,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "new-bucket",
|
Name: "new-bucket",
|
||||||
@ -68,19 +68,19 @@ Examples:
|
|||||||
}
|
}
|
||||||
params.Path = ctx.Args().Get(0)
|
params.Path = ctx.Args().Get(0)
|
||||||
|
|
||||||
if params.Full && (params.Org != "" ||
|
if params.Full && (params.OrgName != "" ||
|
||||||
params.OrgID != "" ||
|
params.OrgID != "" ||
|
||||||
params.Bucket != "" ||
|
params.BucketName != "" ||
|
||||||
params.BucketID != "" ||
|
params.BucketID != "" ||
|
||||||
params.NewOrgName != "" ||
|
params.NewOrgName != "" ||
|
||||||
params.NewBucketName != "") {
|
params.NewBucketName != "") {
|
||||||
return errors.New("--full restore cannot be limited to a single org or bucket")
|
return errors.New("--full restore cannot be limited to a single org or bucket")
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.NewOrgName != "" && params.OrgID == "" && params.Org == "" {
|
if params.NewOrgName != "" && params.OrgID == "" && params.OrgName == "" {
|
||||||
return errors.New("--org-id or --org must be set to use --new-org")
|
return errors.New("--org-id or --org must be set to use --new-org")
|
||||||
}
|
}
|
||||||
if params.NewBucketName != "" && params.BucketID == "" && params.Bucket == "" {
|
if params.NewBucketName != "" && params.BucketID == "" && params.BucketName == "" {
|
||||||
return errors.New("--bucket-id or --bucket must be set to use --new-bucket")
|
return errors.New("--bucket-id or --bucket must be set to use --new-bucket")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,19 +38,7 @@ For information about Stacks and how they integrate with InfluxDB templates, see
|
|||||||
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/stacks/`,
|
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/stacks/`,
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "stack-id",
|
Name: "stack-id",
|
||||||
Usage: "Stack ID to filter by",
|
Usage: "Stack ID to filter by",
|
||||||
@ -103,19 +91,7 @@ and
|
|||||||
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/stacks/init/`,
|
https://docs.influxdata.com/influxdb/latest/reference/cli/influx/stacks/init/`,
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "stack-name, n",
|
Name: "stack-name, n",
|
||||||
Usage: "Name given to created stack",
|
Usage: "Name given to created stack",
|
||||||
@ -152,19 +128,7 @@ func newStacksRemoveCmd() cli.Command {
|
|||||||
Usage: "Remove a stack(s) and all associated resources",
|
Usage: "Remove a stack(s) and all associated resources",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true)),
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.OrgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "stack-id",
|
Name: "stack-id",
|
||||||
Usage: "Stack IDs to be removed",
|
Usage: "Stack IDs to be removed",
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/influxdata/influx-cli/v2/clients"
|
||||||
"github.com/influxdata/influx-cli/v2/clients/template"
|
"github.com/influxdata/influx-cli/v2/clients/template"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
pkgtmpl "github.com/influxdata/influx-cli/v2/pkg/template"
|
pkgtmpl "github.com/influxdata/influx-cli/v2/pkg/template"
|
||||||
@ -13,28 +14,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type templateParams struct {
|
type templateParams struct {
|
||||||
orgId string
|
orgParams clients.OrgParams
|
||||||
orgName string
|
files cli.StringSlice
|
||||||
files cli.StringSlice
|
urls cli.StringSlice
|
||||||
urls cli.StringSlice
|
recurse bool
|
||||||
recurse bool
|
encoding pkgtmpl.Encoding
|
||||||
encoding pkgtmpl.Encoding
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateFlags(params *templateParams) []cli.Flag {
|
func templateFlags(params *templateParams) []cli.Flag {
|
||||||
return []cli.Flag{
|
return append(getOrgFlags(¶ms.orgParams), []cli.Flag{
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: ¶ms.orgId,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.orgName,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "file, f",
|
Name: "file, f",
|
||||||
Usage: "Path to template file; Supports file paths or (deprecated) HTTP(S) URLs",
|
Usage: "Path to template file; Supports file paths or (deprecated) HTTP(S) URLs",
|
||||||
@ -56,7 +44,7 @@ func templateFlags(params *templateParams) []cli.Flag {
|
|||||||
Usage: "Encoding for the input stream. If a file is provided will gather encoding type from file extension. If extension provided will override.",
|
Usage: "Encoding for the input stream. If a file is provided will gather encoding type from file extension. If extension provided will override.",
|
||||||
Value: ¶ms.encoding,
|
Value: ¶ms.encoding,
|
||||||
},
|
},
|
||||||
}
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (params templateParams) parseSources() ([]pkgtmpl.Source, error) {
|
func (params templateParams) parseSources() ([]pkgtmpl.Source, error) {
|
||||||
@ -121,8 +109,7 @@ func newTemplateCmd() cli.Command {
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
parsedParams := template.SummarizeParams{
|
parsedParams := template.SummarizeParams{
|
||||||
OrgId: params.orgId,
|
OrgParams: params.orgParams,
|
||||||
OrgName: params.orgName,
|
|
||||||
RenderTableColors: !params.noColor,
|
RenderTableColors: !params.noColor,
|
||||||
RenderTableBorders: !params.noTableBorders,
|
RenderTableBorders: !params.noTableBorders,
|
||||||
}
|
}
|
||||||
@ -152,8 +139,7 @@ func newTemplateValidateCmd() cli.Command {
|
|||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Action: func(ctx *cli.Context) error {
|
Action: func(ctx *cli.Context) error {
|
||||||
parsedParams := template.ValidateParams{
|
parsedParams := template.ValidateParams{
|
||||||
OrgId: params.orgId,
|
OrgParams: params.orgParams,
|
||||||
OrgName: params.orgName,
|
|
||||||
}
|
}
|
||||||
sources, err := params.parseSources()
|
sources, err := params.parseSources()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/influxdata/influx-cli/v2/clients/user"
|
"github.com/influxdata/influx-cli/v2/clients/user"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,19 +27,7 @@ func newUserCreateCmd() cli.Command {
|
|||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "Create user",
|
Usage: "Create user",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
||||||
&cli.GenericFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Value: ¶ms.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: ¶ms.OrgName,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "The user name",
|
Usage: "The user name",
|
||||||
@ -68,17 +55,17 @@ func newUserCreateCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newUserDeleteCmd() cli.Command {
|
func newUserDeleteCmd() cli.Command {
|
||||||
var id influxid.ID
|
var id string
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "Delete user",
|
Usage: "Delete user",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The user ID",
|
Usage: "The user ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Value: &id,
|
Destination: &id,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
@ -97,10 +84,10 @@ func newUserListCmd() cli.Command {
|
|||||||
Usage: "List users",
|
Usage: "List users",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The user ID",
|
Usage: "The user ID",
|
||||||
Value: ¶ms.Id,
|
Destination: ¶ms.Id,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
@ -117,16 +104,16 @@ func newUserListCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newUserUpdateCmd() cli.Command {
|
func newUserUpdateCmd() cli.Command {
|
||||||
var params user.UpdateParmas
|
var params user.UpdateParams
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "update",
|
Name: "update",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The user ID",
|
Usage: "The user ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Value: ¶ms.Id,
|
Destination: ¶ms.Id,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
@ -148,10 +135,10 @@ func newUserSetPasswordCmd() cli.Command {
|
|||||||
Name: "password",
|
Name: "password",
|
||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlagsNoPrint(),
|
commonFlagsNoPrint(),
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id, i",
|
Name: "id, i",
|
||||||
Usage: "The user ID",
|
Usage: "The user ID",
|
||||||
Value: ¶ms.Id,
|
Destination: ¶ms.Id,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
|
@ -10,10 +10,10 @@ import (
|
|||||||
// and can specify to require one but not both.
|
// and can specify to require one but not both.
|
||||||
func getAuthLookupFlags(params *v1_auth.AuthLookupParams) []cli.Flag {
|
func getAuthLookupFlags(params *v1_auth.AuthLookupParams) []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.GenericFlag{
|
&cli.StringFlag{
|
||||||
Name: "id",
|
Name: "id",
|
||||||
Usage: "The ID of the authorization",
|
Usage: "The ID of the authorization",
|
||||||
Value: ¶ms.ID,
|
Destination: ¶ms.ID,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "username",
|
Name: "username",
|
||||||
|
@ -64,7 +64,7 @@ func (p *writeParams) makeErrorFile() (*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *writeParams) Flags() []cli.Flag {
|
func (p *writeParams) Flags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return append(getOrgFlags(&p.OrgParams), []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "bucket-id",
|
Name: "bucket-id",
|
||||||
Usage: "The ID of destination bucket",
|
Usage: "The ID of destination bucket",
|
||||||
@ -77,18 +77,6 @@ func (p *writeParams) Flags() []cli.Flag {
|
|||||||
EnvVar: "INFLUX_BUCKET_NAME",
|
EnvVar: "INFLUX_BUCKET_NAME",
|
||||||
Destination: &p.BucketName,
|
Destination: &p.BucketName,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org-id",
|
|
||||||
Usage: "The ID of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG_ID",
|
|
||||||
Destination: &p.OrgID,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "org, o",
|
|
||||||
Usage: "The name of the organization",
|
|
||||||
EnvVar: "INFLUX_ORG",
|
|
||||||
Destination: &p.OrgName,
|
|
||||||
},
|
|
||||||
&cli.GenericFlag{
|
&cli.GenericFlag{
|
||||||
Name: "precision, p",
|
Name: "precision, p",
|
||||||
Usage: "Precision of the timestamps of the lines",
|
Usage: "Precision of the timestamps of the lines",
|
||||||
@ -167,7 +155,7 @@ func (p *writeParams) Flags() []cli.Flag {
|
|||||||
Usage: "Input compression, either 'none' or 'gzip'",
|
Usage: "Input compression, either 'none' or 'gzip'",
|
||||||
Value: &p.Compression,
|
Value: &p.Compression,
|
||||||
},
|
},
|
||||||
}
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWriteCmd() cli.Command {
|
func newWriteCmd() cli.Command {
|
||||||
|
@ -18,115 +18,34 @@ var (
|
|||||||
ErrInvalidIDLength = errors.New("id must have a length of 16 bytes")
|
ErrInvalidIDLength = errors.New("id must have a length of 16 bytes")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ID is a unique identifier.
|
// Validate ensures that a passed string has a valid ID syntax.
|
||||||
//
|
// Checks that the string is of length 16, and is a valid hex-encoded uint.
|
||||||
// Its zero value is not a valid ID.
|
func Validate(id string) error {
|
||||||
type ID uint64
|
_, err := Decode(id)
|
||||||
|
return err
|
||||||
// IDFromString creates an ID from a given string.
|
|
||||||
//
|
|
||||||
// It errors if the input string does not match a valid ID.
|
|
||||||
func IDFromString(str string) (ID, error) {
|
|
||||||
var id ID
|
|
||||||
err := id.DecodeFromString(str)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return id, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustIDFromString is like IDFromString but panics if
|
// Encode converts a uint64 to a hex-encoded byte-slice-string.
|
||||||
// s is not a valid base-16 identifier.
|
func Encode(id uint64) string {
|
||||||
func MustIDFromString(s string) ID {
|
|
||||||
id, err := IDFromString(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode parses b as a hex-encoded byte-slice-string.
|
|
||||||
//
|
|
||||||
// It errors if the input byte slice does not have the correct length
|
|
||||||
// or if it contains all zeros.
|
|
||||||
func (i *ID) Decode(b []byte) error {
|
|
||||||
if len(b) != IDLength {
|
|
||||||
return ErrInvalidIDLength
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := strconv.ParseUint(string(b), 16, 64)
|
|
||||||
if err != nil {
|
|
||||||
return ErrInvalidID
|
|
||||||
}
|
|
||||||
|
|
||||||
if *i = ID(res); !i.Valid() {
|
|
||||||
return ErrInvalidID
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeFromString parses s as a hex-encoded string.
|
|
||||||
func (i *ID) DecodeFromString(s string) error {
|
|
||||||
return i.Decode([]byte(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode converts ID to a hex-encoded byte-slice-string.
|
|
||||||
//
|
|
||||||
// It errors if the receiving ID holds its zero value.
|
|
||||||
func (i ID) Encode() ([]byte, error) {
|
|
||||||
if !i.Valid() {
|
|
||||||
return nil, ErrInvalidID
|
|
||||||
}
|
|
||||||
|
|
||||||
b := make([]byte, hex.DecodedLen(IDLength))
|
b := make([]byte, hex.DecodedLen(IDLength))
|
||||||
binary.BigEndian.PutUint64(b, uint64(i))
|
binary.BigEndian.PutUint64(b, id)
|
||||||
|
|
||||||
dst := make([]byte, hex.EncodedLen(len(b)))
|
dst := make([]byte, hex.EncodedLen(len(b)))
|
||||||
hex.Encode(dst, b)
|
hex.Encode(dst, b)
|
||||||
return dst, nil
|
return string(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid checks whether the receiving ID is a valid one or not.
|
// Decode parses id as a hex-encoded byte-slice-string.
|
||||||
func (i ID) Valid() bool {
|
|
||||||
return i != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the ID as a hex encoded string.
|
|
||||||
//
|
//
|
||||||
// Returns an empty string in the case the ID is invalid.
|
// It errors if the input byte slice does not have the correct length
|
||||||
func (i ID) String() string {
|
// or if it contains all zeros.
|
||||||
enc, _ := i.Encode()
|
func Decode(id string) (uint64, error) {
|
||||||
return string(enc)
|
if len([]byte(id)) != 16 {
|
||||||
}
|
return 0, ErrInvalidIDLength
|
||||||
|
|
||||||
// GoString formats the ID the same as the String method.
|
|
||||||
// Without this, when using the %#v verb, an ID would be printed as a uint64,
|
|
||||||
// so you would see e.g. 0x2def021097c6000 instead of 02def021097c6000
|
|
||||||
// (note the leading 0x, which means the former doesn't show up in searches for the latter).
|
|
||||||
func (i ID) GoString() string {
|
|
||||||
return `"` + i.String() + `"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalText encodes i as text.
|
|
||||||
// Providing this method is a fallback for json.Marshal,
|
|
||||||
// with the added benefit that IDs encoded as map keys will be the expected string encoding,
|
|
||||||
// rather than the effective fmt.Sprintf("%d", i) that json.Marshal uses by default for integer types.
|
|
||||||
func (i ID) MarshalText() ([]byte, error) {
|
|
||||||
return i.Encode()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalText decodes i from a byte slice.
|
|
||||||
// Providing this method is also a fallback for json.Unmarshal,
|
|
||||||
// also relevant when IDs are used as map keys.
|
|
||||||
func (i *ID) UnmarshalText(b []byte) error {
|
|
||||||
return i.Decode(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *ID) Set(s string) error {
|
|
||||||
id, err := IDFromString(s)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
*i = id
|
res, err := strconv.ParseUint(id, 16, 64)
|
||||||
return nil
|
if err != nil || res == 0 {
|
||||||
|
return 0, ErrInvalidID
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
@ -2,222 +2,46 @@ package influxid_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
"github.com/influxdata/influx-cli/v2/pkg/influxid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIDFromString(t *testing.T) {
|
func TestDecode(t *testing.T) {
|
||||||
tests := []struct {
|
if _, err := influxid.Decode("020f755c3c082000"); err != nil {
|
||||||
name string
|
|
||||||
id string
|
|
||||||
want influxid.ID
|
|
||||||
wantErr bool
|
|
||||||
err string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Should be able to decode an all zeros ID",
|
|
||||||
id: "0000000000000000",
|
|
||||||
wantErr: true,
|
|
||||||
err: influxid.ErrInvalidID.Error(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Should be able to decode an all f ID",
|
|
||||||
id: "ffffffffffffffff",
|
|
||||||
want: influxid.MustIDFromString("ffffffffffffffff"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Should be able to decode an ID",
|
|
||||||
id: "020f755c3c082000",
|
|
||||||
want: influxid.MustIDFromString("020f755c3c082000"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Should not be able to decode a non hex ID",
|
|
||||||
id: "gggggggggggggggg",
|
|
||||||
wantErr: true,
|
|
||||||
err: influxid.ErrInvalidID.Error(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Should not be able to decode inputs with length less than 16 bytes",
|
|
||||||
id: "abc",
|
|
||||||
wantErr: true,
|
|
||||||
err: influxid.ErrInvalidIDLength.Error(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Should not be able to decode inputs with length greater than 16 bytes",
|
|
||||||
id: "abcdabcdabcdabcd0",
|
|
||||||
wantErr: true,
|
|
||||||
err: influxid.ErrInvalidIDLength.Error(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
got, err := influxid.IDFromString(tt.id)
|
|
||||||
|
|
||||||
// Check negative test cases
|
|
||||||
if (err != nil) && tt.wantErr {
|
|
||||||
if tt.err != err.Error() {
|
|
||||||
t.Errorf("IDFromString() errors out \"%s\", want \"%s\"", err, tt.err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check positive test cases
|
|
||||||
if !reflect.DeepEqual(got, tt.want) && !tt.wantErr {
|
|
||||||
t.Errorf("IDFromString() outputs %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecodeFromString(t *testing.T) {
|
|
||||||
var id influxid.ID
|
|
||||||
err := id.DecodeFromString("020f755c3c082000")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(err.Error())
|
t.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
want := []byte{48, 50, 48, 102, 55, 53, 53, 99, 51, 99, 48, 56, 50, 48, 48, 48}
|
|
||||||
got, _ := id.Encode()
|
|
||||||
if !bytes.Equal(want, got) {
|
|
||||||
t.Errorf("got %s not equal to wanted %s", string(got), string(want))
|
|
||||||
}
|
|
||||||
if id.String() != "020f755c3c082000" {
|
|
||||||
t.Errorf("expecting string representation to contain the right value")
|
|
||||||
}
|
|
||||||
if !id.Valid() {
|
|
||||||
t.Errorf("expecting ID to be a valid one")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncode(t *testing.T) {
|
func TestEncode(t *testing.T) {
|
||||||
var id influxid.ID
|
res, _ := influxid.Decode("5ca1ab1eba5eba11")
|
||||||
if _, err := id.Encode(); err == nil {
|
|
||||||
t.Errorf("encoding an invalid ID should not be possible")
|
|
||||||
}
|
|
||||||
|
|
||||||
id.DecodeFromString("5ca1ab1eba5eba11")
|
|
||||||
want := []byte{53, 99, 97, 49, 97, 98, 49, 101, 98, 97, 53, 101, 98, 97, 49, 49}
|
want := []byte{53, 99, 97, 49, 97, 98, 49, 101, 98, 97, 53, 101, 98, 97, 49, 49}
|
||||||
got, _ := id.Encode()
|
got := []byte(influxid.Encode(res))
|
||||||
if !bytes.Equal(want, got) {
|
if !bytes.Equal(want, got) {
|
||||||
t.Errorf("encoding error")
|
t.Errorf("encoding error")
|
||||||
}
|
}
|
||||||
if id.String() != "5ca1ab1eba5eba11" {
|
|
||||||
t.Errorf("expecting string representation to contain the right value")
|
|
||||||
}
|
|
||||||
if !id.Valid() {
|
|
||||||
t.Errorf("expecting ID to be a valid one")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeFromAllZeros(t *testing.T) {
|
func TestDecodeFromAllZeros(t *testing.T) {
|
||||||
var id influxid.ID
|
if _, err := influxid.Decode(string(make([]byte, influxid.IDLength))); err == nil {
|
||||||
err := id.Decode(make([]byte, influxid.IDLength))
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expecting all zeros ID to not be a valid ID")
|
t.Errorf("expecting all zeros ID to not be a valid ID")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeFromShorterString(t *testing.T) {
|
func TestDecodeFromShorterString(t *testing.T) {
|
||||||
var id influxid.ID
|
if _, err := influxid.Decode("020f75"); err == nil {
|
||||||
err := id.DecodeFromString("020f75")
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expecting shorter inputs to error")
|
t.Errorf("expecting shorter inputs to error")
|
||||||
}
|
}
|
||||||
if id.String() != "" {
|
|
||||||
t.Errorf("expecting invalid ID to be serialized into empty string")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeFromLongerString(t *testing.T) {
|
func TestDecodeFromLongerString(t *testing.T) {
|
||||||
var id influxid.ID
|
if _, err := influxid.Decode("020f755c3c082000aaa"); err == nil {
|
||||||
err := id.DecodeFromString("020f755c3c082000aaa")
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expecting shorter inputs to error")
|
t.Errorf("expecting shorter inputs to error")
|
||||||
}
|
}
|
||||||
if id.String() != "" {
|
|
||||||
t.Errorf("expecting invalid ID to be serialized into empty string")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeFromEmptyString(t *testing.T) {
|
func TestDecodeFromEmptyString(t *testing.T) {
|
||||||
var id influxid.ID
|
if _, err := influxid.Decode(""); err == nil {
|
||||||
err := id.DecodeFromString("")
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expecting empty inputs to error")
|
t.Errorf("expecting empty inputs to error")
|
||||||
}
|
}
|
||||||
if id.String() != "" {
|
|
||||||
t.Errorf("expecting invalid ID to be serialized into empty string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMarshalling(t *testing.T) {
|
|
||||||
var id0 influxid.ID
|
|
||||||
_, err := json.Marshal(id0)
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expecting empty ID to not be a valid one")
|
|
||||||
}
|
|
||||||
|
|
||||||
init := "ca55e77eca55e77e"
|
|
||||||
id1, err := influxid.IDFromString(init)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
serialized, err := json.Marshal(id1)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var id2 influxid.ID
|
|
||||||
json.Unmarshal(serialized, &id2)
|
|
||||||
|
|
||||||
bytes1, _ := id1.Encode()
|
|
||||||
bytes2, _ := id2.Encode()
|
|
||||||
|
|
||||||
if !bytes.Equal(bytes1, bytes2) {
|
|
||||||
t.Errorf("error marshalling/unmarshalling ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
// When used as a map key, IDs must use their string encoding.
|
|
||||||
// If you only implement json.Marshaller, they will be encoded with Go's default integer encoding.
|
|
||||||
b, err := json.Marshal(map[influxid.ID]int{0x1234: 5678})
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
const exp = `{"0000000000001234":5678}`
|
|
||||||
if string(b) != exp {
|
|
||||||
t.Errorf("expected map to json.Marshal as %s; got %s", exp, string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
var idMap map[influxid.ID]int
|
|
||||||
if err := json.Unmarshal(b, &idMap); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
if len(idMap) != 1 {
|
|
||||||
t.Errorf("expected length 1, got %d", len(idMap))
|
|
||||||
}
|
|
||||||
if idMap[0x1234] != 5678 {
|
|
||||||
t.Errorf("unmarshalled incorrectly; exp 0x1234:5678, got %v", idMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestID_GoString(t *testing.T) {
|
|
||||||
type idGoStringTester struct {
|
|
||||||
ID influxid.ID
|
|
||||||
}
|
|
||||||
var x idGoStringTester
|
|
||||||
|
|
||||||
const idString = "02def021097c6000"
|
|
||||||
if err := x.ID.DecodeFromString(idString); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sharpV := fmt.Sprintf("%#v", x)
|
|
||||||
want := `influxid_test.idGoStringTester{ID:"` + idString + `"}`
|
|
||||||
if sharpV != want {
|
|
||||||
t.Fatalf("bad GoString: got %q, want %q", sharpV, want)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if labels := summary.Labels; len(labels) > 0 {
|
if labels := summary.Labels; len(labels) > 0 {
|
||||||
printer := newPrinter("LABELS", []string{"Description", "Color"})
|
printer := newPrinter("LABELS", []string{"Description", "Color"})
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
id := influxid.ID(l.Id).String()
|
id := influxid.Encode(l.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if l.Properties.Description != nil {
|
if l.Properties.Description != nil {
|
||||||
desc = *l.Properties.Description
|
desc = *l.Properties.Description
|
||||||
@ -39,7 +39,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if buckets := summary.Buckets; len(buckets) > 0 {
|
if buckets := summary.Buckets; len(buckets) > 0 {
|
||||||
printer := newPrinter("BUCKETS", []string{"Retention", "Description", "Schema Type"})
|
printer := newPrinter("BUCKETS", []string{"Retention", "Description", "Schema Type"})
|
||||||
for _, b := range buckets {
|
for _, b := range buckets {
|
||||||
id := influxid.ID(b.Id).String()
|
id := influxid.Encode(b.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if b.Description != nil {
|
if b.Description != nil {
|
||||||
desc = *b.Description
|
desc = *b.Description
|
||||||
@ -61,7 +61,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if checks := summary.Checks; len(checks) > 0 {
|
if checks := summary.Checks; len(checks) > 0 {
|
||||||
printer := newPrinter("CHECKS", []string{"Description"})
|
printer := newPrinter("CHECKS", []string{"Description"})
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
id := influxid.ID(c.Id).String()
|
id := influxid.Encode(c.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if c.Description != nil {
|
if c.Description != nil {
|
||||||
desc = *c.Description
|
desc = *c.Description
|
||||||
@ -75,7 +75,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if dashboards := summary.Dashboards; len(dashboards) > 0 {
|
if dashboards := summary.Dashboards; len(dashboards) > 0 {
|
||||||
printer := newPrinter("DASHBOARDS", []string{"Description"})
|
printer := newPrinter("DASHBOARDS", []string{"Description"})
|
||||||
for _, d := range dashboards {
|
for _, d := range dashboards {
|
||||||
id := influxid.ID(d.Id).String()
|
id := influxid.Encode(d.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if d.Description != nil {
|
if d.Description != nil {
|
||||||
desc = *d.Description
|
desc = *d.Description
|
||||||
@ -89,7 +89,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if endpoints := summary.NotificationEndpoints; len(endpoints) > 0 {
|
if endpoints := summary.NotificationEndpoints; len(endpoints) > 0 {
|
||||||
printer := newPrinter("NOTIFICATION ENDPOINTS", []string{"Description", "Status"})
|
printer := newPrinter("NOTIFICATION ENDPOINTS", []string{"Description", "Status"})
|
||||||
for _, e := range endpoints {
|
for _, e := range endpoints {
|
||||||
id := influxid.ID(e.Id).String()
|
id := influxid.Encode(e.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if e.Description != nil {
|
if e.Description != nil {
|
||||||
desc = *e.Description
|
desc = *e.Description
|
||||||
@ -103,8 +103,8 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if rules := summary.NotificationRules; len(rules) > 0 {
|
if rules := summary.NotificationRules; len(rules) > 0 {
|
||||||
printer := newPrinter("NOTIFICATION RULES", []string{"Description", "Every", "Offset", "Endpoint Name", "Endpoint ID", "Endpoint Type"})
|
printer := newPrinter("NOTIFICATION RULES", []string{"Description", "Every", "Offset", "Endpoint Name", "Endpoint ID", "Endpoint Type"})
|
||||||
for _, r := range rules {
|
for _, r := range rules {
|
||||||
id := influxid.ID(r.Id).String()
|
id := influxid.Encode(r.Id)
|
||||||
eid := influxid.ID(r.EndpointID).String()
|
eid := influxid.Encode(r.EndpointID)
|
||||||
var desc string
|
var desc string
|
||||||
if r.Description != nil {
|
if r.Description != nil {
|
||||||
desc = *r.Description
|
desc = *r.Description
|
||||||
@ -118,7 +118,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if tasks := summary.Tasks; len(tasks) > 0 {
|
if tasks := summary.Tasks; len(tasks) > 0 {
|
||||||
printer := newPrinter("TASKS", []string{"Description", "Cycle"})
|
printer := newPrinter("TASKS", []string{"Description", "Cycle"})
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
id := influxid.ID(t.Id).String()
|
id := influxid.Encode(t.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if t.Description != nil {
|
if t.Description != nil {
|
||||||
desc = *t.Description
|
desc = *t.Description
|
||||||
@ -156,7 +156,7 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
if vars := summary.Variables; len(vars) > 0 {
|
if vars := summary.Variables; len(vars) > 0 {
|
||||||
printer := newPrinter("VARIABLES", []string{"Description", "Arg Type", "Arg Values"})
|
printer := newPrinter("VARIABLES", []string{"Description", "Arg Type", "Arg Values"})
|
||||||
for _, v := range vars {
|
for _, v := range vars {
|
||||||
id := influxid.ID(v.Id).String()
|
id := influxid.Encode(v.Id)
|
||||||
var desc string
|
var desc string
|
||||||
if v.Description != nil {
|
if v.Description != nil {
|
||||||
desc = *v.Description
|
desc = *v.Description
|
||||||
@ -176,8 +176,8 @@ func PrintSummary(summary api.TemplateSummaryResources, out io.Writer, useColor
|
|||||||
Title("LABEL ASSOCIATIONS").
|
Title("LABEL ASSOCIATIONS").
|
||||||
SetHeaders("Resource Type", "Resource Name", "Resource ID", "Label Name", "Label ID")
|
SetHeaders("Resource Type", "Resource Name", "Resource ID", "Label Name", "Label ID")
|
||||||
for _, m := range mappings {
|
for _, m := range mappings {
|
||||||
rid := influxid.ID(m.ResourceID).String()
|
rid := influxid.Encode(m.ResourceID)
|
||||||
lid := influxid.ID(m.LabelID).String()
|
lid := influxid.Encode(m.LabelID)
|
||||||
printer.Append([]string{m.ResourceType, m.ResourceName, rid, m.LabelName, lid})
|
printer.Append([]string{m.ResourceType, m.ResourceName, rid, m.LabelName, lid})
|
||||||
}
|
}
|
||||||
printer.Render()
|
printer.Render()
|
||||||
|
Reference in New Issue
Block a user