Skip to content

Commit

Permalink
Merge pull request #311 from Naicigam28/main
Browse files Browse the repository at this point in the history
Updating workflow and adding region config
  • Loading branch information
Naicigam28 committed Dec 14, 2023
2 parents 731152c + e0295f5 commit f420de2
Show file tree
Hide file tree
Showing 8 changed files with 4,554 additions and 2,659 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: 18
- run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -25,8 +25,8 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: lib
path: lib
Expand Down
4,527 changes: 4,527 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "aws-azure-login",
"version": "3.6.2",
"version": "3.6.3",
"description": "Use Azure AD SSO to log into the AWS CLI.",
"main": "index.js",
"author": {
Expand Down Expand Up @@ -29,8 +29,8 @@
"test": "yarn eslint && yarn prettier:check"
},
"dependencies": {
"@aws-sdk/client-sts": "^3.328.0",
"@aws-sdk/node-http-handler": "^3.328.0",
"@aws-sdk/client-sts": "^3.473.0",
"@smithy/node-http-handler": "^2.2.1",
"bluebird": "^3.7.2",
"cheerio": "^1.0.0-rc.10",
"commander": "^9.2.0",
Expand All @@ -51,14 +51,14 @@
"@types/inquirer": "^8.2.1",
"@types/lodash": "^4.14.170",
"@types/mkdirp": "^1.0.1",
"@types/node": "^17.0.26",
"@types/node": "^20.10.4",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.3.0",
"prettier": "^2.6.2",
"ts-node-dev": "^1.1.1",
"typescript": "^4.6.3"
"typescript": "^5.3.3"
}
}
8 changes: 6 additions & 2 deletions src/awsConfig.ts
Expand Up @@ -19,7 +19,7 @@ export interface ProfileConfig {
azure_default_password?: string;
azure_default_role_arn: string;
azure_default_duration_hours: string;
region?: string;
region: string;
azure_default_remember_me: boolean;
[key: string]: unknown;
}
Expand All @@ -31,6 +31,10 @@ interface ProfileCredentials {
aws_expiration: string;
}

interface SaveData {
[key: string]: ProfileConfig | ProfileCredentials;
}

export const awsConfig = {
async setProfileConfigValuesAsync(
profileName: string,
Expand Down Expand Up @@ -149,7 +153,7 @@ export const awsConfig = {
});
},

async _saveAsync(type: string, data: unknown): Promise<void> {
async _saveAsync(type: string, data: SaveData): Promise<void> {
if (!paths[type]) throw new Error(`Unknown config type: '${type}'`);
if (!data) throw new Error(`You must provide data for saving.`);

Expand Down
6 changes: 6 additions & 0 deletions src/configureProfileAsync.ts
Expand Up @@ -55,6 +55,11 @@ export async function configureProfileAsync(
return "Duration hours must be between 0 and 12";
},
},
{
name: "region",
message: "AWS Region:",
default: profile && profile.region,
},
];

const answers = await inquirer.prompt(questions);
Expand All @@ -66,6 +71,7 @@ export async function configureProfileAsync(
azure_default_role_arn: answers.defaultRoleArn as string,
azure_default_duration_hours: answers.defaultDurationHours as string,
azure_default_remember_me: (answers.rememberMe as string) === "true",
region: answers.region as string,
});

console.log("Profile saved.");
Expand Down
8 changes: 5 additions & 3 deletions src/login.ts
Expand Up @@ -14,7 +14,7 @@ import proxy from "proxy-agent";
import { paths } from "./paths";
import mkdirp from "mkdirp";
import { Agent } from "https";
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
import { NodeHttpHandler } from "@smithy/node-http-handler";

const debug = _debug("aws-azure-login");

Expand Down Expand Up @@ -501,6 +501,7 @@ export const login = {
profile.azure_default_role_arn,
profile.azure_default_duration_hours
);

await this._assumeRoleAsync(
profileName,
samlResponse,
Expand Down Expand Up @@ -586,6 +587,7 @@ export const login = {
// Load the profile
async _loadProfileAsync(profileName: string): Promise<ProfileConfig> {
const profile = await awsConfig.getProfileConfigAsync(profileName);

if (!profile)
throw new CLIError(
`Unknown profile '${profileName}'. You must configure it first with --configure.`
Expand Down Expand Up @@ -1008,9 +1010,9 @@ export const login = {
role: Role,
durationHours: number,
awsNoVerifySsl: boolean,
region: string | undefined
region: string
): Promise<void> {
console.log(`Assuming role ${role.roleArn}`);
console.log(`Assuming role ${role.roleArn} in region ${region}...`);
let stsOptions: STSClientConfig = {};
if (process.env.https_proxy) {
stsOptions = {
Expand Down

0 comments on commit f420de2

Please sign in to comment.