az2aws 1.0.0

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.
@@ -0,0 +1,16 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(yarn test)",
5
+ "Bash(npm run test)",
6
+ "Bash(npm run build:*)",
7
+ "Bash(npm install)",
8
+ "Bash(npm cache clean:*)",
9
+ "Bash(npm install:*)",
10
+ "Bash(yarn install)",
11
+ "WebFetch(domain:github.com)",
12
+ "WebFetch(domain:patch-diff.githubusercontent.com)",
13
+ "Bash(ls:*)"
14
+ ]
15
+ }
16
+ }
@@ -0,0 +1,54 @@
1
+ # Contributing
2
+
3
+ ## Get started
4
+
5
+ This project is written in TypeScript and is using prettier and eslint for code formatting. You need node v22.
6
+
7
+ 1. Install node v22. I recommend installing that with nvm: https://github.com/nvm-sh/nvm
8
+
9
+ ```sh
10
+ nvm install 22
11
+ ```
12
+
13
+ 2. Make node v22 default
14
+
15
+ ```sh
16
+ nvm alias default 22
17
+ ```
18
+
19
+ 3. Open a new terminal and verify node version (should return v22.X.X)
20
+
21
+ ```sh
22
+ node -v
23
+ ```
24
+
25
+ 4. Install yarn
26
+
27
+ ```sh
28
+ npm install -g yarn
29
+ ```
30
+
31
+ 5. Fork and clone project
32
+
33
+ ```sh
34
+ git clone git@github.com:<GITHUB_USERNAME>/az2aws.git
35
+ cd az2aws
36
+ ```
37
+
38
+ 6. Install dependencies
39
+
40
+ ```sh
41
+ yarn install
42
+ ```
43
+
44
+ 7a. Start dev mode
45
+
46
+ ```sh
47
+ yarn start
48
+ ```
49
+
50
+ 7b. Start prod mode
51
+
52
+ ```sh
53
+ yarn build && node ./lib/index.js
54
+ ```
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 az2aws devs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ [![view on npm](http://img.shields.io/npm/v/az2aws.svg)](https://www.npmjs.org/package/az2aws)
2
+ [![npm module downloads per month](http://img.shields.io/npm/dm/az2aws.svg)](https://www.npmjs.org/package/az2aws)
3
+
4
+ # az2aws
5
+
6
+ If your organization uses [Azure Active Directory](https://azure.microsoft.com) to provide SSO login to the AWS console, then there is no easy way to log in on the command line or to use the [AWS CLI](https://aws.amazon.com/cli/). This tool fixes that. It lets you use the normal Azure AD login (including MFA) from a command line to create a federated AWS session and places the temporary credentials in the proper place for the AWS CLI and SDKs.
7
+
8
+ ## Installation
9
+
10
+ Installation can be done in any of the following platform - Windows, Linux, Docker, Snap
11
+
12
+ ### Windows
13
+
14
+ Install [Node.js](https://nodejs.org/) v22 or higher. Then install az2aws with npm:
15
+
16
+ npm install -g az2aws
17
+
18
+ You may need to install puppeteer dependency, if you're getting missing chrome or chromium message
19
+
20
+ node <node_modules_dir>/az2aws/node_modules/puppeteer/install.js
21
+
22
+ ### Linux
23
+
24
+ In Linux you can either install for all users or just the current user. In either case, you must first install [Node.js](https://nodejs.org/) v22 or higher and any [puppeteer dependencies](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch). Then follow the appropriate instructions.
25
+
26
+ #### Option A: Install for All Users
27
+
28
+ Install az2aws globally with npm:
29
+
30
+ sudo npm install -g az2aws --unsafe-perm
31
+
32
+ Puppeteer doesn't install globally with execution permissions for all users so you'll need to modify them:
33
+
34
+ sudo chmod -R go+rx $(npm root -g)
35
+
36
+ #### Option B: Install Only for Current User
37
+
38
+ First configure npm to install global packages in [your home directory](https://docs.npmjs.com/getting-started/fixing-npm-permissions):
39
+
40
+ mkdir ~/.npm-global
41
+ npm config set prefix '~/.npm-global'
42
+ export PATH=~/.npm-global/bin:$PATH
43
+ source ~/.profile
44
+ echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
45
+ source ~/.profile
46
+
47
+ Then install az2aws:
48
+
49
+ npm install -g az2aws
50
+
51
+ ### Docker
52
+
53
+ A Docker image has been built with az2aws preinstalled. You simply need to run the command with a volume mounted to your AWS configuration directory.
54
+
55
+ docker run --rm -it -v ~/.aws:/root/.aws az2aws/az2aws
56
+
57
+ The Docker image is configured with an entrypoint so you can just feed any arguments in at the end.
58
+
59
+ You can also put the docker-launch.sh script into your bin directory for the az2aws command to function as usual:
60
+
61
+ # Download the script (replace VERSION with a specific release tag, e.g., v1.0.0)
62
+ curl -o /tmp/az2aws https://raw.githubusercontent.com/az2aws/az2aws/VERSION/docker-launch.sh -L
63
+
64
+ # IMPORTANT: Review the script before installing
65
+ cat /tmp/az2aws
66
+
67
+ # Install after verification
68
+ sudo mv /tmp/az2aws /usr/local/bin/az2aws
69
+ sudo chmod +x /usr/local/bin/az2aws
70
+
71
+ > **Security Note:** Always download from a specific release tag (not `main`) and review the script contents before installing. Downloading and executing scripts directly from mutable branch heads poses a supply chain risk.
72
+
73
+ Now just run `az2aws`.
74
+
75
+ ### Snap
76
+
77
+ https://snapcraft.io/az2aws
78
+
79
+ ## Usage
80
+
81
+ ### Configuration
82
+
83
+ #### AWS
84
+
85
+ To configure the az2aws client run:
86
+
87
+ az2aws --configure
88
+
89
+ You'll need your [Azure Tenant ID and the App ID URI](#getting-your-tenant-id-and-app-id-uri). To configure a named profile, use the --profile flag.
90
+
91
+ az2aws --configure --profile foo
92
+
93
+ ##### GovCloud Support
94
+
95
+ To use az2aws with AWS GovCloud, set the `region` profile property in your ~/.aws/config to the one of the GovCloud regions:
96
+
97
+ - us-gov-west-1
98
+ - us-gov-east-1
99
+
100
+ ##### China Region Support
101
+
102
+ To use az2aws with AWS China Cloud, set the `region` profile property in your ~/.aws/config to the China region:
103
+
104
+ - cn-north-1
105
+
106
+ #### Staying logged in, skip username/password for future logins
107
+
108
+ During the configuration you can decide to stay logged in:
109
+
110
+ ? Stay logged in: skip authentication while refreshing aws credentials (true|false) (false)
111
+
112
+ If you set this configuration to true, the usual authentication with username/password/MFA is skipped as it's using session cookies to remember your identity. This enables you to use `--no-prompt` without the need to store your password anywhere, it's an alternative for using environment variables as described below.
113
+ As soon as you went through the full login procedure once, you can just use:
114
+
115
+ az2aws --no-prompt
116
+
117
+ or
118
+
119
+ az2aws --profile foo --no-prompt
120
+
121
+ to refresh your aws credentials.
122
+
123
+ #### Environment Variables
124
+
125
+ You can optionally store your responses as environment variables:
126
+
127
+ - `AZURE_TENANT_ID`
128
+ - `AZURE_APP_ID_URI`
129
+ - `AZURE_DEFAULT_USERNAME`
130
+ - `AZURE_DEFAULT_PASSWORD`
131
+ - `AZURE_DEFAULT_ROLE_ARN`
132
+ - `AZURE_DEFAULT_DURATION_HOURS`
133
+
134
+ To avoid having to `<Enter>` through the prompts after setting these environment variables, use the `--no-prompt` option when running the command.
135
+
136
+ az2aws --no-prompt
137
+
138
+ Use the `HISTCONTROL` environment variable to avoid storing the password in your bash history (notice the space at the beginning):
139
+
140
+ $ HISTCONTROL=ignoreboth
141
+ $ export AZURE_DEFAULT_PASSWORD=mypassword
142
+ $ az2aws
143
+
144
+ #### Use an Existing Chrome Install and Profile
145
+
146
+ Instead of using the bundled Chromium, you can use an existing Chrome installation with your own user profile by setting the following environment variables:
147
+
148
+ - `BROWSER_CHROME_BIN` - Path to Chrome executable
149
+ - `BROWSER_USER_DATA_DIR` - Chrome user data directory
150
+ - `BROWSER_PROFILE_DIR` - Chrome profile name (e.g., "Default")
151
+
152
+ Example (macOS):
153
+
154
+ export BROWSER_CHROME_BIN="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
155
+ export BROWSER_USER_DATA_DIR="/Users/<user>/Library/Application Support/Google/Chrome"
156
+ export BROWSER_PROFILE_DIR="Default"
157
+ aws-azure-login --mode gui --no-disable-extensions --no-sandbox
158
+
159
+ Example (Linux):
160
+
161
+ export BROWSER_CHROME_BIN="/usr/bin/google-chrome"
162
+ export BROWSER_USER_DATA_DIR="/home/<user>/.config/google-chrome"
163
+ export BROWSER_PROFILE_DIR="Default"
164
+ aws-azure-login --mode gui --no-disable-extensions --no-sandbox
165
+
166
+ Using Chrome instead of Chromium allows you to use browser extensions such as password managers.
167
+
168
+ ### Logging In
169
+
170
+ Once az2aws is configured, you can log in. For the default profile, just run:
171
+
172
+ az2aws
173
+
174
+ You will be prompted for your username and password. If MFA is required you'll also be prompted for a verification code or mobile device approval. To log in with a named profile:
175
+
176
+ az2aws --profile foo
177
+
178
+ Alternatively, you can set the `AWS_PROFILE` environmental variable to the name of the profile just like the AWS CLI.
179
+
180
+ Once you log in you can use the AWS CLI or SDKs as usual!
181
+
182
+ If you are logging in on an operating system with a GUI, you can log in using the actual Azure web form instead of the CLI:
183
+
184
+ az2aws --mode gui
185
+
186
+ Logging in with GUI mode is likely to be much more reliable.
187
+
188
+ _Note:_ on virtual machines, or when rendering of the puppeteer UI fails, you might need to disable the GPU Hardware Acceleration:
189
+
190
+ az2aws --mode gui --disable-gpu
191
+
192
+ _Note:_ on Linux you will likely need to disable the Puppeteer sandbox or Chrome will fail to launch:
193
+
194
+ az2aws --no-sandbox
195
+
196
+ ### Behind corporate proxy
197
+
198
+ If behind corporate proxy, then just set https_proxy env variable.
199
+
200
+ ## Automation
201
+
202
+ ### Renew credentials for all configured profiles
203
+
204
+ You can renew credentials for all configured profiles in one run. This is especially useful, if the maximum session length on AWS side is configured to a low value due to security constraints. Just run:
205
+
206
+ az2aws --all-profiles
207
+
208
+ If you configure all profiles to stay logged in, you can easily skip the prompts:
209
+
210
+ az2aws --all-profiles --no-prompt
211
+
212
+ This will allow you to automate the credentials refresh procedure, eg. by running a cronjob every 5 minutes.
213
+ To skip unnecessary calls, the credentials are only getting refreshed if the time to expire is lower than 11 minutes.
214
+
215
+ ## Getting Your Tenant ID and App ID URI
216
+
217
+ Your Azure AD system admin should be able to provide you with your Tenant ID and App ID URI. If you can't get it from them, you can scrape it from a login page from the myapps.microsoft.com page.
218
+
219
+ 1. Load the myapps.microsoft.com page.
220
+ 2. Click the chicklet for the login you want.
221
+ 3. In the window the pops open quickly copy the login.microsoftonline.com URL. (If you miss it just try again. You can also open the developer console with nagivation preservation to capture the URL.)
222
+ 4. The GUID right after login.microsoftonline.com/ is the tenant ID.
223
+ 5. Copy the SAMLRequest URL param.
224
+ 6. Paste it into a URL decoder ([like this one](https://www.samltool.com/url.php)) and decode.
225
+ 7. Paste the decoded output into the a SAML deflated and encoded XML decoder ([like this one](https://www.samltool.com/decode.php)).
226
+ 8. In the decoded XML output the value of the `Audience` tag is the App ID URI.
227
+ 9. You may double-check tenant ID using `Attribute` tag named `tenantid` provided in XML.
228
+
229
+ ## How It Works
230
+
231
+ The Azure login page uses JavaScript, which requires a real web browser. To automate this from a command line, az2aws uses [Puppeteer](https://github.com/GoogleChrome/puppeteer), which automates a real Chromium browser. It loads the Azure login page behind the scenes, populates your username and password (and MFA token), parses the SAML assertion, uses the [AWS STS AssumeRoleWithSAML API](http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithSAML.html) to get temporary credentials, and saves these in the CLI credentials file.
232
+
233
+ ## Troubleshooting
234
+
235
+ The nature of browser automation with Puppeteer means the solution is bit brittle. A minor change on the Microsoft side could break the tool. If something isn't working, you can fall back to GUI mode (above). To debug an issue, you can run in debug mode (--mode debug) to see the GUI while az2aws tries to populate it. You can also have the tool print out more detail on what it is doing to try to do in order to diagnose. az2aws uses the [Node debug module](https://www.npmjs.com/package/debug) to print out debug info. Just set the DEBUG environmental variable to 'az2aws'. On Linux/OS X:
236
+
237
+ DEBUG=az2aws az2aws
238
+
239
+ On Windows:
240
+
241
+ set DEBUG=az2aws
242
+ az2aws
243
+
244
+ ## Support for Other Authentication Providers
245
+
246
+ Obviously, this tool only supports Azure AD as an identity provider. However, there is a lot of similarity with how other logins with other providers would work (especially if they are SAML providers). If you are interested in building support for a different provider let me know. It would be great to build a more generic AWS CLI login tool with plugins for the various providers.
247
+
248
+ ## Acknowledgements
249
+
250
+ This project is forked from [aws-azure-login](https://github.com/aws-azure-login/aws-azure-login). Thanks to the original authors and contributors.
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIError = void 0;
4
+ class CLIError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ Error.captureStackTrace(this, this.constructor);
8
+ this.name = this.constructor.name;
9
+ this.message = message;
10
+ }
11
+ }
12
+ exports.CLIError = CLIError;
@@ -0,0 +1,103 @@
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.awsConfig = void 0;
7
+ const ini_1 = __importDefault(require("ini"));
8
+ const debug_1 = __importDefault(require("debug"));
9
+ const paths_1 = require("./paths");
10
+ const mkdirp_1 = __importDefault(require("mkdirp"));
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const util_1 = __importDefault(require("util"));
13
+ const debug = (0, debug_1.default)("az2aws");
14
+ const writeFile = util_1.default.promisify(fs_1.default.writeFile);
15
+ // Autorefresh credential time limit in milliseconds
16
+ const refreshLimitInMs = 11 * 60 * 1000;
17
+ exports.awsConfig = {
18
+ async setProfileConfigValuesAsync(profileName, values) {
19
+ const sectionName = profileName === "default" ? "default" : `profile ${profileName}`;
20
+ debug(`Setting config for profile '${profileName}' in section '${sectionName}'`);
21
+ const config = (await this._loadAsync("config")) || {};
22
+ config[sectionName] = {
23
+ ...config[sectionName],
24
+ ...values,
25
+ };
26
+ await this._saveAsync("config", config);
27
+ },
28
+ async getProfileConfigAsync(profileName) {
29
+ const sectionName = profileName === "default" ? "default" : `profile ${profileName}`;
30
+ debug(`Getting config for profile '${profileName}' in section '${sectionName}'`);
31
+ const config = await this._loadAsync("config");
32
+ if (!config) {
33
+ return undefined;
34
+ }
35
+ return config[sectionName];
36
+ },
37
+ async isProfileAboutToExpireAsync(profileName) {
38
+ debug(`Getting credentials for profile '${profileName}'`);
39
+ const config = await this._loadAsync("credentials");
40
+ let expirationDate;
41
+ if (!config ||
42
+ config[profileName] === undefined ||
43
+ config[profileName].aws_expiration === undefined) {
44
+ expirationDate = new Date();
45
+ }
46
+ else {
47
+ expirationDate = new Date(config[profileName].aws_expiration);
48
+ }
49
+ const timeDifference = expirationDate.getTime() - new Date().getTime();
50
+ debug(`Remaining time till credential expiration: ${timeDifference / 1000}s, refresh due if time lower than: ${refreshLimitInMs / 1000}s`);
51
+ return timeDifference < refreshLimitInMs;
52
+ },
53
+ async setProfileCredentialsAsync(profileName, values) {
54
+ const credentials = (await this._loadAsync("credentials")) || {};
55
+ debug(`Setting credentials for profile '${profileName}'`);
56
+ credentials[profileName] = values;
57
+ await this._saveAsync("credentials", credentials);
58
+ },
59
+ async getAllProfileNames() {
60
+ debug(`Getting all configured profiles from config.`);
61
+ const config = (await this._loadAsync("config")) || {};
62
+ const profiles = Object.keys(config).map(function (e) {
63
+ return e.replace("profile ", "");
64
+ });
65
+ debug(`Received profiles: ${profiles.toString()}`);
66
+ return profiles;
67
+ },
68
+ async _loadAsync(type) {
69
+ if (!paths_1.paths[type])
70
+ throw new Error(`Unknown config type: '${type}'`);
71
+ return new Promise((resolve, reject) => {
72
+ debug(`Loading '${type}' file at '${paths_1.paths[type]}'`);
73
+ fs_1.default.readFile(paths_1.paths[type], "utf8", (err, data) => {
74
+ if (err) {
75
+ if (err.code === "ENOENT") {
76
+ debug(`File not found. Returning undefined.`);
77
+ return resolve(undefined);
78
+ }
79
+ else {
80
+ return reject(err);
81
+ }
82
+ }
83
+ debug("Parsing data");
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ const parsedIni = ini_1.default.parse(data);
86
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
87
+ return resolve(parsedIni);
88
+ });
89
+ });
90
+ },
91
+ async _saveAsync(type, data) {
92
+ if (!paths_1.paths[type])
93
+ throw new Error(`Unknown config type: '${type}'`);
94
+ if (!data)
95
+ throw new Error(`You must provide data for saving.`);
96
+ debug(`Stringifying ${type} INI data`);
97
+ const text = ini_1.default.stringify(data);
98
+ debug(`Creating AWS config directory '${paths_1.paths.awsDir}' if not exists.`);
99
+ await (0, mkdirp_1.default)(paths_1.paths.awsDir);
100
+ debug(`Writing '${type}' INI to file '${paths_1.paths[type]}'`);
101
+ await writeFile(paths_1.paths[type], text);
102
+ },
103
+ };
@@ -0,0 +1,77 @@
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.configureProfileAsync = void 0;
7
+ const inquirer_1 = __importDefault(require("inquirer"));
8
+ const awsConfig_1 = require("./awsConfig");
9
+ async function configureProfileAsync(profileName) {
10
+ console.log(`Configuring profile '${profileName}'`);
11
+ const profile = await awsConfig_1.awsConfig.getProfileConfigAsync(profileName);
12
+ const questions = [
13
+ {
14
+ name: "tenantId",
15
+ message: "Azure Tenant ID:",
16
+ validate: (input) => !!input,
17
+ default: profile && profile.azure_tenant_id,
18
+ },
19
+ {
20
+ name: "appIdUri",
21
+ message: "Azure App ID URI:",
22
+ validate: (input) => !!input,
23
+ default: profile && profile.azure_app_id_uri,
24
+ },
25
+ {
26
+ name: "username",
27
+ message: "Default Username:",
28
+ default: profile && profile.azure_default_username,
29
+ },
30
+ {
31
+ name: "rememberMe",
32
+ message: "Stay logged in: skip authentication while refreshing aws credentials (true|false)",
33
+ default: (profile &&
34
+ profile.azure_default_remember_me &&
35
+ profile.azure_default_remember_me.toString()) ||
36
+ "false",
37
+ validate: (input) => {
38
+ if (input === "true" || input === "false")
39
+ return true;
40
+ return "Remember me must be either true or false";
41
+ },
42
+ },
43
+ {
44
+ name: "defaultRoleArn",
45
+ message: "Default Role ARN (if multiple):",
46
+ default: profile && profile.azure_default_role_arn,
47
+ },
48
+ {
49
+ name: "defaultDurationHours",
50
+ message: "Default Session Duration Hours (up to 12):",
51
+ default: (profile && profile.azure_default_duration_hours) || 1,
52
+ validate: (input) => {
53
+ input = Number(input);
54
+ if (input > 0 && input <= 12)
55
+ return true;
56
+ return "Duration hours must be between 0 and 12";
57
+ },
58
+ },
59
+ {
60
+ name: "region",
61
+ message: "AWS Region:",
62
+ default: profile && profile.region,
63
+ },
64
+ ];
65
+ const answers = await inquirer_1.default.prompt(questions);
66
+ await awsConfig_1.awsConfig.setProfileConfigValuesAsync(profileName, {
67
+ azure_tenant_id: answers.tenantId,
68
+ azure_app_id_uri: answers.appIdUri,
69
+ azure_default_username: answers.username,
70
+ azure_default_role_arn: answers.defaultRoleArn,
71
+ azure_default_duration_hours: answers.defaultDurationHours,
72
+ azure_default_remember_me: answers.rememberMe === "true",
73
+ region: answers.region,
74
+ });
75
+ console.log("Profile saved.");
76
+ }
77
+ exports.configureProfileAsync = configureProfileAsync;
package/lib/index.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ process.on("SIGINT", () => process.exit(1));
5
+ process.on("SIGTERM", () => process.exit(1));
6
+ const commander_1 = require("commander");
7
+ const configureProfileAsync_1 = require("./configureProfileAsync");
8
+ const login_1 = require("./login");
9
+ const program = new commander_1.Command();
10
+ program
11
+ .option("-p, --profile <name>", "The name of the profile to log in with (or configure)")
12
+ .option("-a, --all-profiles", "Run for all configured profiles")
13
+ .option("-f, --force-refresh", "Force a credential refresh, even if they are still valid")
14
+ .option("-c, --configure", "Configure the profile")
15
+ .option("-m, --mode <mode>", "'cli' to hide the login page and perform the login through the CLI (default behavior), 'gui' to perform the login through the Azure GUI (more reliable but only works on GUI operating system), 'debug' to show the login page but perform the login through the CLI (useful to debug issues with the CLI login)")
16
+ .option("--no-sandbox", "Disable the Puppeteer sandbox (usually necessary on Linux)")
17
+ .option("--no-prompt", "Do not prompt for input and accept the default choice", false)
18
+ .option("--enable-chrome-network-service", "Enable Chromium's Network Service (needed when login provider redirects with 3XX)")
19
+ .option("--no-verify-ssl", "Disable SSL Peer Verification for connections to AWS (no effect if behind proxy)")
20
+ .option("--enable-chrome-seamless-sso", "Enable Chromium's pass-through authentication with Azure Active Directory Seamless Single Sign-On")
21
+ .option("--no-disable-extensions", "Tell Puppeteer not to pass the --disable-extensions flag to Chromium")
22
+ .option("--disable-gpu", "Tell Puppeteer to pass the --disable-gpu flag to Chromium")
23
+ .parse(process.argv);
24
+ const options = program.opts();
25
+ const profileName = options.profile ||
26
+ process.env.AWS_PROFILE ||
27
+ "default";
28
+ const mode = options.mode || "cli";
29
+ const disableSandbox = !options.sandbox;
30
+ const noPrompt = !options.prompt;
31
+ const enableChromeNetworkService = !!options.enableChromeNetworkService;
32
+ const awsNoVerifySsl = !options.verifySsl;
33
+ const enableChromeSeamlessSso = !!options.enableChromeSeamlessSso;
34
+ const forceRefresh = !!options.forceRefresh;
35
+ const noDisableExtensions = !options.disableExtensions;
36
+ const disableGpu = !!options.disableGpu;
37
+ Promise.resolve()
38
+ .then(() => {
39
+ if (options.allProfiles) {
40
+ return login_1.login.loginAll(mode, disableSandbox, noPrompt, enableChromeNetworkService, awsNoVerifySsl, enableChromeSeamlessSso, forceRefresh, noDisableExtensions, disableGpu);
41
+ }
42
+ if (options.configure)
43
+ return (0, configureProfileAsync_1.configureProfileAsync)(profileName);
44
+ return login_1.login.loginAsync(profileName, mode, disableSandbox, noPrompt, enableChromeNetworkService, awsNoVerifySsl, enableChromeSeamlessSso, noDisableExtensions, disableGpu);
45
+ })
46
+ .catch((err) => {
47
+ if (err.name === "CLIError") {
48
+ console.error(err.message);
49
+ process.exit(2);
50
+ }
51
+ else {
52
+ console.log(err);
53
+ }
54
+ });