Skip to content

Commit c5fe5a3

Browse files
committed
add spinner using ora package
1 parent da47a8d commit c5fe5a3

File tree

3 files changed

+307
-14
lines changed

3 files changed

+307
-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+
};

0 commit comments

Comments
 (0)