microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4afa9def43e6485764446bdc6a5310fcc5d54fff

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

ts/tools/scripts/elevate.js

70lines · modecode

1#!/usr/bin/env node
2// Copyright (c) Microsoft Corporation.
3// Licensed under the MIT License.
4
5const config = require("./elevate.config.json");
6
7async function elevate(startDateTime) {
8 const { getClient } = await import("./lib/pimClient.mjs");
9
10 // get PIM client
11 const client = await getClient();
12
13 // elevate
14 await config.forEach((element) => {
15 var v = client.elevate({
16 requestType: element.properties.RequestType,
17 roleName: element.roleName,
18 expirationType: element.properties.ScheduleInfo.Expiration.Type,
19 expirationDuration:
20 element.properties.ScheduleInfo.Expiration.Duration,
21 startDateTime: startDateTime,
22 });
23 });
24}
25
26(async () => {
27 const command = process.argv[2];
28 switch (command) {
29 case "help":
30 console.log("elevate");
31 console.log(
32 "Uses the logged in account to elevate. Will prompt for login if the user is not logged in.",
33 );
34 console.log("Uses configuration from elevate.config.json.");
35 return;
36 default:
37 let date = new Date();
38 if (command == "tomorrow_morning") {
39 date.setDate(date.getDate() + 1);
40 date.setHours(8, 0, 0);
41 } else {
42 try {
43 date = new Date(Date.parse(command));
44 } catch {
45 console.log(
46 `Unable to parse date '${command}'. The expected format is '2024-09-30T09:01:00'`,
47 );
48 return;
49 }
50 }
51
52 await elevate(date.toISOString());
53 break;
54 }
55})().catch((e) => {
56 if (
57 e.message.includes(
58 "'az' is not recognized as an internal or external command",
59 )
60 ) {
61 console.error(
62 `ERROR: Azure CLI is not installed. Install it and run 'az login' before running this tool.`,
63 );
64
65 exit(0);
66 }
67
68 console.error(`FATAL ERROR: ${e.stack}`);
69 process.exit(-1);
70});