Skip to content

Commit

Permalink
Merge pull request #50 from mmazur/add_config_env_var
Browse files Browse the repository at this point in the history
Add OCM_CONFIG env var support
  • Loading branch information
jhernand authored Jan 16, 2020
2 parents 4c23b79 + 8219a4a commit ebdc990
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
22 changes: 21 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebdc990

Please sign in to comment.