switch-profile 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.1.2](https://github.com/nicolasdao/switch-profile/compare/v0.1.1...v0.1.2) (2022-05-14)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Multiple SSO profiles are not supported. It only uses one. ([b9d9d03](https://github.com/nicolasdao/switch-profile/commit/b9d9d03b4edfa048cc157376222378513138e257))
11
+
5
12
  ### [0.1.1](https://github.com/nicolasdao/switch-profile/compare/v0.1.0...v0.1.1) (2021-08-03)
6
13
 
7
14
 
package/README.md CHANGED
@@ -15,7 +15,26 @@ This utility also supports creating new AWS profiles, including SSO profiles as
15
15
  > - `AWS_SECRET_ACCESS_KEY`
16
16
  > - `AWS_SESSION_TOKEN`
17
17
 
18
- # Why using this utility?
18
+ # Table of contents
19
+
20
+ > * [Extra features](#extra-features)
21
+ > * [FAQ](#faq)
22
+ > - [Why using this utility?](#why-using-this-utility)
23
+ > - [How to create a new SSO profile?](#how-to-create-a-new-sso-profile)
24
+ > * [Troubleshooting](#troubleshooting)
25
+ > - [`invalid_grant: Invalid grant provided`](#invalid_grant-invalid-grant-provided)
26
+ > - [`Error: Fail to get credentials for profile ... Error loading SSO Token...`](#error-fail-to-get-credentials-for-profile--error-loading-sso-token)
27
+ > * [License](#license)
28
+
29
+ # Extra features
30
+
31
+ The `More options` supports the following:
32
+ - `Create profile`: Helps create both a standard or AWS SSO profile.
33
+ - `Delete profiles`: Helps cleaning one or many profiles.
34
+ - `Refresh default profile`: Helps refreshing the current default profile if it has expired (e.g., SSO profile). This option only appears when the default profile has expired.
35
+
36
+ # FAQ
37
+ ## Why using this utility?
19
38
 
20
39
  `switch-profile` was originally created to refresh short-lived AWS SSO profiles in the terminal and set them as default. Indeed, as of 2021, the only two ways to set up a short-lived SSO profile as default in the terminal are:
21
40
  - Manually paste the short-lived credentials in the terminal:
@@ -31,12 +50,22 @@ The issue with the first method is that you have to repeat it every hour, which
31
50
 
32
51
  `switch-profile` aims to solve those issues by making setting any profile as `default` trivial.
33
52
 
34
- # Extra features
53
+ ## How to create a new SSO profile?
35
54
 
36
- The `More options` supports the following:
37
- - `Create profile`: Helps create both a standard or AWS SSO profile.
38
- - `Delete profiles`: Helps cleaning one or many profiles.
39
- - `Refresh default profile`: Helps refreshing the current default profile if it has expired (e.g., SSO profile). This option only appears when the default profile has expired.
55
+ 1. `npx switch-profile`
56
+ 2. Select `More options`, then `Create profile`.
57
+ 3. Answer all the questions.
58
+
59
+ # Troubleshooting
60
+ ## `invalid_grant: Invalid grant provided`
61
+
62
+ If this error occurs during a [profile creation step](#how-to-create-a-new-sso-profile), this is most likely due to an incorrect SSO region. AWS SSO is region specific. This error occurs if an incorrect region is specified during the [profile creation step](#how-to-create-a-new-sso-profile).
63
+
64
+ ## `Error: Fail to get credentials for profile ... Error loading SSO Token...`
65
+
66
+ This is probably due to a recent deletion of the `~/.aws/sso/cache` folder. This folder keeps track of the SSO profiles created on the local machine. Unfortunately in this case, there is no other option but to recreate all the SSO profiles manually:
67
+ 1. Execute `npx switch-profile`
68
+ 2. Select `More options`, then `Delete profiles`.
40
69
 
41
70
  # License
42
71
 
package/index.js CHANGED
@@ -310,6 +310,7 @@ const setProfileToDefault = async (profileName, profileList, successMsg) => {
310
310
  if (credsErrors)
311
311
  return printAWSerrors([new Error(`Fail to get credentials for profile ${profile.name}`), ...credsErrors])
312
312
 
313
+ // console.log(profile)
313
314
  // console.log(creds)
314
315
 
315
316
  const [errors] = await updateDefaultProfile({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "switch-profile",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "bin": "index.js",
6
6
  "description": "NPX script that exposes terminal shortcut to easily switch between cloud configuration (aws, gcp).",
package/src/aws/index.js CHANGED
@@ -7,10 +7,10 @@ const fileHelper = require('../fileHelper')
7
7
  const regions = require('./regions')
8
8
 
9
9
  const SSO_GET_CREDS_TIMEOUT = 5*60*1000 // 5 minutes to complete the SSO login
10
- const AWS_CONFIG_FILE = join(homedir(), '.aws/config')
11
- const AWS_CREDS_FILE = join(homedir(), '.aws/credentials')
12
- const AWS_SSO_FOLDER = join(homedir(), '.aws/sso/cache/')
13
- const AWS_CLI_FOLDER = join(homedir(), '.aws/cli/cache/')
10
+ const AWS_CONFIG_FILE = join(homedir(), '.aws', 'config')
11
+ const AWS_CREDS_FILE = join(homedir(), '.aws', 'credentials')
12
+ const AWS_SSO_FOLDER = join(homedir(), '.aws', 'sso', 'cache')
13
+ const AWS_CLI_FOLDER = join(homedir(), '.aws', 'cli', 'cache')
14
14
  const DEFAULT_CONFIG =
15
15
  `[default]
16
16
  region = ap-southeast-1
@@ -189,14 +189,15 @@ const getSsoCredsFromCacheFile = (access_key_end, secret_key_end) => catchErrors
189
189
 
190
190
  for (let i=0;i<files.length;i++) {
191
191
  const _creds = await fileHelper.json.get(files[i])
192
+
192
193
  // Creds must be SSO
193
194
  if (!_creds || _creds.ProviderType != 'sso' || !_creds.Credentials)
194
195
  continue
195
196
 
196
197
  // Creds must still be valid for the next 2 minutes
197
198
  if (_creds.Credentials.Expiration && (Date.now() - 2*60*1000) < new Date(_creds.Credentials.Expiration).getTime()) {
198
- const credsMatch = _creds.Credentials.AccessKeyId||''.slice(-4) == access_key_end &&
199
- _creds.Credentials.SecretAccessKey||''.slice(-4) == secret_key_end
199
+ const credsMatch = (_creds.Credentials.AccessKeyId||'').slice(-4) == access_key_end &&
200
+ (_creds.Credentials.SecretAccessKey||'').slice(-4) == secret_key_end
200
201
 
201
202
  if (credsMatch)
202
203
  return {
@@ -238,6 +239,7 @@ const getSsoCredentials = profile => catchErrors((async () => {
238
239
  return null
239
240
 
240
241
  const [ssoCredsErrors, creds] = await getSsoCredsFromCacheFile(access_key_end, secret_key_end)
242
+
241
243
  if (ssoCredsErrors)
242
244
  throw wrapErrors(errMsg, ssoCredsErrors)
243
245
  return creds