Skip to content

Commit

Permalink
fix(cmd): removes shorthand from --org-id
Browse files Browse the repository at this point in the history
- to ensure consistency across the cli the  shorthand is being given to
the  shorthand was used for both flags inconsistently, but now it only works for
  • Loading branch information
dearyhud committed Dec 10, 2019
1 parent 67a9ba3 commit 0e4f056
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/influx/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func bucketCreateF(cmd *cobra.Command, args []string) error {
}
b.OrgID = *id
} else if bucketCreateFlags.org != "" {
orgSvc, err := newOrganizationService(flags)
orgSvc, err := newOrganizationService()
if err != nil {
return fmt.Errorf("failed to initialize organization service client: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/influx/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ in the following ways:
inspectReportTSMCommand.Flags().BoolVarP(&inspectReportTSMFlags.detailed, "detailed", "", false, "emit series cardinality segmented by measurements, tag keys and fields. Warning, may take a while.")

inspectReportTSMCommand.Flags().StringVarP(&inspectReportTSMFlags.orgID, "org-id", "", "", "process only data belonging to organization ID.")
inspectReportTSMCommand.Flags().StringVarP(&inspectReportTSMFlags.orgID, "org", "o", "", "process only data belonging to organization ID.")
inspectReportTSMCommand.Flags().StringVarP(&inspectReportTSMFlags.bucketID, "bucket-id", "", "", "process only data belonging to bucket ID. Requires org flag to be set.")

dir, err := fs.InfluxDir()
Expand Down
32 changes: 27 additions & 5 deletions cmd/influx/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type cmdPkgBuilder struct {
hasTableBorders bool
meta pkger.Metadata
orgID string
org string
quiet bool

applyOpts struct {
Expand Down Expand Up @@ -95,8 +96,8 @@ func (b *cmdPkgBuilder) cmdPkgApply() *cobra.Command {
cmd.Flags().IntVarP(&b.applyReqLimit, "req-limit", "r", 0, "Request limit for applying a pkg, defaults to 5(recommended for OSS).")
cmd.Flags().StringVar(&b.applyOpts.force, "force", "", `TTY input, if package will have destructive changes, proceed if set "true".`)

cmd.Flags().StringVarP(&b.orgID, "org-id", "o", "", "The ID of the organization that owns the bucket")
cmd.MarkFlagRequired("org-id")
cmd.Flags().StringVarP(&b.orgID, "org-id", "", "", "The ID of the organization that owns the bucket")
cmd.Flags().StringVarP(&b.org, "org", "o", "", "The name of the organization that owns the bucket")

cmd.Flags().BoolVarP(&b.hasColor, "color", "c", true, "Enable color in output, defaults true")
cmd.Flags().BoolVar(&b.hasTableBorders, "table-borders", true, "Enable table borders, defaults true")
Expand All @@ -108,11 +109,32 @@ func (b *cmdPkgBuilder) cmdPkgApply() *cobra.Command {

func (b *cmdPkgBuilder) pkgApplyRunEFn() func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) (e error) {
if b.orgID == "" && b.org == "" {
return fmt.Errorf("must specify org-id, or org name")
} else if b.orgID != "" && b.org != "" {
return fmt.Errorf("must specify org-id, or org name not both")
}
color.NoColor = !b.hasColor
var influxOrgID *influxdb.ID

influxOrgID, err := influxdb.IDFromString(b.orgID)
if err != nil {
return fmt.Errorf("invalid org ID provided: %s", err.Error())
if b.orgID != "" {
var err error
influxOrgID, err = influxdb.IDFromString(b.orgID)
if err != nil {
return fmt.Errorf("invalid org ID provided: %s", err.Error())
}
} else if b.org != "" {
orgSvc, err := newOrganizationService()
if err != nil {
return fmt.Errorf("failed to initialize organization service client: %v", err)
}

filter := influxdb.OrganizationFilter{Name: &b.org}
org, err := orgSvc.FindOrganization(context.Background(), filter)
if err != nil {
return fmt.Errorf("%v", err)
}
influxOrgID = &org.ID
}

svc, err := b.svcFn(flags.httpClientOpts(), pkger.WithApplyReqLimit(b.applyReqLimit))
Expand Down
9 changes: 7 additions & 2 deletions cmd/influx/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
RunE: wrapCheckSetup(taskCreateF),
}

taskCreateCmd.Flags().StringVarP(&taskCreateFlags.org, "org", "", "", "organization name")
taskCreateCmd.Flags().StringVarP(&taskCreateFlags.org, "org", "o", "", "organization name")
taskCreateCmd.Flags().StringVarP(&taskCreateFlags.orgID, "org-id", "", "", "id of the organization that owns the task")
taskCreateCmd.MarkFlagRequired("flux")

Expand Down Expand Up @@ -155,14 +155,19 @@ func init() {

taskFindCmd.Flags().StringVarP(&taskFindFlags.id, "id", "i", "", "task ID")
taskFindCmd.Flags().StringVarP(&taskFindFlags.user, "user-id", "n", "", "task owner ID")
taskFindCmd.Flags().StringVarP(&taskFindFlags.org, "org", "", "", "task organization name")
taskFindCmd.Flags().StringVarP(&taskFindFlags.org, "org", "o", "", "task organization name")
taskFindCmd.Flags().StringVarP(&taskFindFlags.orgID, "org-id", "", "", "task organization ID")
taskFindCmd.Flags().IntVarP(&taskFindFlags.limit, "limit", "", platform.TaskDefaultPageSize, "the number of tasks to find")

taskCmd.AddCommand(taskFindCmd)
}

func taskFindF(cmd *cobra.Command, args []string) error {
if taskFindFlags.orgID == "" && taskFindFlags.org == "" {
return fmt.Errorf("must specify org-id, or org name")
} else if taskFindFlags.orgID != "" && taskFindFlags.org != "" {
return fmt.Errorf("must specify org-id, or org name not both")
}
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Expand Down
30 changes: 28 additions & 2 deletions cmd/influx/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"errors"
"fmt"
"os"

platform "github.com/influxdata/influxdb"
Expand Down Expand Up @@ -113,6 +114,7 @@ var userCreateFlags struct {
name string
password string
orgID string
org string
}

func userCreateCmd() *cobra.Command {
Expand All @@ -125,12 +127,19 @@ func userCreateCmd() *cobra.Command {
cmd.Flags().StringVarP(&userCreateFlags.name, "name", "n", "", "The user name (required)")
cmd.MarkFlagRequired("name")
cmd.Flags().StringVarP(&userCreateFlags.password, "password", "p", "", "The user password")
cmd.Flags().StringVarP(&userCreateFlags.orgID, "org-id", "o", "", "The organization id the user belongs too. Is required if password provided.")
cmd.Flags().StringVarP(&userCreateFlags.orgID, "org-id", "", "", "The organization id the user belongs to. Is required if password provided.")
cmd.Flags().StringVarP(&userCreateFlags.org, "org", "o", "", "The organization name the user belongs to. Is required if password provided.")

return cmd
}

func userCreateF(cmd *cobra.Command, args []string) error {
if userCreateFlags.orgID == "" && userCreateFlags.org == "" {
return errors.New("must specify org-id, or org name")
} else if userCreateFlags.orgID != "" && userCreateFlags.org != "" {
return errors.New("must specify org-id, or org name not both")
}

s, err := newUserService()
if err != nil {
return err
Expand Down Expand Up @@ -161,7 +170,24 @@ func userCreateF(cmd *cobra.Command, args []string) error {
return nil
}

orgIDStr := userCreateFlags.orgID
var orgIDStr string

if userCreateFlags.orgID != "" {
orgIDStr = userCreateFlags.orgID
} else if userCreateFlags.org != "" {
orgSvc, err := newOrganizationService()
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)
}

orgIDStr = org.ID.GoString()
}
pass := userCreateFlags.password
if orgIDStr == "" && pass == "" {
return writeOutput([]string{"ID", "Name"}, user.ID.String(), user.Name)
Expand Down

0 comments on commit 0e4f056

Please sign in to comment.