|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: Manage Multiple Accounts or Tenants |
| 4 | +tagline: |
| 5 | +--- |
| 6 | + |
| 7 | +You may find yourself in a situation where you need to switch between different |
| 8 | +accounts and/or tenants. The Agave CLI has a tool called `auth-switch` to help |
| 9 | +manage multiple configuration files. |
| 10 | + |
| 11 | + |
| 12 | +<br> |
| 13 | +#### List current API configuration |
| 14 | + |
| 15 | +API configurations are stored in json-formatted files in the `~/.agave/` |
| 16 | +directory. You can list and examine the contents of your configurations with |
| 17 | +simple Linux commands. If you have been following along with this user guide, |
| 18 | +you likely only have one configuration file called `current`: |
| 19 | +``` json |
| 20 | +% ls ~/.agave/ |
| 21 | +current |
| 22 | + |
| 23 | +% cat ~/.agave/current | jq |
| 24 | +{ |
| 25 | + "tenantid": "sd2e", |
| 26 | + "baseurl": "https://api.sd2e.org", |
| 27 | + "devurl": "", |
| 28 | + "apisecret": "4q5qBcWoTXi72f9QsaU8xyNuXtIP", |
| 29 | + "apikey": "0WKfV1TkjuoAr8s5RWOV0Y9QTv0Q", |
| 30 | + "username": "username", |
| 31 | + "access_token": "a249cc980b50dd541a82b1c55d0", |
| 32 | + "refresh_token": "97d84c757b01a68d0cc30b285a8", |
| 33 | + "created_at": "1530890375", |
| 34 | + "expires_in": "14400", |
| 35 | + "expires_at": "Fri Jul 6 14:19:35 CDT 2018" |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +Running the command `auth-switch` without any options will display a table of |
| 40 | +known API configurations, and in this case, it will make a copy of the |
| 41 | +configuration with a slightly different name:: |
| 42 | +``` |
| 43 | +% auth-switch |
| 44 | +| tenant | username | active | |
| 45 | +| ------ | -------- | ------ | |
| 46 | +| sd2e | username | true | |
| 47 | +
|
| 48 | +% ls ~/.agave/ |
| 49 | +current current#sd2e#username |
| 50 | +``` |
| 51 | + |
| 52 | +<br> |
| 53 | +#### Initialize with another tenant |
| 54 | + |
| 55 | +Now, in order to have multiple configurations to switch back and forth, we will |
| 56 | +set up a new API configuration to interact with the TACC Production tenant. A |
| 57 | +user may need to do this if they are working on multiple projects that both use |
| 58 | +the Agave API: |
| 59 | +``` |
| 60 | +# Initialize with the tenant |
| 61 | +% tenants-init -t tacc.prod |
| 62 | +
|
| 63 | +Your CLI is now configured to interact with APIs owned by 'tacc.prod'. |
| 64 | +Use 'clients-create' to set up a new API client or 'auth-tokens-create' to re-use an existing API key and secret. |
| 65 | +
|
| 66 | +# Create a new client for interacting with the tenant |
| 67 | +% clients-create -S |
| 68 | +The name of the client application : my_client |
| 69 | +API username : username |
| 70 | +API password: |
| 71 | +Successfully created client my_client |
| 72 | +
|
| 73 | +# Create a new authorization token |
| 74 | +% auth-tokens-create -S |
| 75 | +API password: |
| 76 | +Token for tacc.prod:username successfully refreshed and cached for 14400 seconds |
| 77 | +57a301c948a562cc810bb40d09a2c713 |
| 78 | +``` |
| 79 | + |
| 80 | +Behind the scenes, the contents of `~/.agave/current` have been replaced with |
| 81 | +a new configuration. The former SD2E configuration was stored in |
| 82 | +`~/.agave/current#sd2e#username`. |
| 83 | + |
| 84 | + |
| 85 | +<br> |
| 86 | +#### Switch between configurations |
| 87 | + |
| 88 | +Finally, use `auth-switch` one more time to switch from the TACC Production |
| 89 | +tenant back to the SD2E tenant: |
| 90 | +``` |
| 91 | +% auth-switch -t sd2e |
| 92 | +Active config now sd2e/username |
| 93 | +
|
| 94 | +% auth-switch |
| 95 | +| tenant | username | active | |
| 96 | +| ------ | -------- | ------ | |
| 97 | +| sd2e | username | true | |
| 98 | +| tacc.prod | username | false | |
| 99 | +
|
| 100 | +% ls ~/.agave/ |
| 101 | +current current#sd2e#username current#tacc.prod#username |
| 102 | +``` |
| 103 | + |
| 104 | +Switching back to the SD2E tenant has also triggered the creation of |
| 105 | +`current#tacc.prod#username`, so both tenants are backed up and the user can |
| 106 | +easily switch between them. Agave uses only the contents of `~/.agave/current` |
| 107 | +and ignores the other files. |
| 108 | + |
| 109 | + |
| 110 | +<br> |
| 111 | +#### Initialize with another username |
| 112 | + |
| 113 | +In this final example, we will initialize with a second username on the SD2E |
| 114 | +tenant. This situation may arise if you manage a community account, if you share |
| 115 | +a workstation with another user, or if you are pair programming with another |
| 116 | +user. *Having multiple API configurations on the same machine is acceptable, but |
| 117 | +please never share your TACC password with anyone.* |
| 118 | +``` |
| 119 | +# Authenticate as a new user |
| 120 | +% tenants-init -t sd2e |
| 121 | +% clients-create -S -u user2 |
| 122 | +% auth-tokens-create -S |
| 123 | +
|
| 124 | +# Switch to original user |
| 125 | +% auth-switch -t sd2e -u username |
| 126 | +
|
| 127 | +# List all configurations |
| 128 | +% auth-switch |
| 129 | +| tenant | username | active | |
| 130 | +| ------ | -------- | ------ | |
| 131 | +| sd2e | user2 | false | |
| 132 | +| sd2e | username | true | |
| 133 | +| tacc.prod | username | false | |
| 134 | +
|
| 135 | +% ls ~/.agave/ |
| 136 | +current current#sd2e#username |
| 137 | +current#sd2e#user2 current#tacc.prod#username |
| 138 | +``` |
| 139 | + |
| 140 | +Notice that since multiple credentials were available for the SD2E tenant, the |
| 141 | +username also had to be specified with `-u` on the command line. |
| 142 | + |
| 143 | +<br> |
| 144 | +*Tip: For more information, including how to automatically refresh the token on |
| 145 | +switching credentials, use '`auth-switch -h`'* |
| 146 | + |
| 147 | +--- |
| 148 | +Return to the [API Documentation Overview](../index.md) |
0 commit comments