ag-awsauth 0.0.7 → 0.0.10
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/bin/awsauth.js +0 -0
- package/dist/config.d.ts +12 -12
- package/dist/config.js +55 -55
- package/dist/helpers/awsconfig.d.ts +3 -3
- package/dist/helpers/awsconfig.js +52 -52
- package/dist/helpers/browser.d.ts +12 -12
- package/dist/helpers/browser.js +170 -167
- package/dist/helpers/input.d.ts +10 -10
- package/dist/helpers/input.js +95 -95
- package/dist/helpers/oidc.d.ts +5 -5
- package/dist/helpers/oidc.js +81 -81
- package/dist/helpers/sso.d.ts +21 -21
- package/dist/helpers/sso.js +143 -137
- package/dist/helpers/sts.d.ts +24 -24
- package/dist/helpers/sts.js +98 -98
- package/dist/index.d.ts +4 -4
- package/dist/index.js +115 -119
- package/dist/types.d.ts +55 -55
- package/dist/types.js +2 -2
- package/package.json +9 -10
- package/dist/direct.d.ts +0 -1
- package/dist/direct.js +0 -4
package/dist/index.js
CHANGED
|
@@ -1,119 +1,115 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.run = exports.main = exports.globalargs = void 0;
|
|
16
|
-
/* eslint-disable padding-line-between-statements */
|
|
17
|
-
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
18
|
-
const dotenv_1 = require("dotenv");
|
|
19
|
-
const fs_1 = __importDefault(require("fs"));
|
|
20
|
-
const path_1 = __importDefault(require("path"));
|
|
21
|
-
const config_1 = require("./config");
|
|
22
|
-
const awsconfig_1 = require("./helpers/awsconfig");
|
|
23
|
-
const input_1 = require("./helpers/input");
|
|
24
|
-
const oidc_1 = require("./helpers/oidc");
|
|
25
|
-
const sso_1 = require("./helpers/sso");
|
|
26
|
-
const sts_1 = require("./helpers/sts");
|
|
27
|
-
if (__dirname.endsWith('dist')) {
|
|
28
|
-
(0, config_1.setBasePath)(path_1.default.resolve(__dirname, '../'));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
(0, config_1.setBasePath)(__dirname);
|
|
32
|
-
}
|
|
33
|
-
(0, dotenv_1.config)({ path: config_1.basePath + '/.env' });
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(0,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(0, log_1.info)('
|
|
78
|
-
yield (0,
|
|
79
|
-
(0,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
(0,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
exports.run = run;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.run = exports.main = exports.globalargs = void 0;
|
|
16
|
+
/* eslint-disable padding-line-between-statements */
|
|
17
|
+
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
18
|
+
const dotenv_1 = require("dotenv");
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const config_1 = require("./config");
|
|
22
|
+
const awsconfig_1 = require("./helpers/awsconfig");
|
|
23
|
+
const input_1 = require("./helpers/input");
|
|
24
|
+
const oidc_1 = require("./helpers/oidc");
|
|
25
|
+
const sso_1 = require("./helpers/sso");
|
|
26
|
+
const sts_1 = require("./helpers/sts");
|
|
27
|
+
if (__dirname.endsWith('dist')) {
|
|
28
|
+
(0, config_1.setBasePath)(path_1.default.resolve(__dirname, '../'));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
(0, config_1.setBasePath)(__dirname);
|
|
32
|
+
}
|
|
33
|
+
(0, dotenv_1.config)({ path: config_1.basePath + '/.env' });
|
|
34
|
+
function main(args) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
exports.globalargs = args;
|
|
37
|
+
(0, log_1.SetLogLevel)(args.verbose ? 'TRACE' : 'WARN');
|
|
38
|
+
(0, log_1.SetLogShim)((...a1) => {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(...a1);
|
|
41
|
+
try {
|
|
42
|
+
fs_1.default.appendFileSync(config_1.logPath, JSON.stringify(a1, null, 2));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
//
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (args.config) {
|
|
49
|
+
(0, log_1.info)('running config');
|
|
50
|
+
(0, config_1.runConfig)();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (args.wipe) {
|
|
54
|
+
(0, log_1.info)('wiping args');
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
yield (0, awsconfig_1.updateAwsCredentials)(undefined);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!(0, config_1.validateConfig)()) {
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
61
|
+
console.error('please run config (-c)');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let credentials = yield (0, sso_1.tryExistingCredentials)();
|
|
65
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.accessToken) || !(credentials === null || credentials === void 0 ? void 0 : credentials.ssoAuthn)) {
|
|
66
|
+
(0, log_1.info)('no creds, get access token through manual sign in');
|
|
67
|
+
credentials = yield (0, oidc_1.requestMFA)({
|
|
68
|
+
identityCenterRegion: config_1.identityCenterRegion,
|
|
69
|
+
ssoStartUrl: config_1.ssoStartUrl,
|
|
70
|
+
});
|
|
71
|
+
(0, log_1.info)('get oidc creds');
|
|
72
|
+
credentials = yield (0, sso_1.getOIDCCredentialsFromAccessToken)(credentials);
|
|
73
|
+
}
|
|
74
|
+
//
|
|
75
|
+
(0, log_1.info)('save aws creds to file');
|
|
76
|
+
yield (0, awsconfig_1.updateAwsCredentials)(credentials);
|
|
77
|
+
(0, log_1.info)('get app instances and display');
|
|
78
|
+
const instances = yield (0, sso_1.appInstances)(credentials);
|
|
79
|
+
const instance = yield (0, input_1.chooseAppInstance)(instances, args);
|
|
80
|
+
let debugRole = '';
|
|
81
|
+
if (instance.searchMetadata) {
|
|
82
|
+
(0, log_1.info)('account is native aws, directly connecting');
|
|
83
|
+
credentials = yield (0, sts_1.directStsAssume)({
|
|
84
|
+
credentials,
|
|
85
|
+
targetRegion: config_1.targetRegion,
|
|
86
|
+
metadata: instance.searchMetadata,
|
|
87
|
+
});
|
|
88
|
+
debugRole = instance.searchMetadata.AccountId;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
(0, log_1.info)('account is external app, getting saml');
|
|
92
|
+
const samlDetails = yield (0, sso_1.getSamlAssertion)(credentials, instance);
|
|
93
|
+
credentials = yield (0, sts_1.getApplicationCreds)(Object.assign(Object.assign({}, samlDetails), { originCreds: credentials, targetRegion: config_1.targetRegion }));
|
|
94
|
+
debugRole = samlDetails.roleArn;
|
|
95
|
+
}
|
|
96
|
+
yield (0, awsconfig_1.updateAwsCredentials)(credentials);
|
|
97
|
+
(0, log_1.warn)(`successfully authed into ${debugRole}`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.main = main;
|
|
101
|
+
function run() {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
const args = yield (0, input_1.readArguments)();
|
|
105
|
+
yield main(args);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
(0, log_1.error)('error:' + e);
|
|
109
|
+
if (e === null || e === void 0 ? void 0 : e.toString) {
|
|
110
|
+
(0, log_1.error)('error:' + e.toString());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
exports.run = run;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
export interface IAwsCreds {
|
|
2
|
-
accessKeyId: string;
|
|
3
|
-
secretAccessKey: string;
|
|
4
|
-
sessionToken: string;
|
|
5
|
-
region: string;
|
|
6
|
-
accessToken: string;
|
|
7
|
-
ssoAuthn: string;
|
|
8
|
-
}
|
|
9
|
-
export interface IAwsCredsRaw {
|
|
10
|
-
region: string;
|
|
11
|
-
aws_access_key_id: string;
|
|
12
|
-
aws_secret_access_key: string;
|
|
13
|
-
aws_session_token: string;
|
|
14
|
-
aws_access_token: string;
|
|
15
|
-
aws_sso_authn: string;
|
|
16
|
-
aws_application_id: string;
|
|
17
|
-
}
|
|
18
|
-
export interface IAppInstances {
|
|
19
|
-
result: IAppInstance[];
|
|
20
|
-
}
|
|
21
|
-
export interface IAppInstance {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
description: string;
|
|
25
|
-
applicationId: string;
|
|
26
|
-
applicationName: string;
|
|
27
|
-
icon: string;
|
|
28
|
-
searchMetadata?: SearchMetadata;
|
|
29
|
-
}
|
|
30
|
-
export interface SearchMetadata {
|
|
31
|
-
AccountId: string;
|
|
32
|
-
AccountName: string;
|
|
33
|
-
AccountEmail: string;
|
|
34
|
-
}
|
|
35
|
-
export interface IAppInstanceDetails {
|
|
36
|
-
result: IAppInstanceDetailsResult[];
|
|
37
|
-
}
|
|
38
|
-
export interface IAppInstanceDetailsResult {
|
|
39
|
-
id: string;
|
|
40
|
-
name: string;
|
|
41
|
-
description: string;
|
|
42
|
-
url: string;
|
|
43
|
-
protocol: string;
|
|
44
|
-
}
|
|
45
|
-
export interface ISamlAssertion {
|
|
46
|
-
encodedResponse: string;
|
|
47
|
-
destination: string;
|
|
48
|
-
prettyPrintedXml: string;
|
|
49
|
-
}
|
|
50
|
-
export interface IApplicationArgs {
|
|
51
|
-
applicationfilter?: string;
|
|
52
|
-
verbose: boolean;
|
|
53
|
-
wipe: boolean;
|
|
54
|
-
config: boolean;
|
|
55
|
-
}
|
|
1
|
+
export interface IAwsCreds {
|
|
2
|
+
accessKeyId: string;
|
|
3
|
+
secretAccessKey: string;
|
|
4
|
+
sessionToken: string;
|
|
5
|
+
region: string;
|
|
6
|
+
accessToken: string;
|
|
7
|
+
ssoAuthn: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAwsCredsRaw {
|
|
10
|
+
region: string;
|
|
11
|
+
aws_access_key_id: string;
|
|
12
|
+
aws_secret_access_key: string;
|
|
13
|
+
aws_session_token: string;
|
|
14
|
+
aws_access_token: string;
|
|
15
|
+
aws_sso_authn: string;
|
|
16
|
+
aws_application_id: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IAppInstances {
|
|
19
|
+
result: IAppInstance[];
|
|
20
|
+
}
|
|
21
|
+
export interface IAppInstance {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
applicationId: string;
|
|
26
|
+
applicationName: string;
|
|
27
|
+
icon: string;
|
|
28
|
+
searchMetadata?: SearchMetadata;
|
|
29
|
+
}
|
|
30
|
+
export interface SearchMetadata {
|
|
31
|
+
AccountId: string;
|
|
32
|
+
AccountName: string;
|
|
33
|
+
AccountEmail: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IAppInstanceDetails {
|
|
36
|
+
result: IAppInstanceDetailsResult[];
|
|
37
|
+
}
|
|
38
|
+
export interface IAppInstanceDetailsResult {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
url: string;
|
|
43
|
+
protocol: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ISamlAssertion {
|
|
46
|
+
encodedResponse: string;
|
|
47
|
+
destination: string;
|
|
48
|
+
prettyPrintedXml: string;
|
|
49
|
+
}
|
|
50
|
+
export interface IApplicationArgs {
|
|
51
|
+
applicationfilter?: string;
|
|
52
|
+
verbose: boolean;
|
|
53
|
+
wipe: boolean;
|
|
54
|
+
config: boolean;
|
|
55
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -5,8 +5,14 @@
|
|
|
5
5
|
"author": "andrei gec (andreigec@hotmail.com)",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"private": false,
|
|
8
|
-
"version": "0.0.
|
|
8
|
+
"version": "0.0.10",
|
|
9
9
|
"preferGlobal": true,
|
|
10
|
+
"scripts": {
|
|
11
|
+
"format": "eslint --ext .ts,.tsx ./src --fix",
|
|
12
|
+
"lint": "tsc && eslint --ext .ts,.tsx ./src",
|
|
13
|
+
"start": "tsc && node bin/awsauth.js",
|
|
14
|
+
"build": "tsc"
|
|
15
|
+
},
|
|
10
16
|
"bin": {
|
|
11
17
|
"ag-awsauth": "./bin/awsauth.js"
|
|
12
18
|
},
|
|
@@ -28,9 +34,8 @@
|
|
|
28
34
|
"esbuild": "0.17.8",
|
|
29
35
|
"eslint-config-e7npm": "0.0.8",
|
|
30
36
|
"ini": "3.0.1",
|
|
31
|
-
"node-beep": "0.0.3",
|
|
32
37
|
"node-fetch": "2.6.9",
|
|
33
|
-
"puppeteer": "19.7.
|
|
38
|
+
"puppeteer": "19.7.2",
|
|
34
39
|
"readline-sync": "1.4.10",
|
|
35
40
|
"ts-node": "10.9.1",
|
|
36
41
|
"typescript": "4.9.5",
|
|
@@ -48,11 +53,5 @@
|
|
|
48
53
|
"yarn": "use pnpm",
|
|
49
54
|
"npm": "use pnpm",
|
|
50
55
|
"pnpm": ">=3"
|
|
51
|
-
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"format": "eslint --ext .ts,.tsx ./src --fix",
|
|
54
|
-
"lint": "tsc && eslint --ext .ts,.tsx ./src",
|
|
55
|
-
"start": "tsc && node bin/awsauth.js",
|
|
56
|
-
"build": "tsc"
|
|
57
56
|
}
|
|
58
|
-
}
|
|
57
|
+
}
|
package/dist/direct.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/direct.js
DELETED