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/bin/awsauth.js
CHANGED
|
File without changes
|
package/dist/config.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const logPath = "log.txt";
|
|
2
|
-
export declare const stsDurationSeconds: number;
|
|
3
|
-
export declare const nativeStsDurationSeconds: number;
|
|
4
|
-
export declare let basePath: string;
|
|
5
|
-
export declare const setBasePath: (bp: string) => void;
|
|
6
|
-
export declare let identityCenterRegion: string;
|
|
7
|
-
export declare let ssoStartUrl: string;
|
|
8
|
-
export declare let targetRegion: string;
|
|
9
|
-
export declare const validateConfig: () => boolean;
|
|
10
|
-
export declare const setConfig: () => void;
|
|
11
|
-
export declare const runConfig: () => void;
|
|
12
|
-
export declare const timeoutMs =
|
|
1
|
+
export declare const logPath = "log.txt";
|
|
2
|
+
export declare const stsDurationSeconds: number;
|
|
3
|
+
export declare const nativeStsDurationSeconds: number;
|
|
4
|
+
export declare let basePath: string;
|
|
5
|
+
export declare const setBasePath: (bp: string) => void;
|
|
6
|
+
export declare let identityCenterRegion: string;
|
|
7
|
+
export declare let ssoStartUrl: string;
|
|
8
|
+
export declare let targetRegion: string;
|
|
9
|
+
export declare const validateConfig: () => boolean;
|
|
10
|
+
export declare const setConfig: () => void;
|
|
11
|
+
export declare const runConfig: () => void;
|
|
12
|
+
export declare const timeoutMs = 30000;
|
package/dist/config.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.timeoutMs = exports.runConfig = exports.setConfig = exports.validateConfig = exports.targetRegion = exports.ssoStartUrl = exports.identityCenterRegion = exports.setBasePath = exports.basePath = exports.nativeStsDurationSeconds = exports.stsDurationSeconds = exports.logPath = void 0;
|
|
7
|
-
const envfile_1 = require("envfile");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
exports.logPath = 'log.txt';
|
|
11
|
-
exports.stsDurationSeconds = 60 * 60 * 4; //4h
|
|
12
|
-
exports.nativeStsDurationSeconds = 60 * 60 * 1; //1h
|
|
13
|
-
exports.basePath = '';
|
|
14
|
-
const setBasePath = (bp) => {
|
|
15
|
-
exports.basePath = bp;
|
|
16
|
-
};
|
|
17
|
-
exports.setBasePath = setBasePath;
|
|
18
|
-
exports.identityCenterRegion = '';
|
|
19
|
-
exports.ssoStartUrl = '';
|
|
20
|
-
exports.targetRegion = '';
|
|
21
|
-
const validateConfig = () => {
|
|
22
|
-
(0, exports.setConfig)();
|
|
23
|
-
if (!exports.identityCenterRegion || !exports.ssoStartUrl || !exports.targetRegion) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
};
|
|
28
|
-
exports.validateConfig = validateConfig;
|
|
29
|
-
const setConfig = () => {
|
|
30
|
-
exports.identityCenterRegion = process.env.identityCenterRegion;
|
|
31
|
-
exports.ssoStartUrl = process.env.ssoStartUrl;
|
|
32
|
-
exports.targetRegion = process.env.targetRegion;
|
|
33
|
-
};
|
|
34
|
-
exports.setConfig = setConfig;
|
|
35
|
-
const runConfig = () => {
|
|
36
|
-
const pn = path_1.default.resolve(exports.basePath + '/.env');
|
|
37
|
-
if (!fs_1.default.existsSync(pn)) {
|
|
38
|
-
fs_1.default.writeFileSync(pn, '');
|
|
39
|
-
}
|
|
40
|
-
const c = (0, envfile_1.parse)(fs_1.default.readFileSync(pn).toString());
|
|
41
|
-
if (!c.ssoStartUrl) {
|
|
42
|
-
c.ssoStartUrl = ' //eg https://d-xxx.awsapps.com/start';
|
|
43
|
-
}
|
|
44
|
-
if (!c.targetRegion) {
|
|
45
|
-
c.targetRegion = ' //eg ap-southeast-1';
|
|
46
|
-
}
|
|
47
|
-
if (!c.identityCenterRegion) {
|
|
48
|
-
c.identityCenterRegion = ' //eg us-east-1';
|
|
49
|
-
}
|
|
50
|
-
fs_1.default.writeFileSync(pn, (0, envfile_1.stringify)(c));
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
52
|
-
require('child_process').exec(`start "" "${pn}"`);
|
|
53
|
-
};
|
|
54
|
-
exports.runConfig = runConfig;
|
|
55
|
-
exports.timeoutMs =
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.timeoutMs = exports.runConfig = exports.setConfig = exports.validateConfig = exports.targetRegion = exports.ssoStartUrl = exports.identityCenterRegion = exports.setBasePath = exports.basePath = exports.nativeStsDurationSeconds = exports.stsDurationSeconds = exports.logPath = void 0;
|
|
7
|
+
const envfile_1 = require("envfile");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
exports.logPath = 'log.txt';
|
|
11
|
+
exports.stsDurationSeconds = 60 * 60 * 4; //4h
|
|
12
|
+
exports.nativeStsDurationSeconds = 60 * 60 * 1; //1h
|
|
13
|
+
exports.basePath = '';
|
|
14
|
+
const setBasePath = (bp) => {
|
|
15
|
+
exports.basePath = bp;
|
|
16
|
+
};
|
|
17
|
+
exports.setBasePath = setBasePath;
|
|
18
|
+
exports.identityCenterRegion = '';
|
|
19
|
+
exports.ssoStartUrl = '';
|
|
20
|
+
exports.targetRegion = '';
|
|
21
|
+
const validateConfig = () => {
|
|
22
|
+
(0, exports.setConfig)();
|
|
23
|
+
if (!exports.identityCenterRegion || !exports.ssoStartUrl || !exports.targetRegion) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
exports.validateConfig = validateConfig;
|
|
29
|
+
const setConfig = () => {
|
|
30
|
+
exports.identityCenterRegion = process.env.identityCenterRegion;
|
|
31
|
+
exports.ssoStartUrl = process.env.ssoStartUrl;
|
|
32
|
+
exports.targetRegion = process.env.targetRegion;
|
|
33
|
+
};
|
|
34
|
+
exports.setConfig = setConfig;
|
|
35
|
+
const runConfig = () => {
|
|
36
|
+
const pn = path_1.default.resolve(exports.basePath + '/.env');
|
|
37
|
+
if (!fs_1.default.existsSync(pn)) {
|
|
38
|
+
fs_1.default.writeFileSync(pn, '');
|
|
39
|
+
}
|
|
40
|
+
const c = (0, envfile_1.parse)(fs_1.default.readFileSync(pn).toString());
|
|
41
|
+
if (!c.ssoStartUrl) {
|
|
42
|
+
c.ssoStartUrl = ' //eg https://d-xxx.awsapps.com/start';
|
|
43
|
+
}
|
|
44
|
+
if (!c.targetRegion) {
|
|
45
|
+
c.targetRegion = ' //eg ap-southeast-1';
|
|
46
|
+
}
|
|
47
|
+
if (!c.identityCenterRegion) {
|
|
48
|
+
c.identityCenterRegion = ' //eg us-east-1';
|
|
49
|
+
}
|
|
50
|
+
fs_1.default.writeFileSync(pn, (0, envfile_1.stringify)(c));
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
52
|
+
require('child_process').exec(`start "" "${pn}"`);
|
|
53
|
+
};
|
|
54
|
+
exports.runConfig = runConfig;
|
|
55
|
+
exports.timeoutMs = 30000;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IAwsCreds, IAwsCredsRaw } from '../types';
|
|
2
|
-
export declare const getAwsCredentials: () => Promise<Record<string, IAwsCredsRaw>>;
|
|
3
|
-
export declare const updateAwsCredentials: (p: IAwsCreds | undefined) => Promise<void>;
|
|
1
|
+
import { IAwsCreds, IAwsCredsRaw } from '../types';
|
|
2
|
+
export declare const getAwsCredentials: () => Promise<Record<string, IAwsCredsRaw>>;
|
|
3
|
+
export declare const updateAwsCredentials: (p: IAwsCreds | undefined) => Promise<void>;
|
|
@@ -1,52 +1,52 @@
|
|
|
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.updateAwsCredentials = exports.getAwsCredentials = void 0;
|
|
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
|
-
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
20
|
-
const fs_1 = __importDefault(require("fs"));
|
|
21
|
-
const ini_1 = require("ini");
|
|
22
|
-
const getAwsCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
const config = yield (0, shared_ini_file_loader_1.loadSharedConfigFiles)();
|
|
24
|
-
const creds = config.credentialsFile;
|
|
25
|
-
if (!creds.default) {
|
|
26
|
-
creds.default = {};
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
const ret = creds;
|
|
30
|
-
return ret;
|
|
31
|
-
});
|
|
32
|
-
exports.getAwsCredentials = getAwsCredentials;
|
|
33
|
-
const updateAwsCredentials = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const creds = yield (0, exports.getAwsCredentials)();
|
|
35
|
-
if (!p) {
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
creds.default = {};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
creds.default.region = p.region;
|
|
41
|
-
creds.default.aws_access_key_id = p.accessKeyId;
|
|
42
|
-
creds.default.aws_secret_access_key = p.secretAccessKey;
|
|
43
|
-
creds.default.aws_session_token = p.sessionToken;
|
|
44
|
-
creds.default.aws_access_token = p.accessToken;
|
|
45
|
-
creds.default.aws_sso_authn = p.ssoAuthn;
|
|
46
|
-
}
|
|
47
|
-
const newcreds = (0, ini_1.stringify)(creds);
|
|
48
|
-
(0, log_1.info)(`saving updated default creds to .aws/credentials`);
|
|
49
|
-
const credspath = (0, getCredentialsFilepath_1.getCredentialsFilepath)();
|
|
50
|
-
fs_1.default.writeFileSync(credspath, newcreds);
|
|
51
|
-
});
|
|
52
|
-
exports.updateAwsCredentials = updateAwsCredentials;
|
|
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.updateAwsCredentials = exports.getAwsCredentials = void 0;
|
|
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
|
+
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
const ini_1 = require("ini");
|
|
22
|
+
const getAwsCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const config = yield (0, shared_ini_file_loader_1.loadSharedConfigFiles)();
|
|
24
|
+
const creds = config.credentialsFile;
|
|
25
|
+
if (!creds.default) {
|
|
26
|
+
creds.default = {};
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
const ret = creds;
|
|
30
|
+
return ret;
|
|
31
|
+
});
|
|
32
|
+
exports.getAwsCredentials = getAwsCredentials;
|
|
33
|
+
const updateAwsCredentials = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const creds = yield (0, exports.getAwsCredentials)();
|
|
35
|
+
if (!p) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
creds.default = {};
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
creds.default.region = p.region;
|
|
41
|
+
creds.default.aws_access_key_id = p.accessKeyId;
|
|
42
|
+
creds.default.aws_secret_access_key = p.secretAccessKey;
|
|
43
|
+
creds.default.aws_session_token = p.sessionToken;
|
|
44
|
+
creds.default.aws_access_token = p.accessToken;
|
|
45
|
+
creds.default.aws_sso_authn = p.ssoAuthn;
|
|
46
|
+
}
|
|
47
|
+
const newcreds = (0, ini_1.stringify)(creds);
|
|
48
|
+
(0, log_1.info)(`saving updated default creds to .aws/credentials`);
|
|
49
|
+
const credspath = (0, getCredentialsFilepath_1.getCredentialsFilepath)();
|
|
50
|
+
fs_1.default.writeFileSync(credspath, newcreds);
|
|
51
|
+
});
|
|
52
|
+
exports.updateAwsCredentials = updateAwsCredentials;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const closeBrowser: () => Promise<void>;
|
|
2
|
-
export declare const launchBrowser: () => Promise<void>;
|
|
3
|
-
export declare const goToPage: (url: string) => Promise<import("puppeteer").Page>;
|
|
4
|
-
export declare function getMFA(p: {
|
|
5
|
-
verificationUriComplete: string;
|
|
6
|
-
creds: {
|
|
7
|
-
username: string;
|
|
8
|
-
password: string;
|
|
9
|
-
};
|
|
10
|
-
}): Promise<{
|
|
11
|
-
ssoAuthn: string;
|
|
12
|
-
}>;
|
|
1
|
+
export declare const closeBrowser: () => Promise<void>;
|
|
2
|
+
export declare const launchBrowser: () => Promise<void>;
|
|
3
|
+
export declare const goToPage: (url: string) => Promise<import("puppeteer").Page>;
|
|
4
|
+
export declare function getMFA(p: {
|
|
5
|
+
verificationUriComplete: string;
|
|
6
|
+
creds: {
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
9
|
+
};
|
|
10
|
+
}): Promise<{
|
|
11
|
+
ssoAuthn: string;
|
|
12
|
+
}>;
|
package/dist/helpers/browser.js
CHANGED
|
@@ -1,167 +1,170 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getMFA = exports.goToPage = exports.launchBrowser = exports.closeBrowser = void 0;
|
|
13
|
-
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
14
|
-
const sleep_1 = require("ag-common/dist/common/helpers/sleep");
|
|
15
|
-
const puppeteer_1 = require("puppeteer");
|
|
16
|
-
const __1 = require("..");
|
|
17
|
-
const config_1 = require("../config");
|
|
18
|
-
const input_1 = require("./input");
|
|
19
|
-
let browser;
|
|
20
|
-
const closeBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
try {
|
|
22
|
-
if (!browser) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
yield browser.close();
|
|
26
|
-
browser = undefined;
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
(0, log_1.warn)('error closing browser:', e);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
exports.closeBrowser = closeBrowser;
|
|
33
|
-
const launchBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const opt = {
|
|
35
|
-
defaultViewport: { height: 1000, width: 500 },
|
|
36
|
-
headless: !(__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose),
|
|
37
|
-
ignoreHTTPSErrors: true,
|
|
38
|
-
devtools: false,
|
|
39
|
-
};
|
|
40
|
-
if (!opt.args) {
|
|
41
|
-
opt.args = [];
|
|
42
|
-
}
|
|
43
|
-
opt.args.push('--disable-features=AudioServiceOutOfProcess');
|
|
44
|
-
opt.args.push('--disable-features=AudioServiceOutOfProcessKillAtHang');
|
|
45
|
-
opt.args.push('--disable-software-rasterizer');
|
|
46
|
-
opt.args.push('--disable-gpu');
|
|
47
|
-
opt.args.push('--disable-dev-shm-usage');
|
|
48
|
-
yield (0, exports.closeBrowser)();
|
|
49
|
-
(0, log_1.debug)('launch browser, opt=', opt);
|
|
50
|
-
browser = (yield (0, puppeteer_1.launch)(opt));
|
|
51
|
-
(0, log_1.debug)('browser created');
|
|
52
|
-
});
|
|
53
|
-
exports.launchBrowser = launchBrowser;
|
|
54
|
-
const goToPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
try {
|
|
56
|
-
if (!browser) {
|
|
57
|
-
yield (0, exports.launchBrowser)();
|
|
58
|
-
}
|
|
59
|
-
if (!browser) {
|
|
60
|
-
throw new Error('no browser');
|
|
61
|
-
}
|
|
62
|
-
(0, log_1.info)(`go to page:${url}`);
|
|
63
|
-
const page = yield browser.newPage();
|
|
64
|
-
yield page.goto(url, {
|
|
65
|
-
waitUntil: ['networkidle2'],
|
|
66
|
-
timeout: config_1.timeoutMs,
|
|
67
|
-
});
|
|
68
|
-
return page;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
const em = 'browser error:' + e.toString();
|
|
72
|
-
(0, log_1.error)(em);
|
|
73
|
-
throw new Error(em);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
exports.goToPage = goToPage;
|
|
77
|
-
function getMFA(p) {
|
|
78
|
-
var _a;
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
//go to browser site for auth
|
|
81
|
-
(0, log_1.info)('start mfa');
|
|
82
|
-
const page = yield (0, exports.goToPage)(p.verificationUriComplete);
|
|
83
|
-
(0, log_1.info)('username block');
|
|
84
|
-
yield page.waitForSelector('#username-input', { timeout: config_1.timeoutMs });
|
|
85
|
-
yield page.focus('#username-input input');
|
|
86
|
-
yield page.keyboard.type(p.creds.username);
|
|
87
|
-
yield page.$eval('#username-submit-button button', (el) => el.click());
|
|
88
|
-
//
|
|
89
|
-
(0, log_1.info)('password block');
|
|
90
|
-
yield page.waitForSelector('#password-input', { timeout: config_1.timeoutMs });
|
|
91
|
-
yield page.focus('#password-input input');
|
|
92
|
-
yield page.keyboard.type(p.creds.password);
|
|
93
|
-
yield page.$eval('#password-submit-button button', (el) => el.click());
|
|
94
|
-
yield (0, sleep_1.sleep)(250);
|
|
95
|
-
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
96
|
-
//
|
|
97
|
-
try {
|
|
98
|
-
const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
|
|
99
|
-
timeout: 2000, //can be short
|
|
100
|
-
});
|
|
101
|
-
const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
|
|
102
|
-
if (value) {
|
|
103
|
-
throw new Error(value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
const em = e.toString();
|
|
108
|
-
if (!em.includes('exceeded')) {
|
|
109
|
-
const em2 = `creds error:` + em;
|
|
110
|
-
(0, log_1.error)(em2);
|
|
111
|
-
throw new Error(em2);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
//
|
|
115
|
-
let retry = true;
|
|
116
|
-
do {
|
|
117
|
-
(0, log_1.info)('mfa block');
|
|
118
|
-
const { mfa } = (0, input_1.enterMFA)();
|
|
119
|
-
yield page.waitForSelector('#input-0', { timeout: config_1.timeoutMs });
|
|
120
|
-
yield page.focus('#input-0 input');
|
|
121
|
-
yield page.keyboard.type(mfa);
|
|
122
|
-
yield page.$eval('.awsui-signin-button-container button', (el) => el.click());
|
|
123
|
-
//
|
|
124
|
-
try {
|
|
125
|
-
yield (0, sleep_1.sleep)(250);
|
|
126
|
-
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
127
|
-
const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
|
|
128
|
-
timeout: 2000, // can be short
|
|
129
|
-
});
|
|
130
|
-
const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
|
|
131
|
-
if (value) {
|
|
132
|
-
throw new Error(value);
|
|
133
|
-
}
|
|
134
|
-
retry = false;
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
const em = e.toString();
|
|
138
|
-
if (!em.includes('exceeded')) {
|
|
139
|
-
const em2 = `mfa error:` + em + ' retry';
|
|
140
|
-
(0, log_1.error)(em2);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
retry = false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
} while (retry);
|
|
147
|
-
//
|
|
148
|
-
yield (0, sleep_1.sleep)(3000);
|
|
149
|
-
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
150
|
-
yield page.waitForSelector('
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
yield page
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getMFA = exports.goToPage = exports.launchBrowser = exports.closeBrowser = void 0;
|
|
13
|
+
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
14
|
+
const sleep_1 = require("ag-common/dist/common/helpers/sleep");
|
|
15
|
+
const puppeteer_1 = require("puppeteer");
|
|
16
|
+
const __1 = require("..");
|
|
17
|
+
const config_1 = require("../config");
|
|
18
|
+
const input_1 = require("./input");
|
|
19
|
+
let browser;
|
|
20
|
+
const closeBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
if (!browser) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
yield browser.close();
|
|
26
|
+
browser = undefined;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
(0, log_1.warn)('error closing browser:', e);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.closeBrowser = closeBrowser;
|
|
33
|
+
const launchBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const opt = {
|
|
35
|
+
defaultViewport: { height: 1000, width: 500 },
|
|
36
|
+
headless: !(__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose),
|
|
37
|
+
ignoreHTTPSErrors: true,
|
|
38
|
+
devtools: false,
|
|
39
|
+
};
|
|
40
|
+
if (!opt.args) {
|
|
41
|
+
opt.args = [];
|
|
42
|
+
}
|
|
43
|
+
opt.args.push('--disable-features=AudioServiceOutOfProcess');
|
|
44
|
+
opt.args.push('--disable-features=AudioServiceOutOfProcessKillAtHang');
|
|
45
|
+
opt.args.push('--disable-software-rasterizer');
|
|
46
|
+
opt.args.push('--disable-gpu');
|
|
47
|
+
opt.args.push('--disable-dev-shm-usage');
|
|
48
|
+
yield (0, exports.closeBrowser)();
|
|
49
|
+
(0, log_1.debug)('launch browser, opt=', opt);
|
|
50
|
+
browser = (yield (0, puppeteer_1.launch)(opt));
|
|
51
|
+
(0, log_1.debug)('browser created');
|
|
52
|
+
});
|
|
53
|
+
exports.launchBrowser = launchBrowser;
|
|
54
|
+
const goToPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
if (!browser) {
|
|
57
|
+
yield (0, exports.launchBrowser)();
|
|
58
|
+
}
|
|
59
|
+
if (!browser) {
|
|
60
|
+
throw new Error('no browser');
|
|
61
|
+
}
|
|
62
|
+
(0, log_1.info)(`go to page:${url}`);
|
|
63
|
+
const page = yield browser.newPage();
|
|
64
|
+
yield page.goto(url, {
|
|
65
|
+
waitUntil: ['networkidle2'],
|
|
66
|
+
timeout: config_1.timeoutMs,
|
|
67
|
+
});
|
|
68
|
+
return page;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
const em = 'browser error:' + e.toString();
|
|
72
|
+
(0, log_1.error)(em);
|
|
73
|
+
throw new Error(em);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
exports.goToPage = goToPage;
|
|
77
|
+
function getMFA(p) {
|
|
78
|
+
var _a;
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
//go to browser site for auth
|
|
81
|
+
(0, log_1.info)('start mfa');
|
|
82
|
+
const page = yield (0, exports.goToPage)(p.verificationUriComplete);
|
|
83
|
+
(0, log_1.info)('username block');
|
|
84
|
+
yield page.waitForSelector('#username-input', { timeout: config_1.timeoutMs });
|
|
85
|
+
yield page.focus('#username-input input');
|
|
86
|
+
yield page.keyboard.type(p.creds.username);
|
|
87
|
+
yield page.$eval('#username-submit-button button', (el) => el.click());
|
|
88
|
+
//
|
|
89
|
+
(0, log_1.info)('password block');
|
|
90
|
+
yield page.waitForSelector('#password-input', { timeout: config_1.timeoutMs });
|
|
91
|
+
yield page.focus('#password-input input');
|
|
92
|
+
yield page.keyboard.type(p.creds.password);
|
|
93
|
+
yield page.$eval('#password-submit-button button', (el) => el.click());
|
|
94
|
+
yield (0, sleep_1.sleep)(250);
|
|
95
|
+
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
96
|
+
//
|
|
97
|
+
try {
|
|
98
|
+
const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
|
|
99
|
+
timeout: 2000, //can be short
|
|
100
|
+
});
|
|
101
|
+
const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
|
|
102
|
+
if (value) {
|
|
103
|
+
throw new Error(value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
const em = e.toString();
|
|
108
|
+
if (!em.includes('exceeded')) {
|
|
109
|
+
const em2 = `creds error:` + em;
|
|
110
|
+
(0, log_1.error)(em2);
|
|
111
|
+
throw new Error(em2);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//
|
|
115
|
+
let retry = true;
|
|
116
|
+
do {
|
|
117
|
+
(0, log_1.info)('mfa block');
|
|
118
|
+
const { mfa } = (0, input_1.enterMFA)();
|
|
119
|
+
yield page.waitForSelector('#input-0', { timeout: config_1.timeoutMs });
|
|
120
|
+
yield page.focus('#input-0 input');
|
|
121
|
+
yield page.keyboard.type(mfa);
|
|
122
|
+
yield page.$eval('.awsui-signin-button-container button', (el) => el.click());
|
|
123
|
+
//
|
|
124
|
+
try {
|
|
125
|
+
yield (0, sleep_1.sleep)(250);
|
|
126
|
+
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
127
|
+
const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
|
|
128
|
+
timeout: 2000, // can be short
|
|
129
|
+
});
|
|
130
|
+
const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
|
|
131
|
+
if (value) {
|
|
132
|
+
throw new Error(value);
|
|
133
|
+
}
|
|
134
|
+
retry = false;
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
const em = e.toString();
|
|
138
|
+
if (!em.includes('exceeded')) {
|
|
139
|
+
const em2 = `mfa error:` + em + ' retry';
|
|
140
|
+
(0, log_1.error)(em2);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
retry = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} while (retry);
|
|
147
|
+
//
|
|
148
|
+
yield (0, sleep_1.sleep)(3000);
|
|
149
|
+
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
150
|
+
yield page.waitForSelector('.awsui-signin-button', {
|
|
151
|
+
timeout: config_1.timeoutMs,
|
|
152
|
+
visible: true, //may need this for more calls
|
|
153
|
+
});
|
|
154
|
+
yield page.$eval('.awsui-signin-button', (el) => el.click());
|
|
155
|
+
yield (0, sleep_1.sleep)(250);
|
|
156
|
+
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
157
|
+
yield page.waitForSelector('.awsui-icon-variant-success', {
|
|
158
|
+
timeout: config_1.timeoutMs,
|
|
159
|
+
});
|
|
160
|
+
(0, log_1.warn)('mfa success');
|
|
161
|
+
const cookies = yield (page === null || page === void 0 ? void 0 : page.cookies());
|
|
162
|
+
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;
|
|
163
|
+
if (!ssoAuthn) {
|
|
164
|
+
throw new Error('no aws authn');
|
|
165
|
+
}
|
|
166
|
+
yield (0, exports.closeBrowser)();
|
|
167
|
+
return { ssoAuthn };
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
exports.getMFA = getMFA;
|
package/dist/helpers/input.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IAppInstance, IApplicationArgs } from '../types';
|
|
2
|
-
export declare function chooseAppInstance(ai: IAppInstance[], args: IApplicationArgs): Promise<IAppInstance>;
|
|
3
|
-
export declare function readArguments(): Promise<IApplicationArgs>;
|
|
4
|
-
export declare function enterCreds(): {
|
|
5
|
-
username: string;
|
|
6
|
-
password: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function enterMFA(): {
|
|
9
|
-
mfa: string;
|
|
10
|
-
};
|
|
1
|
+
import { IAppInstance, IApplicationArgs } from '../types';
|
|
2
|
+
export declare function chooseAppInstance(ai: IAppInstance[], args: IApplicationArgs): Promise<IAppInstance>;
|
|
3
|
+
export declare function readArguments(): Promise<IApplicationArgs>;
|
|
4
|
+
export declare function enterCreds(): {
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function enterMFA(): {
|
|
9
|
+
mfa: string;
|
|
10
|
+
};
|