Skip to content

Commit bbf8ec2

Browse files
authored
Merge pull request #1 from codeeno/add-spinner
Add spinner
2 parents da47a8d + 742d4a3 commit bbf8ec2

File tree

4 files changed

+310
-14
lines changed

4 files changed

+310
-14
lines changed

lib/aws.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
11
import AWS from "aws-sdk";
22
import os from "os";
3+
import ora from "ora";
34

45
export const createAWSClient = (region) => ({
56
SSOOIDC: new AWS.SSOOIDC({ region: region }),
67
SSO: new AWS.SSO({ region: region }),
78
});
89

9-
export const registerClient = async (AWSClient) =>
10-
await AWSClient.SSOOIDC.registerClient({
10+
export const registerClient = async (AWSClient) => {
11+
const spinner = ora("Registering client..").start();
12+
const client = await AWSClient.SSOOIDC.registerClient({
1113
clientName: os.hostname(),
1214
clientType: "public",
1315
}).promise();
16+
spinner.stop();
17+
return client;
18+
};
1419

15-
export const startDeviceAuthorization = async (clientId, clientSecret, startUrl, AWSClient) =>
16-
await AWSClient.SSOOIDC.startDeviceAuthorization({
20+
export const startDeviceAuthorization = async (clientId, clientSecret, startUrl, AWSClient) => {
21+
const spinner = ora("Starting device authorization..").start();
22+
const auth = await AWSClient.SSOOIDC.startDeviceAuthorization({
1723
clientId: clientId,
1824
clientSecret: clientSecret,
1925
startUrl: startUrl,
2026
}).promise();
27+
spinner.stop();
28+
return auth;
29+
};
2130

22-
export const createToken = async (clientId, clientSecret, deviceCode, AWSClient) =>
23-
await AWSClient.SSOOIDC.createToken({
31+
export const createToken = async (clientId, clientSecret, deviceCode, AWSClient) => {
32+
const spinner = ora("Creating token..").start();
33+
const token = await AWSClient.SSOOIDC.createToken({
2434
clientId: clientId,
2535
clientSecret: clientSecret,
2636
deviceCode: deviceCode,
2737
grantType: "urn:ietf:params:oauth:grant-type:device_code",
2838
}).promise();
39+
spinner.stop();
40+
return token;
41+
};
2942

30-
export const listAccounts = async (accessToken, nextToken, AWSClient) =>
31-
await AWSClient.SSO.listAccounts({
43+
export const listAccounts = async (accessToken, nextToken, AWSClient) => {
44+
const spinner = ora("Fetching accounts..").start();
45+
const accounts = await AWSClient.SSO.listAccounts({
3246
maxResults: 500,
3347
accessToken: accessToken,
3448
nextToken: nextToken,
3549
}).promise();
50+
spinner.stop();
51+
return accounts;
52+
};
3653

37-
export const listAccountRoles = async (accessToken, accountId, nextToken, AWSClient) =>
38-
await AWSClient.SSO.listAccountRoles({
54+
export const listAccountRoles = async (accessToken, accountId, nextToken, AWSClient) => {
55+
const spinner = ora("Fetching roles..").start();
56+
const roles = await AWSClient.SSO.listAccountRoles({
3957
accessToken: accessToken,
4058
accountId: accountId,
4159
nextToken: nextToken,
4260
}).promise();
61+
spinner.stop();
62+
return roles;
63+
};
4364

44-
export const getRoleCredentials = async (accessToken, accountId, roleName, AWSClient) =>
45-
await AWSClient.SSO.getRoleCredentials({
65+
export const getRoleCredentials = async (accessToken, accountId, roleName, AWSClient) => {
66+
const spinner = ora("Fetching credentials..").start();
67+
const credentials = await AWSClient.SSO.getRoleCredentials({
4668
accessToken: accessToken,
4769
accountId: accountId,
4870
roleName: roleName,
4971
}).promise();
72+
spinner.stop();
73+
return credentials;
74+
};

lib/web.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from "axios";
22
import os from "os";
3+
import ora from "ora";
34
import { buildError } from "./error.js";
45

56
const buildURLQuery = (obj) =>
@@ -12,6 +13,7 @@ export const getSigninUrl = async (accessKeyId, secretAccessKey, sessionToken) =
1213
const destinationUrl = `https://console.aws.amazon.com/console/home`;
1314

1415
try {
16+
const spinner = ora("Fetching sign-in URL..").start();
1517
const response = await axios.get(federationUrl, {
1618
params: {
1719
Action: "getSigninToken",
@@ -30,6 +32,7 @@ export const getSigninUrl = async (accessKeyId, secretAccessKey, sessionToken) =
3032
SigninToken: encodeURI(response?.data?.SigninToken),
3133
});
3234

35+
spinner.stop();
3336
return `${federationUrl}?${urlParams}`;
3437
} catch (err) {
3538
throw buildError("ERR_GET_SIGNIN_URL", `${err}`);

0 commit comments

Comments
 (0)