-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUsers.ts
More file actions
103 lines (96 loc) · 3.05 KB
/
Copy pathUsers.ts
File metadata and controls
103 lines (96 loc) · 3.05 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import * as inquirer from "inquirer";
import {SDK} from "../ironnode";
import {log} from "./Logger";
/**
* Convert a string of comma separated IDs into an ID list accepted by the SDK
*/
function idListToAccessList(idList: string) {
if (!idList) {
return [];
}
return idList.split(",").map((id) => id.trim());
}
/**
* Displays a nicely formatted list of documents the user has access to
*/
function getFormattedDeviceList(IronNode: SDK) {
return inquirer.prompt<{id: number}>({
type: "list",
name: "id",
message: "What's the ID of the device?",
pageSize: 10,
choices: () => {
return IronNode.user.listDevices().then((devices) => {
const deviceInfo = devices.result.map((device) => ({
name: `${device.name} (${device.id})`,
value: device.id,
}));
return [...deviceInfo, new inquirer.Separator()];
});
},
});
}
/**
* Display a list of all groups the user is either an admin or a member of
*/
export function publicKeyLookup(IronNode: SDK) {
return inquirer
.prompt<{users: string}>([
{
name: "users",
type: "input",
message: "User IDs to lookup (comma seperate multiple IDs):",
},
])
.then(({users}) => IronNode.user.getPublicKey(idListToAccessList(users)))
.then(log);
}
/**
* Ask for the users escrow password and use it to rotate the users master private key.
*/
export function rotateMasterKey(IronNode: SDK) {
return inquirer
.prompt<{escrowPassword: string}>([
{
name: "escrowPassword",
type: "password",
message: "Enter accounts escrow password:",
},
])
.then(({escrowPassword}) => IronNode.user.rotateMasterKey(escrowPassword))
.then(log);
}
/**
* Get a users devices and display the results
*/
export function deviceList(IronNode: SDK) {
return IronNode.user.listDevices().then(log);
}
/**
* Delete a device. Gets the list of the users devices and lets the user pick one to delete
*/
export function deviceDelete(IronNode: SDK) {
return getFormattedDeviceList(IronNode)
.then(({id}) => IronNode.user.deleteDevice(id))
.then(log);
}
/**
* Ask user for the current and a new password and call into the SDK to change their password.
*/
export function changePassword(IronNode: SDK) {
return inquirer
.prompt<{currentPassword: string; newPassword: string}>([
{
name: "currentPassword",
type: "password",
message: "Enter current escrow password:",
},
{
name: "newPassword",
type: "password",
message: "Enter new escrow password:",
},
])
.then(({currentPassword, newPassword}) => IronNode.user.changePassword(currentPassword, newPassword))
.then(() => log("Password successfully changed"));
}