opal-security 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -25
- package/lib/commands/login.js +8 -1
- package/lib/commands/request/create.d.ts +2 -0
- package/lib/commands/request/create.js +41 -20
- package/lib/commands/request/get.js +5 -57
- package/lib/commands/request/list.js +3 -60
- package/lib/graphql/gql.d.ts +35 -15
- package/lib/graphql/gql.js +9 -5
- package/lib/graphql/graphql.d.ts +286 -228
- package/lib/graphql/graphql.js +1674 -1095
- package/lib/labels.d.ts +3 -0
- package/lib/labels.js +37 -0
- package/lib/lib/request/api/index.d.ts +6 -0
- package/lib/lib/request/api/index.js +20 -0
- package/lib/lib/request/api/mutations/create-request.d.ts +8 -0
- package/lib/lib/request/api/mutations/create-request.js +159 -0
- package/lib/lib/request/api/queries/apps.d.ts +4 -0
- package/lib/lib/request/api/queries/apps.js +73 -0
- package/lib/lib/request/api/queries/assets.d.ts +6 -0
- package/lib/lib/request/api/queries/assets.js +136 -0
- package/lib/lib/request/api/queries/request-defaults.d.ts +5 -0
- package/lib/lib/request/api/queries/request-defaults.js +51 -0
- package/lib/lib/request/api/queries/requests.d.ts +4 -0
- package/lib/lib/request/api/queries/requests.js +163 -0
- package/lib/lib/request/api/queries/roles.d.ts +5 -0
- package/lib/lib/request/api/queries/roles.js +239 -0
- package/lib/{utils → lib/request}/displays.d.ts +4 -2
- package/lib/{utils → lib/request}/displays.js +41 -19
- package/lib/lib/request/prompts/apps-prompt.d.ts +4 -0
- package/lib/lib/request/prompts/apps-prompt.js +35 -0
- package/lib/lib/request/prompts/asset-prompt.d.ts +5 -0
- package/lib/lib/request/prompts/asset-prompt.js +81 -0
- package/lib/lib/request/prompts/duration-prompt.d.ts +2 -0
- package/lib/lib/request/prompts/duration-prompt.js +122 -0
- package/lib/lib/request/prompts/index.d.ts +8 -0
- package/lib/lib/request/prompts/index.js +20 -0
- package/lib/lib/request/prompts/reason-prompt.d.ts +2 -0
- package/lib/lib/request/prompts/reason-prompt.js +20 -0
- package/lib/lib/request/prompts/role-prompt.d.ts +4 -0
- package/lib/lib/request/prompts/role-prompt.js +44 -0
- package/lib/lib/request/prompts/validate-prompt.d.ts +4 -0
- package/lib/lib/request/prompts/validate-prompt.js +29 -0
- package/lib/lib/request/request-utils.d.ts +15 -0
- package/lib/lib/request/request-utils.js +467 -0
- package/lib/lib/request/types.d.ts +55 -0
- package/lib/lib/request/types.js +15 -0
- package/lib/lib/util.d.ts +1 -0
- package/lib/lib/util.js +16 -0
- package/lib/types.d.ts +19 -3
- package/lib/types.js +18 -2
- package/oclif.manifest.json +54 -38
- package/package.json +1 -1
- package/lib/lib/requests.d.ts +0 -54
- package/lib/lib/requests.js +0 -1160
- package/lib/utils/utils.d.ts +0 -1
- package/lib/utils/utils.js +0 -18
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptForDuration = promptForDuration;
|
|
4
|
+
const { AutoComplete, Form } = require("enquirer");
|
|
5
|
+
async function promptForDuration(metadata) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const durations = ((_b = (_a = metadata.requestDefaults) === null || _a === void 0 ? void 0 : _a.durationOptions) === null || _b === void 0 ? void 0 : _b.map((option) => {
|
|
8
|
+
var _a;
|
|
9
|
+
let label = option.label;
|
|
10
|
+
if (option.durationInMinutes ===
|
|
11
|
+
((_a = metadata.requestDefaults) === null || _a === void 0 ? void 0 : _a.maxDurationInMinutes)) {
|
|
12
|
+
label = `${label} (MAX)`;
|
|
13
|
+
}
|
|
14
|
+
if (option.durationInMinutes ===
|
|
15
|
+
metadata.requestDefaults.recommendedDurationInMinutes) {
|
|
16
|
+
label = `${label} (RECOMMENDED)`;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
message: label,
|
|
20
|
+
value: {
|
|
21
|
+
label: label,
|
|
22
|
+
durationInMinutes: option.durationInMinutes,
|
|
23
|
+
toString: () => label,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
})) || [];
|
|
27
|
+
// Sort durations by minutes
|
|
28
|
+
durations.sort((a, b) => {
|
|
29
|
+
// Sort so that Permanent is always last
|
|
30
|
+
if (a.message === "Permanent")
|
|
31
|
+
return 1;
|
|
32
|
+
if (b.message === "Permanent")
|
|
33
|
+
return -1;
|
|
34
|
+
return a.value.durationInMinutes - b.value.durationInMinutes;
|
|
35
|
+
});
|
|
36
|
+
const expirationSelect = new AutoComplete({
|
|
37
|
+
name: "expiration",
|
|
38
|
+
message: "When should access expire?",
|
|
39
|
+
hint: "Type to filter",
|
|
40
|
+
type: "list",
|
|
41
|
+
choices: durations,
|
|
42
|
+
pageSize: 15,
|
|
43
|
+
});
|
|
44
|
+
let selected = await expirationSelect.run();
|
|
45
|
+
switch (selected.label) {
|
|
46
|
+
case "Custom": {
|
|
47
|
+
selected = await setCustomDuration(metadata);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "Permanent": {
|
|
51
|
+
selected.durationInMinutes = undefined;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
metadata.durationInMinutes = selected.durationInMinutes;
|
|
56
|
+
metadata.durationLabel = selected.label;
|
|
57
|
+
}
|
|
58
|
+
function getDurationNumbers(duration) {
|
|
59
|
+
const d = +duration.days || 0;
|
|
60
|
+
const h = +duration.hours || 0;
|
|
61
|
+
const m = +duration.minutes || 0;
|
|
62
|
+
return { d, h, m };
|
|
63
|
+
}
|
|
64
|
+
function getDurationInMinutes(duration) {
|
|
65
|
+
const { d, h, m } = getDurationNumbers(duration);
|
|
66
|
+
const minutesInDay = 1440; // 24 hours * 60 minutes
|
|
67
|
+
const minutesInHour = 60;
|
|
68
|
+
return d * minutesInDay + h * minutesInHour + m;
|
|
69
|
+
}
|
|
70
|
+
function getDHMFromMinutes(minutes) {
|
|
71
|
+
const label = [];
|
|
72
|
+
const d = Math.floor(minutes / 1440);
|
|
73
|
+
if (d > 0) {
|
|
74
|
+
label.push(`${d}d`);
|
|
75
|
+
}
|
|
76
|
+
const remainingMinutes = minutes % 1440;
|
|
77
|
+
const h = Math.floor(remainingMinutes / 60);
|
|
78
|
+
if (h > 0) {
|
|
79
|
+
label.push(`${h}h`);
|
|
80
|
+
}
|
|
81
|
+
const m = remainingMinutes % 60;
|
|
82
|
+
if (m > 0) {
|
|
83
|
+
label.push(`${m}m`);
|
|
84
|
+
}
|
|
85
|
+
return label.join(" ");
|
|
86
|
+
}
|
|
87
|
+
async function setCustomDuration(metadata) {
|
|
88
|
+
const durationForm = new Form({
|
|
89
|
+
name: "user",
|
|
90
|
+
message: "Please set a custom access duration:",
|
|
91
|
+
choices: [
|
|
92
|
+
{ name: "days", message: "Days", initial: "0" },
|
|
93
|
+
{ name: "hours", message: "Hours", initial: "0" },
|
|
94
|
+
{ name: "minutes", message: "Minutes", initial: "0" },
|
|
95
|
+
],
|
|
96
|
+
validate: (answer) => {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
const { d, h, m } = getDurationNumbers(answer);
|
|
99
|
+
const durationInMinutes = getDurationInMinutes(answer);
|
|
100
|
+
if (d < 0 || h < 0 || m < 0 || d + h + m === 0 || (h > 23 && m > 59)) {
|
|
101
|
+
return "Please enter a valid duration.";
|
|
102
|
+
}
|
|
103
|
+
if (((_a = metadata.requestDefaults) === null || _a === void 0 ? void 0 : _a.maxDurationInMinutes) &&
|
|
104
|
+
durationInMinutes > ((_b = metadata.requestDefaults) === null || _b === void 0 ? void 0 : _b.maxDurationInMinutes)) {
|
|
105
|
+
const maxDHM = getDHMFromMinutes((_c = metadata.requestDefaults) === null || _c === void 0 ? void 0 : _c.maxDurationInMinutes);
|
|
106
|
+
return `The max duration for the selected assets is ${maxDHM}.`;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
return: (answer) => {
|
|
111
|
+
return getDurationInMinutes(answer);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const durationResult = await durationForm.run();
|
|
115
|
+
const { d, h, m } = getDurationNumbers(durationResult);
|
|
116
|
+
const durationInMinutes = getDurationInMinutes(durationResult);
|
|
117
|
+
const durationLabel = getDHMFromMinutes(durationInMinutes);
|
|
118
|
+
return {
|
|
119
|
+
durationInMinutes: durationInMinutes,
|
|
120
|
+
label: durationLabel,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { selectRequestableItems } from "./apps-prompt";
|
|
2
|
+
export { chooseOktaAzureRoles, chooseAssets } from "./asset-prompt";
|
|
3
|
+
export { chooseRoles } from "./role-prompt";
|
|
4
|
+
export { promptForReason } from "./reason-prompt";
|
|
5
|
+
export { promptForDuration } from "./duration-prompt";
|
|
6
|
+
export { doneSelectingAssets, promptRequestSubmission, } from "./validate-prompt";
|
|
7
|
+
export declare const selectInstructions: string;
|
|
8
|
+
export declare const multiSelectInstructions: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.multiSelectInstructions = exports.selectInstructions = exports.promptRequestSubmission = exports.doneSelectingAssets = exports.promptForDuration = exports.promptForReason = exports.chooseRoles = exports.chooseAssets = exports.chooseOktaAzureRoles = exports.selectRequestableItems = void 0;
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
var apps_prompt_1 = require("./apps-prompt");
|
|
6
|
+
Object.defineProperty(exports, "selectRequestableItems", { enumerable: true, get: function () { return apps_prompt_1.selectRequestableItems; } });
|
|
7
|
+
var asset_prompt_1 = require("./asset-prompt");
|
|
8
|
+
Object.defineProperty(exports, "chooseOktaAzureRoles", { enumerable: true, get: function () { return asset_prompt_1.chooseOktaAzureRoles; } });
|
|
9
|
+
Object.defineProperty(exports, "chooseAssets", { enumerable: true, get: function () { return asset_prompt_1.chooseAssets; } });
|
|
10
|
+
var role_prompt_1 = require("./role-prompt");
|
|
11
|
+
Object.defineProperty(exports, "chooseRoles", { enumerable: true, get: function () { return role_prompt_1.chooseRoles; } });
|
|
12
|
+
var reason_prompt_1 = require("./reason-prompt");
|
|
13
|
+
Object.defineProperty(exports, "promptForReason", { enumerable: true, get: function () { return reason_prompt_1.promptForReason; } });
|
|
14
|
+
var duration_prompt_1 = require("./duration-prompt");
|
|
15
|
+
Object.defineProperty(exports, "promptForDuration", { enumerable: true, get: function () { return duration_prompt_1.promptForDuration; } });
|
|
16
|
+
var validate_prompt_1 = require("./validate-prompt");
|
|
17
|
+
Object.defineProperty(exports, "doneSelectingAssets", { enumerable: true, get: function () { return validate_prompt_1.doneSelectingAssets; } });
|
|
18
|
+
Object.defineProperty(exports, "promptRequestSubmission", { enumerable: true, get: function () { return validate_prompt_1.promptRequestSubmission; } });
|
|
19
|
+
exports.selectInstructions = chalk_1.default.dim("[↑↓] Navigate · [Enter] Select · Type to filter");
|
|
20
|
+
exports.multiSelectInstructions = chalk_1.default.dim("[↑↓] Navigate · [Space] Select · [Enter] Confirm · Type to filter");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptForReason = promptForReason;
|
|
4
|
+
const { prompt } = require("enquirer");
|
|
5
|
+
async function promptForReason(metadata) {
|
|
6
|
+
const { reason } = await prompt([
|
|
7
|
+
{
|
|
8
|
+
name: "reason",
|
|
9
|
+
message: "Why do you need access?",
|
|
10
|
+
type: "input",
|
|
11
|
+
validate: (answer) => {
|
|
12
|
+
if (!metadata.requestDefaults.reasonOptional && answer.length < 1) {
|
|
13
|
+
return "A reason for requesting these assets is required.";
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
metadata.reason = reason;
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ApolloClient, NormalizedCacheObject } from "@apollo/client";
|
|
2
|
+
import type { Command } from "@oclif/core";
|
|
3
|
+
import type { RequestMap } from "../types";
|
|
4
|
+
export declare function chooseRoles(cmd: Command, client: ApolloClient<NormalizedCacheObject>, appId: string, assetId: string, requestMap: RequestMap): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chooseRoles = chooseRoles;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const { AutoComplete } = require("enquirer");
|
|
7
|
+
async function chooseRoles(cmd, client, appId, assetId, requestMap) {
|
|
8
|
+
var _a;
|
|
9
|
+
const entry = requestMap[appId];
|
|
10
|
+
const assetEntry = entry === null || entry === void 0 ? void 0 : entry.assets[assetId];
|
|
11
|
+
if (entry === undefined || assetEntry === undefined) {
|
|
12
|
+
throw new Error(`App ${appId} or Asset ${assetId} not found in requestMap`);
|
|
13
|
+
}
|
|
14
|
+
const assetRoles = (_a = (await (0, api_1.queryAssetRoles)(cmd, client, assetEntry.type, assetId))) !== null && _a !== void 0 ? _a : [];
|
|
15
|
+
if (assetRoles !== undefined &&
|
|
16
|
+
(assetRoles.length === 0 ||
|
|
17
|
+
(assetRoles.length === 1 && assetRoles[0].value.name === ""))) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const rolePrompt = new AutoComplete({
|
|
21
|
+
name: "Roles",
|
|
22
|
+
message: `Select one or more roles for ${assetEntry.assetName}:`,
|
|
23
|
+
hint: _1.multiSelectInstructions,
|
|
24
|
+
limit: 15,
|
|
25
|
+
multiple: true,
|
|
26
|
+
choices: assetRoles,
|
|
27
|
+
validate: (answer) => {
|
|
28
|
+
if (answer.length < 1) {
|
|
29
|
+
return "You must select at least one item.";
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const roles = await rolePrompt.run();
|
|
35
|
+
if (!assetEntry.roles) {
|
|
36
|
+
assetEntry.roles = {};
|
|
37
|
+
}
|
|
38
|
+
for (const role of roles) {
|
|
39
|
+
assetEntry.roles[role.id] = {
|
|
40
|
+
roleId: role.id,
|
|
41
|
+
roleName: role.name,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.doneSelectingAssets = doneSelectingAssets;
|
|
4
|
+
exports.promptRequestSubmission = promptRequestSubmission;
|
|
5
|
+
const displays_1 = require("../displays");
|
|
6
|
+
const { Select } = require("enquirer");
|
|
7
|
+
async function doneSelectingAssets() {
|
|
8
|
+
const submitMessage = "✅ Yes, proceed with request";
|
|
9
|
+
const addMoreMessage = "❌ No, add more items";
|
|
10
|
+
const prompt = new Select({
|
|
11
|
+
name: "submitOrAdd",
|
|
12
|
+
message: "Is this all you want to request?",
|
|
13
|
+
choices: [submitMessage, addMoreMessage],
|
|
14
|
+
});
|
|
15
|
+
const submitOrAdd = await prompt.run();
|
|
16
|
+
return submitOrAdd === submitMessage;
|
|
17
|
+
}
|
|
18
|
+
async function promptRequestSubmission(cmd, metadata) {
|
|
19
|
+
(0, displays_1.displayFinalRequestSummary)(cmd, metadata);
|
|
20
|
+
const submitMessage = "✅ Yes, submit request";
|
|
21
|
+
const cancelMessage = "❌ No, cancel request";
|
|
22
|
+
const prompt = new Select({
|
|
23
|
+
name: "submitOrCancel",
|
|
24
|
+
message: "Is this all you want to request?",
|
|
25
|
+
choices: [submitMessage, cancelMessage],
|
|
26
|
+
});
|
|
27
|
+
const submitOrCancel = await prompt.run();
|
|
28
|
+
return submitOrCancel === submitMessage;
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApolloClient, NormalizedCacheObject } from "@apollo/client";
|
|
2
|
+
import type { Command } from "@oclif/core";
|
|
3
|
+
import { RequestMessageCode } from "../../graphql/graphql";
|
|
4
|
+
import { type ConnectionType } from "../../types";
|
|
5
|
+
import { type RequestMap, type RequestMetadata } from "./types";
|
|
6
|
+
export declare function initEmptyRequestMetadata(): RequestMetadata;
|
|
7
|
+
export declare function setRequestDefaults(cmd: Command, client: ApolloClient<NormalizedCacheObject>, metadata: RequestMetadata): Promise<void>;
|
|
8
|
+
export declare function submitFinalRequest(cmd: Command, client: ApolloClient<NormalizedCacheObject>, metadata: RequestMetadata): Promise<void>;
|
|
9
|
+
export declare function getRequestLink(cmd: Command, id: string): string;
|
|
10
|
+
export declare function generateRequestLink(cmd: Command, defaultDurationInMinutes: number): string;
|
|
11
|
+
export declare function bypassRequestSelection(cmd: Command, client: ApolloClient<NormalizedCacheObject>, flagValue: string[], metadata: RequestMetadata): Promise<void>;
|
|
12
|
+
export declare function bypassDuration(cmd: Command, duration: number, metadata: RequestMetadata): void;
|
|
13
|
+
export declare function getRequestMessageFromCode(cmd: Command, code: RequestMessageCode, connectionName: string | undefined, connectionType: ConnectionType | undefined, extraParams?: string, sourceGroupRedirect?: () => void): string;
|
|
14
|
+
export declare function duplicateRequestTemplate(cmd: Command, client: ApolloClient<NormalizedCacheObject>, requestId: string, metadata: RequestMetadata): Promise<void>;
|
|
15
|
+
export declare function copyBundleAssets(cmd: Command, client: ApolloClient<NormalizedCacheObject>, bundleId: string, requestMap: RequestMap): Promise<void>;
|