ag-awsauth 0.0.248 → 0.0.250

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.
@@ -14,14 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.updateAwsCredentials = exports.getAwsCredentials = void 0;
16
16
  const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader");
17
- //@ts-ignore
18
- const getCredentialsFilepath_1 = require("@aws-sdk/shared-ini-file-loader/dist-cjs/getCredentialsFilepath");
19
17
  const log_1 = require("ag-common/dist/common/helpers/log");
20
18
  const fs_1 = __importDefault(require("fs"));
21
19
  const ini_1 = require("ini");
20
+ const getCredentialsFilepath_1 = require("./getCredentialsFilepath");
22
21
  const getAwsCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
23
22
  const config = yield (0, shared_ini_file_loader_1.loadSharedConfigFiles)();
24
23
  const creds = config.credentialsFile;
24
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
25
25
  if (!creds.default) {
26
26
  creds.default = {};
27
27
  }
@@ -33,7 +33,7 @@ exports.closeBrowser = closeBrowser;
33
33
  const launchBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
34
34
  const opt = {
35
35
  defaultViewport: { height: 1000, width: 500 },
36
- headless: (__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose) ? false : 'new',
36
+ headless: (__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose) ? false : true,
37
37
  ignoreHTTPSErrors: true,
38
38
  devtools: false,
39
39
  };
@@ -75,8 +75,8 @@ const goToPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
75
75
  });
76
76
  exports.goToPage = goToPage;
