opal-security 3.2.3 → 4.0.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 +46 -61
- package/bin/dev +5 -5
- package/bin/run +2 -4
- package/build/commands/aws/identity.js +16 -0
- package/build/commands/clear-auth-config.d.ts +6 -0
- package/build/commands/clear-auth-config.js +22 -0
- package/{lib → build}/commands/groups/get.js +14 -16
- package/{lib → build}/commands/iam-roles/start.js +28 -30
- package/build/commands/kube-roles/start.js +71 -0
- package/{lib → build}/commands/login.d.ts +1 -0
- package/build/commands/login.js +379 -0
- package/build/commands/logout.js +22 -0
- package/{lib → build}/commands/postgres-instances/start.js +25 -27
- package/{lib → build}/commands/request/create.js +34 -36
- package/{lib → build}/commands/request/get.js +22 -24
- package/{lib → build}/commands/request/list.js +17 -19
- package/{lib → build}/commands/resources/get.js +15 -18
- package/build/commands/set-auth-config.d.ts +11 -0
- package/build/commands/set-auth-config.js +59 -0
- package/build/commands/set-custom-header.js +35 -0
- package/{lib → build}/commands/set-token.js +15 -17
- package/{lib → build}/commands/set-url.js +26 -28
- package/{lib → build}/commands/ssh/copyFrom.js +22 -24
- package/{lib → build}/commands/ssh/copyTo.js +22 -24
- package/{lib → build}/commands/ssh/start.js +30 -33
- package/build/commands/whoami.js +27 -0
- package/{lib → build}/graphql/fragment-masking.d.ts +1 -1
- package/{lib → build}/graphql/fragment-masking.js +3 -8
- package/{lib → build}/graphql/gql.d.ts +1 -1
- package/{lib → build}/graphql/gql.js +2 -5
- package/{lib → build}/graphql/graphql.js +256 -261
- package/build/graphql/index.d.ts +2 -0
- package/build/graphql/index.js +2 -0
- package/{lib → build}/handler.d.ts +1 -1
- package/build/handler.js +36 -0
- package/build/index.js +1 -0
- package/{lib → build}/labels.d.ts +1 -1
- package/build/labels.js +37 -0
- package/{lib → build}/lib/apollo.d.ts +2 -2
- package/{lib → build}/lib/apollo.js +62 -69
- package/build/lib/auth-success-template.d.ts +3 -0
- package/build/lib/auth-success-template.js +149 -0
- package/{lib → build}/lib/aws.js +2 -7
- package/{lib → build}/lib/cmd.d.ts +4 -4
- package/{lib → build}/lib/cmd.js +16 -20
- package/build/lib/config.js +46 -0
- package/{lib → build}/lib/credentials/index.d.ts +3 -2
- package/build/lib/credentials/index.js +85 -0
- package/{lib → build}/lib/credentials/keychain.js +4 -10
- package/{lib → build}/lib/credentials/localEncryption.js +12 -17
- package/{lib → build}/lib/flags.js +7 -10
- package/build/lib/local-auth-server.d.ts +5 -0
- package/build/lib/local-auth-server.js +69 -0
- package/build/lib/request/api/index.d.ts +6 -0
- package/build/lib/request/api/index.js +8 -0
- package/{lib → build}/lib/request/api/mutations/create-request.d.ts +2 -2
- package/{lib → build}/lib/request/api/mutations/create-request.js +3 -6
- package/{lib → build}/lib/request/api/queries/apps.d.ts +1 -1
- package/{lib → build}/lib/request/api/queries/apps.js +3 -6
- package/{lib → build}/lib/request/api/queries/assets.d.ts +2 -2
- package/{lib → build}/lib/request/api/queries/assets.js +7 -11
- package/{lib → build}/lib/request/api/queries/request-defaults.d.ts +2 -2
- package/{lib → build}/lib/request/api/queries/request-defaults.js +3 -6
- package/{lib → build}/lib/request/api/queries/requests.d.ts +3 -3
- package/{lib → build}/lib/request/api/queries/requests.js +10 -16
- package/{lib → build}/lib/request/api/queries/roles.d.ts +1 -1
- package/{lib → build}/lib/request/api/queries/roles.js +14 -18
- package/{lib → build}/lib/request/displays.d.ts +2 -2
- package/{lib → build}/lib/request/displays.js +27 -37
- package/{lib → build}/lib/request/prompts/apps-prompt.d.ts +1 -1
- package/build/lib/request/prompts/apps-prompt.js +33 -0
- package/{lib → build}/lib/request/prompts/asset-prompt.d.ts +1 -1
- package/build/lib/request/prompts/asset-prompt.js +61 -0
- package/{lib → build}/lib/request/prompts/duration-prompt.d.ts +1 -1
- package/{lib → build}/lib/request/prompts/duration-prompt.js +6 -10
- package/build/lib/request/prompts/index.d.ts +7 -0
- package/build/lib/request/prompts/index.js +8 -0
- package/{lib → build}/lib/request/prompts/reason-prompt.d.ts +1 -1
- package/{lib → build}/lib/request/prompts/reason-prompt.js +3 -6
- package/{lib → build}/lib/request/prompts/role-prompt.d.ts +1 -1
- package/build/lib/request/prompts/role-prompt.js +33 -0
- package/{lib → build}/lib/request/prompts/validate-prompt.d.ts +1 -1
- package/{lib → build}/lib/request/prompts/validate-prompt.js +9 -13
- package/{lib → build}/lib/request/request-utils.d.ts +2 -2
- package/{lib → build}/lib/request/request-utils.js +50 -62
- package/{lib → build}/lib/request/types.d.ts +1 -1
- package/build/lib/request/types.js +12 -0
- package/{lib → build}/lib/resources.d.ts +1 -1
- package/{lib → build}/lib/resources.js +18 -23
- package/{lib → build}/lib/sessions.d.ts +1 -1
- package/{lib → build}/lib/sessions.js +57 -32
- package/{lib → build}/lib/ssh.d.ts +1 -1
- package/{lib → build}/lib/ssh.js +6 -11
- package/{lib → build}/lib/util.js +7 -14
- package/{lib → build}/types.js +98 -101
- package/oclif.manifest.json +77 -98
- package/package.json +24 -14
- package/lib/commands/aws/identity.js +0 -18
- package/lib/commands/clear-auth-provider.d.ts +0 -9
- package/lib/commands/clear-auth-provider.js +0 -28
- package/lib/commands/curl-example.d.ts +0 -8
- package/lib/commands/curl-example.js +0 -34
- package/lib/commands/kube-roles/start.js +0 -73
- package/lib/commands/login.js +0 -286
- package/lib/commands/logout.js +0 -23
- package/lib/commands/set-auth-provider.d.ts +0 -11
- package/lib/commands/set-auth-provider.js +0 -44
- package/lib/commands/set-custom-header.js +0 -37
- package/lib/commands/whoami.js +0 -34
- package/lib/graphql/index.d.ts +0 -2
- package/lib/graphql/index.js +0 -5
- package/lib/handler.js +0 -41
- package/lib/index.js +0 -5
- package/lib/labels.js +0 -40
- package/lib/lib/config.js +0 -54
- package/lib/lib/credentials/index.js +0 -67
- package/lib/lib/request/api/index.d.ts +0 -6
- package/lib/lib/request/api/index.js +0 -20
- package/lib/lib/request/prompts/apps-prompt.js +0 -35
- package/lib/lib/request/prompts/asset-prompt.js +0 -81
- package/lib/lib/request/prompts/index.d.ts +0 -8
- package/lib/lib/request/prompts/index.js +0 -20
- package/lib/lib/request/prompts/role-prompt.js +0 -44
- package/lib/lib/request/types.js +0 -15
- /package/{lib → build}/commands/aws/identity.d.ts +0 -0
- /package/{lib → build}/commands/groups/get.d.ts +0 -0
- /package/{lib → build}/commands/iam-roles/start.d.ts +0 -0
- /package/{lib → build}/commands/kube-roles/start.d.ts +0 -0
- /package/{lib → build}/commands/logout.d.ts +0 -0
- /package/{lib → build}/commands/postgres-instances/start.d.ts +0 -0
- /package/{lib → build}/commands/request/create.d.ts +0 -0
- /package/{lib → build}/commands/request/get.d.ts +0 -0
- /package/{lib → build}/commands/request/list.d.ts +0 -0
- /package/{lib → build}/commands/resources/get.d.ts +0 -0
- /package/{lib → build}/commands/set-custom-header.d.ts +0 -0
- /package/{lib → build}/commands/set-token.d.ts +0 -0
- /package/{lib → build}/commands/set-url.d.ts +0 -0
- /package/{lib → build}/commands/ssh/copyFrom.d.ts +0 -0
- /package/{lib → build}/commands/ssh/copyTo.d.ts +0 -0
- /package/{lib → build}/commands/ssh/start.d.ts +0 -0
- /package/{lib → build}/commands/whoami.d.ts +0 -0
- /package/{lib → build}/graphql/graphql.d.ts +0 -0
- /package/{lib → build}/index.d.ts +0 -0
- /package/{lib → build}/lib/aws.d.ts +0 -0
- /package/{lib → build}/lib/config.d.ts +0 -0
- /package/{lib → build}/lib/credentials/keychain.d.ts +0 -0
- /package/{lib → build}/lib/credentials/localEncryption.d.ts +0 -0
- /package/{lib → build}/lib/flags.d.ts +0 -0
- /package/{lib → build}/lib/util.d.ts +0 -0
- /package/{lib → build}/types.d.ts +0 -0
|
@@ -10,7 +10,7 @@ export declare const runMutation: <TResponse = any, TVar extends OperationVariab
|
|
|
10
10
|
error: ErrorLike | null;
|
|
11
11
|
}>;
|
|
12
12
|
export declare const runQueryDeprecated: <TResponse = any, TVar extends OperationVariables = Record<string, any>>({ command, query, variables, }: QueryHandlerProps<TVar>) => Promise<{
|
|
13
|
-
resp: ApolloClient.QueryResult<
|
|
13
|
+
resp: ApolloClient.QueryResult<any> | undefined;
|
|
14
14
|
error: ErrorLike | null;
|
|
15
15
|
}>;
|
|
16
16
|
export {};
|
package/build/handler.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import gql from "graphql-tag";
|
|
2
|
+
import { client, initClient } from "./lib/apollo.js";
|
|
3
|
+
export const runMutation = async ({ command, query, variables, }) => {
|
|
4
|
+
await initClient(command);
|
|
5
|
+
let mutationResp = undefined;
|
|
6
|
+
let mutationError = null;
|
|
7
|
+
try {
|
|
8
|
+
mutationResp = await (client === null || client === void 0 ? void 0 : client.mutate({
|
|
9
|
+
mutation: gql `
|
|
10
|
+
${query}
|
|
11
|
+
`,
|
|
12
|
+
variables: variables,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
mutationError = error;
|
|
17
|
+
}
|
|
18
|
+
return { resp: mutationResp, error: mutationError };
|
|
19
|
+
};
|
|
20
|
+
export const runQueryDeprecated = async ({ command, query, variables, }) => {
|
|
21
|
+
await initClient(command);
|
|
22
|
+
let queryResp;
|
|
23
|
+
let queryError = null;
|
|
24
|
+
try {
|
|
25
|
+
queryResp = await (client === null || client === void 0 ? void 0 : client.query({
|
|
26
|
+
query: gql `
|
|
27
|
+
${query}
|
|
28
|
+
`,
|
|
29
|
+
variables: variables,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
queryError = error;
|
|
34
|
+
}
|
|
35
|
+
return { resp: queryResp, error: queryError };
|
|
36
|
+
};
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from "@oclif/core";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ConnectionType, EntityType } from "./graphql/graphql";
|
|
1
|
+
import { ConnectionType, EntityType } from "./graphql/graphql.js";
|
|
2
2
|
export declare const connectionTypeLabelByType: Record<ConnectionType, string>;
|
|
3
3
|
export declare const DisplayLabels: Partial<Record<EntityType, string>>;
|
package/build/labels.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ConnectionType, EntityType } from "./graphql/graphql.js";
|
|
2
|
+
export const connectionTypeLabelByType = {
|
|
3
|
+
[ConnectionType.ActiveDirectory]: "Active Directory",
|
|
4
|
+
[ConnectionType.Aws]: "Amazon Web Services (Legacy)",
|
|
5
|
+
[ConnectionType.AwsSso]: "Amazon Web Services",
|
|
6
|
+
[ConnectionType.Custom]: "Custom Integration",
|
|
7
|
+
[ConnectionType.CustomConnector]: "Custom App Connector",
|
|
8
|
+
[ConnectionType.Duo]: "Duo",
|
|
9
|
+
[ConnectionType.Gcp]: "Google Cloud Platform",
|
|
10
|
+
[ConnectionType.GitHub]: "GitHub",
|
|
11
|
+
[ConnectionType.GitLab]: "GitLab",
|
|
12
|
+
[ConnectionType.GoogleGroups]: "Google Groups",
|
|
13
|
+
[ConnectionType.GoogleWorkspace]: "Google Workspace",
|
|
14
|
+
[ConnectionType.Ldap]: "LDAP",
|
|
15
|
+
[ConnectionType.Mongo]: "MongoDB Database",
|
|
16
|
+
[ConnectionType.MongoAtlas]: "MongoDB Atlas Database",
|
|
17
|
+
[ConnectionType.OktaDirectory]: "Okta Directory",
|
|
18
|
+
[ConnectionType.Opal]: "Opal",
|
|
19
|
+
[ConnectionType.Pagerduty]: "PagerDuty",
|
|
20
|
+
[ConnectionType.Tailscale]: "Tailscale",
|
|
21
|
+
[ConnectionType.Salesforce]: "Salesforce",
|
|
22
|
+
[ConnectionType.Workday]: "Workday",
|
|
23
|
+
[ConnectionType.Mysql]: "MySQL",
|
|
24
|
+
[ConnectionType.Mariadb]: "MariaDB",
|
|
25
|
+
[ConnectionType.Postgres]: "PostgreSQL",
|
|
26
|
+
[ConnectionType.Teleport]: "Teleport",
|
|
27
|
+
[ConnectionType.AzureAd]: "Azure",
|
|
28
|
+
[ConnectionType.Snowflake]: "Snowflake",
|
|
29
|
+
[ConnectionType.Databricks]: "Databricks",
|
|
30
|
+
[ConnectionType.Coupa]: "Coupa",
|
|
31
|
+
[ConnectionType.DatastaxAstra]: "DataStax Astra",
|
|
32
|
+
[ConnectionType.Ilevel]: "iLEVEL",
|
|
33
|
+
};
|
|
34
|
+
export const DisplayLabels = {
|
|
35
|
+
[EntityType.Resource]: "Resource",
|
|
36
|
+
[EntityType.Group]: "Group",
|
|
37
|
+
};
|
|
@@ -2,7 +2,7 @@ import { ApolloClient } from "@apollo/client";
|
|
|
2
2
|
import type { Command } from "@oclif/core";
|
|
3
3
|
export declare let client: ApolloClient | null;
|
|
4
4
|
export declare let cookieStr: string;
|
|
5
|
-
export declare const printResponse: (command: Command, resp
|
|
6
|
-
export declare const handleError: (command: Command, err:
|
|
5
|
+
export declare const printResponse: (command: Command, resp?: ApolloClient.QueryResult) => void;
|
|
6
|
+
export declare const handleError: (command: Command, err: unknown, resp?: ApolloClient.QueryResult) => void;
|
|
7
7
|
export declare const initClient: (command: Command, fetchAccessToken?: boolean) => Promise<void>;
|
|
8
8
|
export declare function getClient(command: Command, fetchAccessToken?: boolean): Promise<ApolloClient>;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const config_1 = require("../lib/config");
|
|
16
|
-
const credentials_1 = require("../lib/credentials");
|
|
17
|
-
const fetch = require("node-fetch");
|
|
18
|
-
const https = require("node:https");
|
|
19
|
-
const http = require("node:http");
|
|
1
|
+
import { ApolloClient, ApolloLink, HttpLink, InMemoryCache, } from "@apollo/client";
|
|
2
|
+
import { setContext } from "@apollo/client/link/context";
|
|
3
|
+
import { ErrorLink } from "@apollo/client/link/error";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { render } from "prettyjson";
|
|
6
|
+
import { map, mergeMap } from "rxjs/operators";
|
|
7
|
+
import { major } from "semver";
|
|
8
|
+
import { invariant } from "@apollo/client/utilities/invariant";
|
|
9
|
+
import { from } from "rxjs";
|
|
10
|
+
import Login, { CLIAuthSessionCheckName, CLISignInMethodName, CLITokenExchangeName, } from "../commands/login.js";
|
|
11
|
+
import { allowSelfSignedCertsKey, customHttpHeaderKey, getOrCreateConfigData, urlKey, } from "./config.js";
|
|
12
|
+
import { SecretType, getOpalCredentials } from "./credentials/index.js";
|
|
13
|
+
import http from "node:http";
|
|
14
|
+
import https from "node:https";
|
|
20
15
|
// DO NOT USE DIRECTLY, use getClient instead
|
|
21
|
-
|
|
16
|
+
export let client = null;
|
|
22
17
|
// This is used to keep track of the auth-session cookie during login, before we can persist it into the credential store
|
|
23
|
-
|
|
18
|
+
export let cookieStr = "";
|
|
24
19
|
let alreadyWarnedAboutVersion = false;
|
|
25
|
-
const printResponse = (command, resp) => {
|
|
26
|
-
const filteredJson = JSON.parse(JSON.stringify(resp.data, (k, v) => {
|
|
20
|
+
export const printResponse = (command, resp) => {
|
|
21
|
+
const filteredJson = JSON.parse(JSON.stringify(resp === null || resp === void 0 ? void 0 : resp.data, (k, v) => {
|
|
27
22
|
if (k === "__typename" ||
|
|
28
23
|
v === null ||
|
|
29
24
|
(Array.isArray(v) && v.length === 0)) {
|
|
@@ -31,13 +26,14 @@ const printResponse = (command, resp) => {
|
|
|
31
26
|
}
|
|
32
27
|
return v;
|
|
33
28
|
}));
|
|
34
|
-
command.log(
|
|
29
|
+
command.log(render(filteredJson));
|
|
35
30
|
};
|
|
36
|
-
|
|
37
|
-
const handleError = (command, err, resp) => {
|
|
31
|
+
export const handleError = (command, err, resp) => {
|
|
38
32
|
if (err &&
|
|
39
33
|
typeof err === "object" &&
|
|
40
34
|
"networkError" in err &&
|
|
35
|
+
err.networkError &&
|
|
36
|
+
typeof err.networkError === "object" &&
|
|
41
37
|
"statusCode" in err.networkError) {
|
|
42
38
|
// Status code errors are already handled in the global Apollo handler, so we can just return here.
|
|
43
39
|
return;
|
|
@@ -58,42 +54,40 @@ const handleError = (command, err, resp) => {
|
|
|
58
54
|
errorMsg = `❗ ${errorMsg}`;
|
|
59
55
|
command.log(errorMsg);
|
|
60
56
|
if (resp) {
|
|
61
|
-
|
|
57
|
+
printResponse(command, resp);
|
|
62
58
|
}
|
|
63
59
|
// OPAL-6579: Use process.exit to avoid UnhandledPromiseRejectionWarning
|
|
64
60
|
process.exit(1);
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
const initClient = async (command, fetchAccessToken = true) => {
|
|
62
|
+
export const initClient = async (command, fetchAccessToken = true) => {
|
|
68
63
|
const configDir = command.config.configDir;
|
|
69
64
|
const currentCLIVersion = command.config.version;
|
|
70
|
-
const configData =
|
|
71
|
-
const opalCreds = await
|
|
65
|
+
const configData = getOrCreateConfigData(configDir);
|
|
66
|
+
const opalCreds = await getOpalCredentials(command, fetchAccessToken);
|
|
72
67
|
const organizationID = opalCreds === null || opalCreds === void 0 ? void 0 : opalCreds.organizationID;
|
|
73
68
|
const httpsAgent = new https.Agent({
|
|
74
|
-
rejectUnauthorized: !configData[
|
|
69
|
+
rejectUnauthorized: !configData[allowSelfSignedCertsKey],
|
|
75
70
|
});
|
|
76
71
|
const httpAgent = new http.Agent({});
|
|
77
|
-
const specifiedUrl = configData[
|
|
78
|
-
const customHeader = configData[
|
|
72
|
+
const specifiedUrl = configData[urlKey];
|
|
73
|
+
const customHeader = configData[customHttpHeaderKey];
|
|
79
74
|
const customHeaderKey = customHeader === undefined ? "" : customHeader.split(":")[0];
|
|
80
75
|
const customHeaderValue = customHeader === undefined ? "" : customHeader.split(":")[1];
|
|
81
76
|
const agent = specifiedUrl.includes("https") ? httpsAgent : httpAgent;
|
|
82
|
-
const httpLink = new
|
|
77
|
+
const httpLink = new HttpLink({
|
|
83
78
|
uri: `${specifiedUrl}/query`,
|
|
84
79
|
credentials: "include",
|
|
85
|
-
fetch,
|
|
86
80
|
fetchOptions: {
|
|
87
81
|
agent: agent,
|
|
88
82
|
},
|
|
89
83
|
});
|
|
90
|
-
const authLink =
|
|
84
|
+
const authLink = setContext((_, { headers }) => {
|
|
91
85
|
const baseHeaders = Object.assign(Object.assign({}, headers), { "User-Agent": `Opal CLI v${currentCLIVersion}`, "X-Opal-Organization-ID": organizationID, "X-Opal-Cli-Version": currentCLIVersion });
|
|
92
|
-
if (opalCreds.secretType ===
|
|
86
|
+
if (opalCreds.secretType === SecretType.ApiToken && !!opalCreds.secret) {
|
|
93
87
|
baseHeaders.authorization = `Bearer ${opalCreds.secret}`;
|
|
94
88
|
}
|
|
95
|
-
else if (!!opalCreds.secret || !!
|
|
96
|
-
baseHeaders.cookie = opalCreds.secret ||
|
|
89
|
+
else if (!!opalCreds.secret || !!cookieStr) {
|
|
90
|
+
baseHeaders.cookie = opalCreds.secret || cookieStr;
|
|
97
91
|
}
|
|
98
92
|
if (customHeaderKey) {
|
|
99
93
|
return {
|
|
@@ -121,15 +115,15 @@ const initClient = async (command, fetchAccessToken = true) => {
|
|
|
121
115
|
const expectedCLIMajorVersion = headers.get("Opal-CLI-Expected-Major-Version");
|
|
122
116
|
if (expectedCLIMajorVersion === null || expectedCLIMajorVersion === void 0 ? void 0 : expectedCLIMajorVersion.match(/^\d+$/)) {
|
|
123
117
|
const semverExpectedMinCLIVersion = `${expectedCLIMajorVersion}.0.0`;
|
|
124
|
-
if (
|
|
125
|
-
command.log(
|
|
118
|
+
if (major(currentCLIVersion) < major(semverExpectedMinCLIVersion)) {
|
|
119
|
+
command.log(chalk.yellow(`
|
|
126
120
|
❗ Your CLI is outdated and is incompatible with your Opal server.
|
|
127
|
-
Expected major version ${
|
|
128
|
-
Upgrade using the following command: ${
|
|
121
|
+
Expected major version ${chalk.blueBright(semverExpectedMinCLIVersion)}, but version ${chalk.blueBright(currentCLIVersion)} is installed.
|
|
122
|
+
Upgrade using the following command: ${chalk.blueBright("brew upgrade opalsecurity/brew/opal-security")}\n`));
|
|
129
123
|
alreadyWarnedAboutVersion = true;
|
|
130
124
|
}
|
|
131
|
-
else if (
|
|
132
|
-
command.log(
|
|
125
|
+
else if (major(currentCLIVersion) > major(semverExpectedMinCLIVersion)) {
|
|
126
|
+
command.log(chalk.yellow(`
|
|
133
127
|
❗ Uh oh! The currently installed Opal server is outdated. Please contact your Opal admins to let them know they need to upgrade their deployment.\n`));
|
|
134
128
|
alreadyWarnedAboutVersion = true;
|
|
135
129
|
}
|
|
@@ -138,33 +132,33 @@ const initClient = async (command, fetchAccessToken = true) => {
|
|
|
138
132
|
if (recommendedCLIMajorVersion === null || recommendedCLIMajorVersion === void 0 ? void 0 : recommendedCLIMajorVersion.match(/^\d+$/)) {
|
|
139
133
|
const recommendedSemverString = `${recommendedCLIMajorVersion}.0.0`;
|
|
140
134
|
if (recommendedSemverString &&
|
|
141
|
-
|
|
142
|
-
command.log(
|
|
135
|
+
major(currentCLIVersion) < major(recommendedSemverString)) {
|
|
136
|
+
command.log(chalk.yellow(`
|
|
143
137
|
❗ Opal recommends that you upgrade your CLI.
|
|
144
|
-
Recommended version >=${
|
|
145
|
-
Upgrade using the following command: ${
|
|
138
|
+
Recommended version >=${chalk.blueBright(recommendedSemverString)}, but version ${chalk.blueBright(currentCLIVersion)} is installed.
|
|
139
|
+
Upgrade using the following command: ${chalk.blueBright("brew upgrade opalsecurity/brew/opal-security")}\n`));
|
|
146
140
|
}
|
|
147
141
|
alreadyWarnedAboutVersion = true;
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
144
|
};
|
|
151
|
-
const checkCLIVersionLink = new
|
|
152
|
-
return forward(operation).pipe(
|
|
145
|
+
const checkCLIVersionLink = new ApolloLink((operation, forward) => {
|
|
146
|
+
return forward(operation).pipe(map((response) => {
|
|
153
147
|
checkCLIVersion(operation);
|
|
154
148
|
return response;
|
|
155
149
|
}));
|
|
156
150
|
});
|
|
157
|
-
const errorLink = new
|
|
151
|
+
const errorLink = new ErrorLink(({ error, operation, forward }) => {
|
|
158
152
|
// There's a few GQL operations where we don't want to use this error handler:
|
|
159
153
|
const customErrorOperations = [
|
|
160
154
|
// This is triggered just after the user called `opal login` or `opal set-token`, and has
|
|
161
155
|
// special handling if they fail, so we don't trigger an automatic re-login
|
|
162
|
-
|
|
156
|
+
CLIAuthSessionCheckName,
|
|
163
157
|
// This has special error handling to fall back to an older auth method that uses the OAuth access token
|
|
164
|
-
|
|
158
|
+
CLITokenExchangeName,
|
|
165
159
|
// This has special error handling due to the fact that the backend version
|
|
166
160
|
// can be out of date and not include the new cliClientId field.
|
|
167
|
-
|
|
161
|
+
CLISignInMethodName,
|
|
168
162
|
];
|
|
169
163
|
if (operation.operationName &&
|
|
170
164
|
customErrorOperations.includes(operation.operationName)) {
|
|
@@ -174,20 +168,20 @@ const initClient = async (command, fetchAccessToken = true) => {
|
|
|
174
168
|
const errorMessage = error.message;
|
|
175
169
|
if (errorMessage.includes("invalid authentication")) {
|
|
176
170
|
command.log("Your session is invalid or expired. Authenticating now...\n");
|
|
177
|
-
const loginCommand = new
|
|
178
|
-
return
|
|
171
|
+
const loginCommand = new Login([], command.config);
|
|
172
|
+
return from(loginCommand.run()).pipe(mergeMap(() => forward(operation)));
|
|
179
173
|
}
|
|
180
|
-
return
|
|
174
|
+
return handleError(command, `Received error from server${errorMessage ? ` with message "${errorMessage}"` : ""}`);
|
|
181
175
|
}
|
|
182
176
|
});
|
|
183
177
|
// Parses our auth-session cookie out of the Set-Cookie response header, saving it locally so we can use it for future requests
|
|
184
|
-
const preserveCookiesLink = new
|
|
185
|
-
return forward(operation).pipe(
|
|
178
|
+
const preserveCookiesLink = new ApolloLink((operation, forward) => {
|
|
179
|
+
return forward(operation).pipe(map((response) => {
|
|
186
180
|
var _a, _b, _c, _d;
|
|
187
181
|
const cookieHeaderStr = (_c = (_b = (_a = operation.getContext().response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.get("Set-Cookie")) !== null && _c !== void 0 ? _c : "";
|
|
188
182
|
const authSessionCookie = (_d = cookieHeaderStr.match(/auth-session=[^;]+;/)) === null || _d === void 0 ? void 0 : _d[0];
|
|
189
183
|
if (authSessionCookie) {
|
|
190
|
-
|
|
184
|
+
cookieStr = authSessionCookie;
|
|
191
185
|
}
|
|
192
186
|
return response;
|
|
193
187
|
}));
|
|
@@ -196,14 +190,13 @@ const initClient = async (command, fetchAccessToken = true) => {
|
|
|
196
190
|
link = checkCLIVersionLink.concat(link);
|
|
197
191
|
link = preserveCookiesLink.concat(link);
|
|
198
192
|
link = errorLink.concat(link);
|
|
199
|
-
|
|
193
|
+
client = new ApolloClient({
|
|
200
194
|
link: link,
|
|
201
|
-
cache: new
|
|
195
|
+
cache: new InMemoryCache(),
|
|
202
196
|
});
|
|
203
197
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return exports.client;
|
|
198
|
+
export async function getClient(command, fetchAccessToken = true) {
|
|
199
|
+
await initClient(command, fetchAccessToken);
|
|
200
|
+
invariant(client, "Failed to initialize Opal Client");
|
|
201
|
+
return client;
|
|
209
202
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const authSuccessHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Authentication Successful - Opal CLI</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n background: black;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 20px;\n }\n .container {\n background: white;\n border-radius: 16px;\n box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);\n max-width: 480px;\n width: 100%;\n padding: 48px 40px;\n text-align: center;\n }\n .logo {\n width: 80px;\n height: 80px;\n margin: 0 auto 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n .logo svg {\n width: 80px;\n height: 80px;\n }\n .checkmark {\n width: 80px;\n height: 80px;\n margin: 0 auto 24px;\n background: #10b981;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n animation: scaleIn 0.5s ease-out;\n }\n .checkmark svg {\n width: 48px;\n height: 48px;\n stroke: white;\n stroke-width: 3;\n stroke-linecap: round;\n stroke-linejoin: round;\n fill: none;\n animation: checkmark 0.5s ease-out 0.2s forwards;\n stroke-dasharray: 100;\n stroke-dashoffset: 100;\n }\n @keyframes scaleIn {\n from { transform: scale(0); opacity: 0; }\n to { transform: scale(1); opacity: 1; }\n }\n @keyframes checkmark {\n to { stroke-dashoffset: 0; }\n }\n h1 {\n font-size: 28px;\n color: #1f2937;\n margin-bottom: 12px;\n font-weight: 600;\n }\n .subtitle {\n font-size: 16px;\n color: #6b7280;\n margin-bottom: 32px;\n line-height: 1.5;\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"checkmark\">\n <svg viewBox=\"0 0 52 52\">\n <polyline points=\"14 27 22 35 38 19\" />\n </svg>\n </div>\n <h1>Authentication Successful!</h1>\n <p class=\"subtitle\">Your Opal CLI has been successfully authenticated and this window can be safely closed</p>\n <div class=\"logo\">\n <svg width=\"80\" height=\"80\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <g clip-path=\"url(#clip0_852_5824)\">\n <path\n d=\"M7.335 5.53875L7.98093 3.16032C8.09343 2.76094 8.505 2.51907 8.91656 2.62125L11.3119 3.2625L11.9859 0.753753L9.59062 0.112503C7.79343 -0.361872 5.93156 0.697503 5.45343 2.48063L4.8075 4.85907L7.335 5.53782V5.53875Z\"\n fill=\"currentColor\" />\n <path\n d=\"M19.1409 4.86004L18.495 2.4816C18.0169 0.69848 16.155 -0.360895 14.3578 0.11348L11.9625 0.75473L12.6366 3.26348L15.0319 2.62223C15.4434 2.52004 15.855 2.76098 15.9675 3.16129L16.6134 5.53973L19.1409 4.86098V4.86004Z\"\n fill=\"currentColor\" />\n <path\n d=\"M16.6134 18.4612L15.9675 20.8396C15.855 21.239 15.4434 21.4809 15.0319 21.3787L12.6366 20.7374L11.9625 23.2462L14.3578 23.8874C16.155 24.3618 18.0169 23.3024 18.495 21.5193L19.1409 19.1409L16.6134 18.4621V18.4612Z\"\n fill=\"currentColor\" />\n <path\n d=\"M4.8075 19.1399L5.45343 21.5183C5.93156 23.3015 7.79343 24.3608 9.59062 23.8865L11.9859 23.2452L11.3119 20.7365L8.91656 21.3777C8.505 21.4799 8.09343 21.239 7.98093 20.8386L7.335 18.4602L4.8075 19.139V19.1399Z\"\n fill=\"currentColor\" />\n <path\n d=\"M5.53875 16.6397L3.16032 15.9938C2.76094 15.8813 2.51907 15.4697 2.62125 15.0581L3.2625 12.6628L0.753753 11.9888L0.112503 14.3841C-0.361872 16.1813 0.697503 18.0431 2.48063 18.5213L4.85907 19.1672L5.53782 16.6397H5.53875Z\"\n fill=\"currentColor\" />\n <path\n d=\"M4.86001 4.83374L2.48157 5.47968C0.698449 5.9578 -0.360926 7.81968 0.113449 9.61687L0.754699 12.0122L3.26345 11.3381L2.6222 8.9428C2.52001 8.53124 2.76095 8.11968 3.16126 8.00718L5.5397 7.36124L4.86095 4.83374H4.86001Z\"\n fill=\"currentColor\" />\n <path\n d=\"M18.4612 7.36026L20.8397 8.0062C21.2391 8.1187 21.4809 8.53026 21.3787 8.94183L20.7375 11.3371L23.2462 12.0112L23.8875 9.61589C24.3619 7.8187 23.3025 5.95683 21.5194 5.4787L19.1409 4.83276L18.4622 7.36026H18.4612Z\"\n fill=\"currentColor\" />\n <path\n d=\"M19.14 19.1662L21.5185 18.5203C23.3016 18.0422 24.361 16.1803 23.8866 14.3831L23.2453 11.9878L20.7366 12.6619L21.3778 15.0572C21.48 15.4687 21.2391 15.8803 20.8388 15.9928L18.4603 16.6387L19.1391 19.1662H19.14Z\"\n fill=\"currentColor\" />\n </g>\n <defs>\n <clipPath id=\"clip0_852_5824\">\n <rect width=\"24\" height=\"24\" fill=\"white\" />\n </clipPath>\n </defs>\n </svg>\n </div>\n\n </div>\n</body>\n</html>";
|
|
2
|
+
export declare const authErrorHtml: (error: string) => string;
|
|
3
|
+
export declare const authMissingCodeHtml = "\n<html>\n <body>\n <h1>Authentication Failed</h1>\n <p>Missing authorization code.</p>\n <p>You can close this window.</p>\n </body>\n</html>\n";
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import sanitizeHtml from "sanitize-html";
|
|
2
|
+
export const authSuccessHtml = `<!DOCTYPE html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Authentication Successful - Opal CLI</title>
|
|
8
|
+
<style>
|
|
9
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
10
|
+
body {
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
12
|
+
background: black;
|
|
13
|
+
min-height: 100vh;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
padding: 20px;
|
|
18
|
+
}
|
|
19
|
+
.container {
|
|
20
|
+
background: white;
|
|
21
|
+
border-radius: 16px;
|
|
22
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
23
|
+
max-width: 480px;
|
|
24
|
+
width: 100%;
|
|
25
|
+
padding: 48px 40px;
|
|
26
|
+
text-align: center;
|
|
27
|
+
}
|
|
28
|
+
.logo {
|
|
29
|
+
width: 80px;
|
|
30
|
+
height: 80px;
|
|
31
|
+
margin: 0 auto 24px;
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
}
|
|
36
|
+
.logo svg {
|
|
37
|
+
width: 80px;
|
|
38
|
+
height: 80px;
|
|
39
|
+
}
|
|
40
|
+
.checkmark {
|
|
41
|
+
width: 80px;
|
|
42
|
+
height: 80px;
|
|
43
|
+
margin: 0 auto 24px;
|
|
44
|
+
background: #10b981;
|
|
45
|
+
border-radius: 50%;
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
animation: scaleIn 0.5s ease-out;
|
|
50
|
+
}
|
|
51
|
+
.checkmark svg {
|
|
52
|
+
width: 48px;
|
|
53
|
+
height: 48px;
|
|
54
|
+
stroke: white;
|
|
55
|
+
stroke-width: 3;
|
|
56
|
+
stroke-linecap: round;
|
|
57
|
+
stroke-linejoin: round;
|
|
58
|
+
fill: none;
|
|
59
|
+
animation: checkmark 0.5s ease-out 0.2s forwards;
|
|
60
|
+
stroke-dasharray: 100;
|
|
61
|
+
stroke-dashoffset: 100;
|
|
62
|
+
}
|
|
63
|
+
@keyframes scaleIn {
|
|
64
|
+
from { transform: scale(0); opacity: 0; }
|
|
65
|
+
to { transform: scale(1); opacity: 1; }
|
|
66
|
+
}
|
|
67
|
+
@keyframes checkmark {
|
|
68
|
+
to { stroke-dashoffset: 0; }
|
|
69
|
+
}
|
|
70
|
+
h1 {
|
|
71
|
+
font-size: 28px;
|
|
72
|
+
color: #1f2937;
|
|
73
|
+
margin-bottom: 12px;
|
|
74
|
+
font-weight: 600;
|
|
75
|
+
}
|
|
76
|
+
.subtitle {
|
|
77
|
+
font-size: 16px;
|
|
78
|
+
color: #6b7280;
|
|
79
|
+
margin-bottom: 32px;
|
|
80
|
+
line-height: 1.5;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
83
|
+
</head>
|
|
84
|
+
<body>
|
|
85
|
+
<div class="container">
|
|
86
|
+
<div class="checkmark">
|
|
87
|
+
<svg viewBox="0 0 52 52">
|
|
88
|
+
<polyline points="14 27 22 35 38 19" />
|
|
89
|
+
</svg>
|
|
90
|
+
</div>
|
|
91
|
+
<h1>Authentication Successful!</h1>
|
|
92
|
+
<p class="subtitle">Your Opal CLI has been successfully authenticated and this window can be safely closed</p>
|
|
93
|
+
<div class="logo">
|
|
94
|
+
<svg width="80" height="80" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
95
|
+
<g clip-path="url(#clip0_852_5824)">
|
|
96
|
+
<path
|
|
97
|
+
d="M7.335 5.53875L7.98093 3.16032C8.09343 2.76094 8.505 2.51907 8.91656 2.62125L11.3119 3.2625L11.9859 0.753753L9.59062 0.112503C7.79343 -0.361872 5.93156 0.697503 5.45343 2.48063L4.8075 4.85907L7.335 5.53782V5.53875Z"
|
|
98
|
+
fill="currentColor" />
|
|
99
|
+
<path
|
|
100
|
+
d="M19.1409 4.86004L18.495 2.4816C18.0169 0.69848 16.155 -0.360895 14.3578 0.11348L11.9625 0.75473L12.6366 3.26348L15.0319 2.62223C15.4434 2.52004 15.855 2.76098 15.9675 3.16129L16.6134 5.53973L19.1409 4.86098V4.86004Z"
|
|
101
|
+
fill="currentColor" />
|
|
102
|
+
<path
|
|
103
|
+
d="M16.6134 18.4612L15.9675 20.8396C15.855 21.239 15.4434 21.4809 15.0319 21.3787L12.6366 20.7374L11.9625 23.2462L14.3578 23.8874C16.155 24.3618 18.0169 23.3024 18.495 21.5193L19.1409 19.1409L16.6134 18.4621V18.4612Z"
|
|
104
|
+
fill="currentColor" />
|
|
105
|
+
<path
|
|
106
|
+
d="M4.8075 19.1399L5.45343 21.5183C5.93156 23.3015 7.79343 24.3608 9.59062 23.8865L11.9859 23.2452L11.3119 20.7365L8.91656 21.3777C8.505 21.4799 8.09343 21.239 7.98093 20.8386L7.335 18.4602L4.8075 19.139V19.1399Z"
|
|
107
|
+
fill="currentColor" />
|
|
108
|
+
<path
|
|
109
|
+
d="M5.53875 16.6397L3.16032 15.9938C2.76094 15.8813 2.51907 15.4697 2.62125 15.0581L3.2625 12.6628L0.753753 11.9888L0.112503 14.3841C-0.361872 16.1813 0.697503 18.0431 2.48063 18.5213L4.85907 19.1672L5.53782 16.6397H5.53875Z"
|
|
110
|
+
fill="currentColor" />
|
|
111
|
+
<path
|
|
112
|
+
d="M4.86001 4.83374L2.48157 5.47968C0.698449 5.9578 -0.360926 7.81968 0.113449 9.61687L0.754699 12.0122L3.26345 11.3381L2.6222 8.9428C2.52001 8.53124 2.76095 8.11968 3.16126 8.00718L5.5397 7.36124L4.86095 4.83374H4.86001Z"
|
|
113
|
+
fill="currentColor" />
|
|
114
|
+
<path
|
|
115
|
+
d="M18.4612 7.36026L20.8397 8.0062C21.2391 8.1187 21.4809 8.53026 21.3787 8.94183L20.7375 11.3371L23.2462 12.0112L23.8875 9.61589C24.3619 7.8187 23.3025 5.95683 21.5194 5.4787L19.1409 4.83276L18.4622 7.36026H18.4612Z"
|
|
116
|
+
fill="currentColor" />
|
|
117
|
+
<path
|
|
118
|
+
d="M19.14 19.1662L21.5185 18.5203C23.3016 18.0422 24.361 16.1803 23.8866 14.3831L23.2453 11.9878L20.7366 12.6619L21.3778 15.0572C21.48 15.4687 21.2391 15.8803 20.8388 15.9928L18.4603 16.6387L19.1391 19.1662H19.14Z"
|
|
119
|
+
fill="currentColor" />
|
|
120
|
+
</g>
|
|
121
|
+
<defs>
|
|
122
|
+
<clipPath id="clip0_852_5824">
|
|
123
|
+
<rect width="24" height="24" fill="white" />
|
|
124
|
+
</clipPath>
|
|
125
|
+
</defs>
|
|
126
|
+
</svg>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
</div>
|
|
130
|
+
</body>
|
|
131
|
+
</html>`;
|
|
132
|
+
export const authErrorHtml = (error) => `
|
|
133
|
+
<html>
|
|
134
|
+
<body>
|
|
135
|
+
<h1>Authentication Failed</h1>
|
|
136
|
+
<p>Error: ${sanitizeHtml(error)}</p>
|
|
137
|
+
<p>You can close this window.</p>
|
|
138
|
+
</body>
|
|
139
|
+
</html>
|
|
140
|
+
`;
|
|
141
|
+
export const authMissingCodeHtml = `
|
|
142
|
+
<html>
|
|
143
|
+
<body>
|
|
144
|
+
<h1>Authentication Failed</h1>
|
|
145
|
+
<p>Missing authorization code.</p>
|
|
146
|
+
<p>You can close this window.</p>
|
|
147
|
+
</body>
|
|
148
|
+
</html>
|
|
149
|
+
`;
|
package/{lib → build}/lib/aws.js
RENAMED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAwsEnvVarMessage = exports.getAwsConfigUpdateCmd = void 0;
|
|
4
1
|
const opalProfileKey = "opal";
|
|
5
2
|
const sanitize = (str) => {
|
|
6
3
|
// Remove non standard characters.
|
|
@@ -13,7 +10,7 @@ const sanitize = (str) => {
|
|
|
13
10
|
sanitizedStr = sanitizedStr.replace(/ /g, "-");
|
|
14
11
|
return sanitizedStr;
|
|
15
12
|
};
|
|
16
|
-
const getAwsConfigUpdateCmd = (itemName, awsAccessKeyId, awsSecretAccessKey, awsSessionToken) => {
|
|
13
|
+
export const getAwsConfigUpdateCmd = (itemName, awsAccessKeyId, awsSecretAccessKey, awsSessionToken) => {
|
|
17
14
|
let updateProfilesCmd = "";
|
|
18
15
|
const sanitizedProfileName = sanitize(itemName);
|
|
19
16
|
const profileNames = [opalProfileKey, sanitizedProfileName];
|
|
@@ -30,8 +27,7 @@ const getAwsConfigUpdateCmd = (itemName, awsAccessKeyId, awsSecretAccessKey, aws
|
|
|
30
27
|
});
|
|
31
28
|
return updateProfilesCmd;
|
|
32
29
|
};
|
|
33
|
-
|
|
34
|
-
const getAwsEnvVarMessage = () => {
|
|
30
|
+
export const getAwsEnvVarMessage = () => {
|
|
35
31
|
if (!process.env.AWS_DEFAULT_PROFILE ||
|
|
36
32
|
process.env.AWS_DEFAULT_PROFILE !== opalProfileKey) {
|
|
37
33
|
let envVarPhrase = "";
|
|
@@ -49,4 +45,3 @@ const getAwsEnvVarMessage = () => {
|
|
|
49
45
|
}
|
|
50
46
|
return "";
|
|
51
47
|
};
|
|
52
|
-
exports.getAwsEnvVarMessage = getAwsEnvVarMessage;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ExecException } from "node:child_process";
|
|
2
2
|
import type { Command } from "@oclif/core";
|
|
3
|
-
import
|
|
3
|
+
import moment from "moment";
|
|
4
4
|
export declare let mostRecentCommand: Command | null;
|
|
5
5
|
export declare let mostRecentCommandTime: moment.Moment | null;
|
|
6
6
|
export declare const setMostRecentCommand: (cmd: Command) => void;
|
|
7
7
|
export declare const startInteractiveShell: (runCmd: string, shellName?: string) => void;
|
|
8
|
-
export declare const runCommandExec: (runCmd: string, successMessage: string, errorMessage: string, envVars?:
|
|
9
|
-
export declare const runCommandExecWithCallback: (cmd: string, callback?: (error: ExecException | null, stdout:
|
|
10
|
-
export declare const runCommandSpawn: (runCmd: string, successMessage: string, errorMessage: string, envVars?:
|
|
8
|
+
export declare const runCommandExec: (runCmd: string, successMessage: string, errorMessage: string, envVars?: NodeJS.ProcessEnv) => void;
|
|
9
|
+
export declare const runCommandExecWithCallback: (cmd: string, callback?: (error: ExecException | null, stdout: string, stderr: string) => void) => Promise<unknown>;
|
|
10
|
+
export declare const runCommandSpawn: (runCmd: string, successMessage: string, errorMessage: string, envVars?: NodeJS.ProcessEnv) => void;
|
package/{lib → build}/lib/cmd.js
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { exec, spawn } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import _ from "lodash";
|
|
5
|
+
import moment from "moment";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
export let mostRecentCommand = null;
|
|
9
|
+
export let mostRecentCommandTime = null;
|
|
10
|
+
export const setMostRecentCommand = (cmd) => {
|
|
11
|
+
mostRecentCommand = cmd;
|
|
12
|
+
mostRecentCommandTime = moment(new Date());
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
const startInteractiveShell = (runCmd, shellName) => {
|
|
14
|
+
export const startInteractiveShell = (runCmd, shellName) => {
|
|
15
15
|
const shell = spawn(`${runCmd}`, [], {
|
|
16
16
|
env: Object.assign(Object.assign({}, process.env), { SCRIPT_PATH: __dirname }),
|
|
17
17
|
stdio: "inherit",
|
|
@@ -37,8 +37,7 @@ const startInteractiveShell = (runCmd, shellName) => {
|
|
|
37
37
|
// intercepting SIGTSTP
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
const runCommandExec = (runCmd, successMessage, errorMessage, envVars) => {
|
|
40
|
+
export const runCommandExec = (runCmd, successMessage, errorMessage, envVars) => {
|
|
42
41
|
const envVarsToUse = envVars || {};
|
|
43
42
|
exec(`${runCmd}`, {
|
|
44
43
|
env: Object.assign(Object.assign(Object.assign({}, process.env), { SCRIPT_PATH: __dirname }), envVarsToUse),
|
|
@@ -57,8 +56,7 @@ const runCommandExec = (runCmd, successMessage, errorMessage, envVars) => {
|
|
|
57
56
|
}
|
|
58
57
|
});
|
|
59
58
|
};
|
|
60
|
-
|
|
61
|
-
const runCommandExecWithCallback = (cmd, callback) => {
|
|
59
|
+
export const runCommandExecWithCallback = (cmd, callback) => {
|
|
62
60
|
return new Promise((resolve) => {
|
|
63
61
|
exec(cmd, (error, stdOut, stdErr) => {
|
|
64
62
|
callback === null || callback === void 0 ? void 0 : callback(error, stdOut, stdErr);
|
|
@@ -66,8 +64,7 @@ const runCommandExecWithCallback = (cmd, callback) => {
|
|
|
66
64
|
});
|
|
67
65
|
});
|
|
68
66
|
};
|
|
69
|
-
|
|
70
|
-
const runCommandSpawn = (runCmd, successMessage, errorMessage, envVars) => {
|
|
67
|
+
export const runCommandSpawn = (runCmd, successMessage, errorMessage, envVars) => {
|
|
71
68
|
const envVarsToUse = envVars || {};
|
|
72
69
|
const shell = spawn(`${runCmd}`, [], {
|
|
73
70
|
env: Object.assign(Object.assign(Object.assign({}, process.env), { SCRIPT_PATH: __dirname }), envVarsToUse),
|
|
@@ -83,4 +80,3 @@ const runCommandSpawn = (runCmd, successMessage, errorMessage, envVars) => {
|
|
|
83
80
|
}
|
|
84
81
|
});
|
|
85
82
|
};
|
|
86
|
-
exports.runCommandSpawn = runCommandSpawn;
|