Skip to content

Commit

Permalink
feat(cmd): bucket create accepts org name as flag
Browse files Browse the repository at this point in the history
adds:
- `--org` or -`o` shorthand for the organization name

enables the user to specify an organization name when creating a bucket.
  • Loading branch information
dearyhud committed Dec 10, 2019
1 parent d279680 commit cf47291
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 19 additions & 2 deletions cmd/influx/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func bucketF(cmd *cobra.Command, args []string) {
type BucketCreateFlags struct {
name string
orgID string
org string
retention time.Duration
}

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit cf47291

Please sign in to comment.