From 41c216bb6a9f85d0b2abc61b6ffef7a0e8862d51 Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Tue, 21 Apr 2020 09:51:09 -0700 Subject: [PATCH] feat(influx): extend CLI org type to support config orgs in global config --- CHANGELOG.md | 1 + cmd/influx/main.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff02c9152c9..019b67ef331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ 1. [17618](https://github.com/influxdata/influxdb/pull/17618): Add index for URM by user ID to improve lookup performance 1. [17751](https://github.com/influxdata/influxdb/pull/17751): Existing session expiration time is respected on session renewal +1. [17817](https://github.com/influxdata/influxdb/pull/17817): Make CLI respect env vars and flags in addition to the configs and extend support for config orgs to all commands ### UI Improvements diff --git a/cmd/influx/main.go b/cmd/influx/main.go index 9900b75163c..07ff2b6f37b 100644 --- a/cmd/influx/main.go +++ b/cmd/influx/main.go @@ -408,16 +408,25 @@ func (o *organization) getID(orgSVC influxdb.OrganizationService) (influxdb.ID, return 0, fmt.Errorf("invalid org ID provided: %s", err.Error()) } return *influxOrgID, nil - } else if o.name != "" { + } + + getOrgByName := func(name string) (influxdb.ID, error) { org, err := orgSVC.FindOrganization(context.Background(), influxdb.OrganizationFilter{ - Name: &o.name, + Name: &name, }) if err != nil { - return 0, fmt.Errorf("%v", err) + return 0, err } return org.ID, nil } - return 0, fmt.Errorf("failed to locate an organization id") + if o.name != "" { + return getOrgByName(o.name) + } + // last check is for the org set in the CLI config. This will be last in priority. + if flags.Org != "" { + return getOrgByName(flags.Org) + } + return 0, fmt.Errorf("failed to locate organization criteria") } func (o *organization) validOrgFlags(f *globalFlags) error {