From cf472916df64c2ebee193c6f7f802b91bb4dc69a Mon Sep 17 00:00:00 2001 From: Deary Hudson Date: Tue, 10 Dec 2019 13:04:55 -0600 Subject: [PATCH] feat(cmd): bucket create accepts org name as flag adds: - `--org` or -`o` shorthand for the organization name enables the user to specify an organization name when creating a bucket. --- CHANGELOG.md | 1 + cmd/influx/bucket.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 373cc5dfb4b..e47773f1d78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [15836](https://github.com/influxdata/influxdb/pull/16077): Add stacked line layer option to graphs 1. [16094](https://github.com/influxdata/influxdb/pull/16094): Annotate log messages with trace ID, if available +1. [16187](https://github.com/influxdata/influxdb/pull/16187): Bucket create to accept an org name flag ### Bug Fixes diff --git a/cmd/influx/bucket.go b/cmd/influx/bucket.go index 0e1a66021e1..fe88af2e864 100644 --- a/cmd/influx/bucket.go +++ b/cmd/influx/bucket.go @@ -27,6 +27,7 @@ func bucketF(cmd *cobra.Command, args []string) { type BucketCreateFlags struct { name string orgID string + org string retention time.Duration } @@ -42,6 +43,7 @@ func init() { bucketCreateCmd.Flags().StringVarP(&bucketCreateFlags.name, "name", "n", "", "Name of bucket that will be created") bucketCreateCmd.Flags().DurationVarP(&bucketCreateFlags.retention, "retention", "r", 0, "Duration in nanoseconds data will live in bucket") bucketCreateCmd.Flags().StringVarP(&bucketCreateFlags.orgID, "org-id", "", "", "The ID of the organization that owns the bucket") + bucketCreateCmd.Flags().StringVarP(&bucketCreateFlags.org, "org", "o", "", "The org name") bucketCreateCmd.MarkFlagRequired("name") bucketCmd.AddCommand(bucketCreateCmd) @@ -63,8 +65,10 @@ func newBucketService(f Flags) (platform.BucketService, error) { } func bucketCreateF(cmd *cobra.Command, args []string) error { - if bucketCreateFlags.orgID == "" { - return fmt.Errorf("must specify org-id") + if bucketCreateFlags.orgID == "" && bucketCreateFlags.org == "" { + return fmt.Errorf("must specify org-id, or org name") + } else if bucketCreateFlags.orgID != "" && bucketCreateFlags.org != "" { + return fmt.Errorf("must specify org-id, or org name not both") } s, err := newBucketService(flags) @@ -83,6 +87,19 @@ func bucketCreateF(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to decode org id %q: %v", bucketCreateFlags.orgID, err) } b.OrgID = *id + } else if bucketCreateFlags.org != "" { + orgSvc, err := newOrganizationService(flags) + if err != nil { + return fmt.Errorf("failed to initialize organization service client: %v", err) + } + + filter := platform.OrganizationFilter{Name: &bucketCreateFlags.org} + org, err := orgSvc.FindOrganization(context.Background(), filter) + if err != nil { + return fmt.Errorf("%v", err) + } + + b.OrgID = org.ID } if err := s.CreateBucket(context.Background(), b); err != nil {