From aa6db48e9e615361644517dd7bb142eb4fef0b2e Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Thu, 16 Jan 2020 13:50:48 +0100 Subject: [PATCH 1/2] Add OCM_CONFIG env var support --- pkg/config/config.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5a5c53b1..81cbf687 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -117,12 +117,16 @@ func Remove() error { // Location returns the location of the configuration file. func Location() (path string, err error) { - home, err := homedir.Dir() - if err != nil { - return + if ocmconfig := os.Getenv("OCM_CONFIG"); ocmconfig != "" { + path = ocmconfig + } else { + home, err := homedir.Dir() + if err != nil { + return "", err + } + path = filepath.Join(home, ".ocm.json") } - path = filepath.Join(home, ".ocm.json") - return + return path, nil } // Armed checks if the configuration contains either credentials or tokens that haven't expired, so From 8219a4a181a9faa5c1a29e7455632b56e140cbd9 Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Thu, 16 Jan 2020 15:05:49 +0100 Subject: [PATCH 2/2] Add docs for OCM_CONFIG --- README.adoc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index f130de54..e09eb4e1 100644 --- a/README.adoc +++ b/README.adoc @@ -1,7 +1,7 @@ = OCM API Command Line Tools This project contains the `ocm` command line tool that simplifies the use -of the _OCM_ API available in `api.openshift.com`. +of the _OCM_ API available at `api.openshift.com`. == Installation @@ -74,6 +74,26 @@ $ ocm login \ NOTE: The `insecure` option disables verification of TLS certificates and host names, do not use it in production environments. +== Multiple Concurrent Logins with OCM_CONFIG + +An `.ocm.json` file stores login credentials for a single API gateway. +Using multiple gateways therefore requires having to log in and out a lot or the ability to utilize multiple config files. +The latter functionality is provided with the `OCM_CONFIG` environment variable. +If running `ocm login` was successfull in both cases, the `ocm whoami` commands will return different results: + +.... +$ OCM_CONFIG=$HOME/.ocm.json.prod ocm login --url=production --token=... +(…) +$ OCM_CONFIG=$HOME/.ocm.json.stg ocm login --url=staging --token=... +(…) +$ OCM_CONFIG=$HOME/.ocm.json.prod ocm whoami +(…) +$ OCM_CONFIG=$HOME/.ocm.json.stg ocm whoami +(…) +.... + +NOTE: Tokens for production and staging will differ. + == Obtaining Tokens If you need the _OpenID_ access token to use it with some other tool, you can