77
77
  function getMFA(p) {
78
- var _a;
79
78
  return __awaiter(this, void 0, void 0, function* () {
79
+ var _a;
80
80
  //go to browser site for auth
81
81
  (0, log_1.info)('start mfa');
82
82
  const page = yield (0, exports.goToPage)(p.verificationUriComplete);
@@ -187,8 +187,8 @@ function getMFA(p) {
187
187
  timeout: config_1.timeoutMs,
188
188
  });
189
189
  (0, log_1.warn)('mfa success');
190
- const cookies = yield (page === null || page === void 0 ? void 0 : page.cookies());
191
- const ssoAuthn = (_a = cookies === null || cookies === void 0 ? void 0 : cookies.find((c) => c.name === 'x-amz-sso_authn')) === null || _a === void 0 ? void 0 : _a.value;
190
+ const cookies = yield page.cookies();
191
+ const ssoAuthn = (_a = cookies.find((c) => c.name === 'x-amz-sso_authn')) === null || _a === void 0 ? void 0 : _a.value;
192
192
  if (!ssoAuthn) {
193
193
  throw new Error('no aws authn');
194
194
  }
@@ -0,0 +1,3 @@
1
+ export declare const getHomeDir: () => string;
2
+ export declare const ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
3
+ export declare const getCredentialsFilepath: () => string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCredentialsFilepath = exports.ENV_CREDENTIALS_PATH = exports.getHomeDir = void 0;
4
+ const os_1 = require("os");
5
+ const path_1 = require("path");
6
+ const homeDirCache = {};
7
+ const getHomeDirCacheKey = () => {
8
+ // geteuid is only available on POSIX platforms (i.e. not Windows or Android).
9
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10
+ if (process && process.geteuid) {
11
+ return `${process.geteuid()}`;
12
+ }
13
+ return 'DEFAULT';
14
+ };
15
+ const getHomeDir = () => {
16
+ const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${path_1.sep}` } = process.env;
17
+ if (HOME)
18
+ return HOME;
19
+ if (USERPROFILE)
20
+ return USERPROFILE;
21
+ if (HOMEPATH)
22
+ return `${HOMEDRIVE}${HOMEPATH}`;
23
+ const homeDirCacheKey = getHomeDirCacheKey();
24
+ if (!homeDirCache[homeDirCacheKey])
25
+ homeDirCache[homeDirCacheKey] = (0, os_1.homedir)();
26
+ return homeDirCache[homeDirCacheKey];
27
+ };
28
+ exports.getHomeDir = getHomeDir;
29
+ exports.ENV_CREDENTIALS_PATH = 'AWS_SHARED_CREDENTIALS_FILE';
30
+ const getCredentialsFilepath = () => process.env[exports.ENV_CREDENTIALS_PATH] ||
31
+ (0, path_1.join)((0, exports.getHomeDir)(), '.aws', 'credentials');
32
+ exports.getCredentialsFilepath = getCredentialsFilepath;
@@ -21,7 +21,7 @@ const config_1 = require("../config");
21
21
  const awsconfig_1 = require("./awsconfig");
22
22
  const sts_1 = require("./sts");
23
23
  const getAssumedRole = (p) => __awaiter(void 0, void 0, void 0, function* () {
24
- var _a, _b, _c, _d, _e;
24
+ var _a, _b, _c, _d;
25
25
  const sso = new client_sso_1.SSOClient({ region: config_1.identityCenterRegion });
26
26
  let accountId = p.accountId;
27
27
  if (!accountId) {
@@ -35,10 +35,10 @@ const getAssumedRole = (p) => __awaiter(void 0, void 0, void 0, function* () {
35
35
  accessToken: p.accessToken,
36
36
  accountId,
37
37
  }));
38
- const roles = (_e = (_d = (_c = rolesResult.roleList) === null || _c === void 0 ? void 0 : _c.map((r) => ({
38
+ const roles = (_d = (_c = rolesResult.roleList) === null || _c === void 0 ? void 0 : _c.map((r) => ({
39
39
  accountId: r.accountId || '',
40
40
  roleName: r.roleName || '',
41
- }))) === null || _d === void 0 ? void 0 : _d.filter((r) => r.accountId && r.roleName)) !== null && _e !== void 0 ? _e : [];
41
+ })).filter((r) => r.accountId && r.roleName)) !== null && _d !== void 0 ? _d : [];
42
42
  if (roles.length === 0) {
43
43
  throw new Error('no roles can be assumed');
44
44
  }
@@ -55,9 +55,9 @@ const getOIDCCredentialsFromAccessToken = (p) => __awaiter(void 0, void 0, void
55
55
  const ssoResp = yield sso.send(new client_sso_1.GetRoleCredentialsCommand(Object.assign(Object.assign({}, role), { accessToken: p.accessToken })));
56
56
  const rc = ssoResp.roleCredentials;
57
57
  if (!(rc === null || rc === void 0 ? void 0 : rc.accessKeyId) ||
58
- !(rc === null || rc === void 0 ? void 0 : rc.expiration) ||
59
- !(rc === null || rc === void 0 ? void 0 : rc.secretAccessKey) ||
60
- !(rc === null || rc === void 0 ? void 0 : rc.sessionToken)) {
58
+ !rc.expiration ||
59
+ !rc.secretAccessKey ||
60
+ !rc.sessionToken) {
61
61
  throw new Error('role creds undefined:' + JSON.stringify(rc, null, 2));
62
62
  }
63
63
  return Object.assign(Object.assign({}, p), { accessKeyId: rc.accessKeyId, secretAccessKey: rc.secretAccessKey, sessionToken: rc.sessionToken, region: config_1.identityCenterRegion });
@@ -66,7 +66,8 @@ exports.getOIDCCredentialsFromAccessToken = getOIDCCredentialsFromAccessToken;
66
66
  function appInstances(p) {
67
67
  return __awaiter(this, void 0, void 0, function* () {
68
68
  const ai = (yield (yield (0, node_fetch_1.default)(`https://portal.sso.${config_1.identityCenterRegion}.amazonaws.com/instance/appinstances`, { headers: { 'x-amz-sso_bearer_token': p.ssoAuthn } })).json());
69
- if (!(ai === null || ai === void 0 ? void 0 : ai.result)) {
69
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
70
+ if (!ai.result) {
70
71
  throw new Error('appinstance error' + JSON.stringify(ai, null, 2));
71
72
  }
72
73
  return ai.result.sort((a, b) => (a.name < b.name ? -1 : 1));
@@ -74,10 +75,10 @@ function appInstances(p) {
74
75
  }
75
76
  exports.appInstances = appInstances;
76
77
  function getSamlAssertion(p, instance) {
77
- var _a, _b;
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
+ var _a;
79
80
  const det = (yield (yield (0, node_fetch_1.default)(`https://portal.sso.${config_1.identityCenterRegion}.amazonaws.com/instance/appinstance/${instance.id}/profiles`, { headers: { 'x-amz-sso_bearer_token': p.ssoAuthn } })).json());
80
- const asserturl = (_b = (_a = det === null || det === void 0 ? void 0 : det.result) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.url;
81
+ const asserturl = (_a = det.result[0]) === null || _a === void 0 ? void 0 : _a.url;
81
82
  if (!asserturl) {
82
83
  throw new Error('assertion url cant be found');
83
84
  }
@@ -95,7 +96,7 @@ function getSamlAssertion(p, instance) {
95
96
  }
96
97
  exports.getSamlAssertion = getSamlAssertion;
97
98
  const tryExistingCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
98
- var _f;
99
+ var _e;
99
100
  const credraw = yield (0, awsconfig_1.getAwsCredentials)();
100
101
  if (!credraw.default.aws_access_token) {
101
102
  return undefined;
@@ -124,7 +125,8 @@ const tryExistingCredentials = () => __awaiter(void 0, void 0, void 0, function*
124
125
  catch (e) {
125
126
  //
126
127
  const em = e.toString();
127
- if ((_f = em.includes('is expired')) !== null && _f !== void 0 ? _f : em.includes('or invalid')) {
128
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
129
+ if ((_e = em.includes('is expired')) !== null && _e !== void 0 ? _e : em.includes('or invalid')) {
128
130
  (0, log_1.info)('access token or sso expired, need to wipe');
129
131
  }
130
132
  else {
@@ -15,8 +15,8 @@ const log_1 = require("ag-common/dist/common/helpers/log");
15
15
  const config_1 = require("../config");
16
16
  const sso_1 = require("./sso");
17
17
  function validateCredentials(credentials) {
18
- var _a, _b;
19
18
  return __awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
20
  const sts = new client_sts_1.STS({
21
21
  credentials,
22
22
  region: credentials.region,
@@ -24,7 +24,7 @@ function validateCredentials(credentials) {
24
24
  try {
25
25
  const stub = yield sts.getCallerIdentity({});
26
26
  yield (0, sso_1.appInstances)(credentials);
27
- if (((_b = (_a = stub === null || stub === void 0 ? void 0 : stub.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) !== null && _b !== void 0 ? _b : 500) < 400 &&
27
+ if (((_a = stub.$metadata.httpStatusCode) !== null && _a !== void 0 ? _a : 500) < 400 &&
28
28
  stub.Account &&
29
29
  stub.Arn) {
30
30
  (0, log_1.info)(`test cached credentials OK`);
@@ -43,8 +43,8 @@ function validateCredentials(credentials) {
43
43
  }
44
44
  exports.validateCredentials = validateCredentials;
45
45
  function getApplicationCreds(p) {
46
- var _a, _b, _c, _d;
47
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ var _a, _b;
48
48
  const sts = new client_sts_1.STS({
49
49
  credentials: p.originCreds,
50
50
  region: p.targetRegion,
@@ -59,9 +59,9 @@ function getApplicationCreds(p) {
59
59
  (0, log_1.error)('bad assume saml role', ret);
60
60
  throw new Error('bad assume saml role');
61
61
  }
62
- if (!((_b = ret === null || ret === void 0 ? void 0 : ret.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
63
- !((_c = ret === null || ret === void 0 ? void 0 : ret.Credentials) === null || _c === void 0 ? void 0 : _c.SecretAccessKey) ||
64
- !((_d = ret === null || ret === void 0 ? void 0 : ret.Credentials) === null || _d === void 0 ? void 0 : _d.SessionToken)) {
62
+ if (!((_b = ret.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
63
+ !ret.Credentials.SecretAccessKey ||
64
+ !ret.Credentials.SessionToken) {
65
65
  throw new Error('no creds');
66
66
  }
67
67
  return Object.assign(Object.assign({}, p.originCreds), { region: p.targetRegion, accessKeyId: ret.Credentials.AccessKeyId, secretAccessKey: ret.Credentials.SecretAccessKey, sessionToken: ret.Credentials.SessionToken });
@@ -69,8 +69,8 @@ function getApplicationCreds(p) {
69
69
  }
70
70
  exports.getApplicationCreds = getApplicationCreds;
71
71
  function directStsAssume(p) {
72
- var _a, _b, _c, _d;
73
72
  return __awaiter(this, void 0, void 0, function* () {
73
+ var _a, _b;
74
74
  const role = yield (0, sso_1.getAssumedRole)({
75
75
  accessToken: p.credentials.accessToken,
76
76
  accountId: p.metadata.AccountId,
@@ -87,9 +87,9 @@ function directStsAssume(p) {
87
87
  if (((_a = ar.$metadata.httpStatusCode) !== null && _a !== void 0 ? _a : 500) >= 400) {
88
88
  throw new Error('assume role error' + JSON.stringify(ar, null, 2));
89
89
  }
90
- if (!((_b = ar === null || ar === void 0 ? void 0 : ar.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
91
- !((_c = ar === null || ar === void 0 ? void 0 : ar.Credentials) === null || _c === void 0 ? void 0 : _c.SecretAccessKey) ||
92
- !((_d = ar === null || ar === void 0 ? void 0 : ar.Credentials) === null || _d === void 0 ? void 0 : _d.SessionToken)) {
90
+ if (!((_b = ar.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
91
+ !ar.Credentials.SecretAccessKey ||
92
+ !ar.Credentials.SessionToken) {
93
93
  throw new Error('no creds');
94
94
  }
95
95
  return Object.assign(Object.assign({}, p.credentials), { region: p.targetRegion, accessKeyId: ar.Credentials.AccessKeyId, secretAccessKey: ar.Credentials.SecretAccessKey, sessionToken: ar.Credentials.SessionToken });
@@ -38,7 +38,7 @@ const getUpstreamVersion = () => __awaiter(void 0, void 0, void 0, function* ()
38
38
  try {
39
39
  const r = yield (0, node_fetch_1.default)('https://api.github.com/repos/andreigec/ag-awsauth/tags', { headers: { Accept: 'application/json' } });
40
40
  const tags = (yield r.json());
41
- return (_a = tags === null || tags === void 0 ? void 0 : tags[0]) === null || _a === void 0 ? void 0 : _a.name;
41
+ return (_a = tags[0]) === null || _a === void 0 ? void 0 : _a.name;
42
42
  }
43
43
  catch (e) {
44
44
  (0, log_1.warn)(`error getting upstream version:` + e.message);
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ function main(args) {
67
67
  return;
68
68
  }
69
69
  let credentials = yield (0, sso_1.tryExistingCredentials)();
70
- if (!(credentials === null || credentials === void 0 ? void 0 : credentials.accessToken) || !(credentials === null || credentials === void 0 ? void 0 : credentials.ssoAuthn)) {
70
+ if (!(credentials === null || credentials === void 0 ? void 0 : credentials.accessToken) || !credentials.ssoAuthn) {
71
71
  (0, log_1.info)('no creds, get access token through manual sign in');
72
72
  credentials = yield (0, oidc_1.requestMFA)({
73
73
  identityCenterRegion: config_1.identityCenterRegion,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "andrei gec (andreigec@hotmail.com)",
6
6
  "license": "ISC",
7
7
  "private": false,
8
- "version": "0.0.248",
8
+ "version": "0.0.250",
9
9
  "preferGlobal": true,
10
10
  "scripts": {
11
11
  "format": "eslint --ext .ts,.tsx src --fix",
@@ -25,25 +25,25 @@
25
25
  "LICENSE.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@aws-sdk/client-sso": "3.507.0",
29
- "@aws-sdk/client-sso-oidc": "3.507.0",
30
- "@aws-sdk/client-sts": "3.507.0",
31
- "@aws-sdk/shared-ini-file-loader": "3.370.0",
32
- "ag-common": "0.0.619",
28
+ "@aws-sdk/client-sso": "3.590.0",
29
+ "@aws-sdk/client-sso-oidc": "3.590.0",
30
+ "@aws-sdk/client-sts": "3.590.0",
31
+ "@aws-sdk/shared-ini-file-loader": "^3.374.0",
32
+ "ag-common": "0.0.715",
33
33
  "cli-select": "1.1.2",
34
- "dotenv": "16.4.1",
34
+ "dotenv": "16.4.5",
35
35
  "envfile": "7.1.0",
36
- "eslint-config-e7npm": "0.0.81",
37
- "ini": "4.1.1",
36
+ "eslint-config-e7npm": "0.0.105",
37
+ "ini": "4.1.3",
38
38
  "node-fetch": "2.7.0",
39
- "puppeteer": "21.11.0",
39
+ "puppeteer": "22.10.0",
40
40
  "readline-sync": "1.4.10",
41
- "typescript": "5.3.3",
41
+ "typescript": "5.4.5",
42
42
  "yargs": "17.7.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/ini": "4.1.0",
46
- "@types/node": "20.11.16",
46
+ "@types/node": "20.14.1",
47
47
  "@types/node-fetch": "2.6.11",
48
48
  "@types/readline-sync": "1.4.8",
49
49
  "@types/yargs": "17.0.32"