forked from aws-azure-login/aws-azure-login
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigureProfileAsync.ts
More file actions
72 lines (66 loc) · 2.29 KB
/
configureProfileAsync.ts
File metadata and controls
72 lines (66 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import inquirer, { Question } from "inquirer";
import { awsConfig } from "./awsConfig";
export async function configureProfileAsync(
profileName: string
): Promise<void> {
console.log(`Configuring profile '${profileName}'`);
const profile = await awsConfig.getProfileConfigAsync(profileName);
const questions: Question[] = [
{
name: "tenantId",
message: "Azure Tenant ID:",
validate: (input): boolean => !!input,
default: profile && profile.azure_tenant_id,
},
{
name: "appIdUri",
message: "Azure App ID URI:",
validate: (input): boolean => !!input,
default: profile && profile.azure_app_id_uri,
},
{
name: "username",
message: "Default Username:",
default: profile && profile.azure_default_username,
},
{
name: "rememberMe",
message:
"Stay logged in: skip authentication while refreshing aws credentials (true|false)",
default:
(profile &&
profile.azure_default_remember_me &&
profile.azure_default_remember_me.toString()) ||
"false",
validate: (input): boolean | string => {
if (input === "true" || input === "false") return true;
return "Remember me must be either true or false";
},
},
{
name: "defaultRoleArn",
message: "Default Role ARN (if multiple):",
default: profile && profile.azure_default_role_arn,
},
{
name: "defaultDurationHours",
message: "Default Session Duration Hours (up to 12):",
default: (profile && profile.azure_default_duration_hours) || 1,
validate: (input): boolean | string => {
input = Number(input);
if (input > 0 && input <= 12) return true;
return "Duration hours must be between 0 and 12";
},
},
];
const answers = await inquirer.prompt(questions);
await awsConfig.setProfileConfigValuesAsync(profileName, {
azure_tenant_id: answers.tenantId as string,
azure_app_id_uri: answers.appIdUri as string,
azure_default_username: answers.username as string,
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",
});
console.log("Profile saved.");
}