opal-security 2.1.3 → 2.3.1
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 +233 -157
- package/bin/dev +6 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +4 -4
- package/lib/commands/aws/identity.d.ts +2 -2
- package/lib/commands/aws/identity.js +5 -5
- package/lib/commands/curl-example.d.ts +2 -2
- package/lib/commands/curl-example.js +7 -6
- package/lib/commands/iam-roles/start.d.ts +6 -6
- package/lib/commands/iam-roles/start.js +16 -16
- package/lib/commands/kube-roles/start.d.ts +6 -6
- package/lib/commands/kube-roles/start.js +13 -13
- package/lib/commands/login.d.ts +4 -4
- package/lib/commands/login.js +29 -30
- package/lib/commands/logout.d.ts +3 -3
- package/lib/commands/logout.js +5 -5
- package/lib/commands/migrate-creds.d.ts +8 -0
- package/lib/commands/migrate-creds.js +48 -0
- package/lib/commands/postgres-instances/start.d.ts +7 -7
- package/lib/commands/postgres-instances/start.js +14 -14
- package/lib/commands/resources/get.d.ts +3 -3
- package/lib/commands/resources/get.js +8 -8
- package/lib/commands/set-custom-header.d.ts +4 -4
- package/lib/commands/set-custom-header.js +9 -9
- package/lib/commands/set-token.d.ts +3 -3
- package/lib/commands/set-token.js +10 -17
- package/lib/commands/set-url.d.ts +10 -12
- package/lib/commands/set-url.js +19 -20
- package/lib/commands/ssh/copyFrom.d.ts +7 -7
- package/lib/commands/ssh/copyFrom.js +13 -13
- package/lib/commands/ssh/copyTo.d.ts +7 -7
- package/lib/commands/ssh/copyTo.js +13 -13
- package/lib/commands/ssh/start.d.ts +5 -5
- package/lib/commands/ssh/start.js +16 -16
- package/lib/handler.d.ts +6 -5
- package/lib/handler.js +8 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -2
- package/lib/lib/apollo.d.ts +2 -2
- package/lib/lib/apollo.js +26 -19
- package/lib/lib/aws.js +4 -2
- package/lib/lib/cmd.d.ts +5 -4
- package/lib/lib/cmd.js +10 -5
- package/lib/lib/config.js +8 -5
- package/lib/lib/credentials/index.d.ts +11 -0
- package/lib/lib/credentials/index.js +55 -0
- package/lib/lib/credentials/keychain.d.ts +3 -0
- package/lib/lib/credentials/keychain.js +41 -0
- package/lib/lib/credentials/localEncryption.d.ts +3 -0
- package/lib/lib/credentials/localEncryption.js +75 -0
- package/lib/lib/flags.d.ts +5 -6
- package/lib/lib/flags.js +6 -6
- package/lib/lib/resources.d.ts +4 -4
- package/lib/lib/resources.js +14 -11
- package/lib/lib/sessions.d.ts +2 -2
- package/lib/lib/sessions.js +13 -11
- package/lib/lib/ssh.d.ts +1 -1
- package/lib/lib/ssh.js +6 -4
- package/lib/lib/util.js +8 -5
- package/lib/types.d.ts +1204 -1204
- package/lib/types.js +49 -49
- package/oclif.manifest.json +756 -1
- package/package.json +29 -24
- package/lib/lib/credentials.d.ts +0 -9
- package/lib/lib/credentials.js +0 -76
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
4
|
const cmd_1 = require("../../lib/cmd");
|
|
5
5
|
const flags_1 = require("../../lib/flags");
|
|
6
|
-
class Identity extends
|
|
6
|
+
class Identity extends core_1.Command {
|
|
7
7
|
async run() {
|
|
8
|
-
cmd_1.setMostRecentCommand(this);
|
|
8
|
+
(0, cmd_1.setMostRecentCommand)(this);
|
|
9
9
|
const currentCallerIdentityCmd = 'aws sts get-caller-identity --profile opal';
|
|
10
|
-
cmd_1.runCommandExec(currentCallerIdentityCmd, 'This is the current caller identity for the "opal" AWS profile.', 'Failed to get the current caller identity for the "opal" AWS profile.');
|
|
10
|
+
(0, cmd_1.runCommandExec)(currentCallerIdentityCmd, 'This is the current caller identity for the "opal" AWS profile.', 'Failed to get the current caller identity for the "opal" AWS profile.');
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
exports.default = Identity;
|
|
14
13
|
Identity.description = 'Gets the current caller identity for the "opal" AWS profile.';
|
|
15
14
|
Identity.examples = ['opal aws:identity'];
|
|
16
15
|
Identity.flags = {
|
|
17
16
|
help: flags_1.SHARED_FLAGS.help,
|
|
18
17
|
};
|
|
18
|
+
exports.default = Identity;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Command } from '@oclif/
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export default class CurlExample extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
help: import("@oclif/
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
6
|
};
|
|
7
7
|
run(): Promise<void>;
|
|
8
8
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
4
|
const config_1 = require("../lib/config");
|
|
5
5
|
const credentials_1 = require("../lib/credentials");
|
|
6
6
|
const flags_1 = require("../lib/flags");
|
|
7
|
-
class CurlExample extends
|
|
7
|
+
class CurlExample extends core_1.Command {
|
|
8
8
|
async run() {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const opalCreds = await (0, credentials_1.getOpalCredentials)(this);
|
|
10
|
+
const accessToken = opalCreds === null || opalCreds === void 0 ? void 0 : opalCreds.accessToken;
|
|
11
|
+
const organizationID = opalCreds === null || opalCreds === void 0 ? void 0 : opalCreds.organizationID;
|
|
12
|
+
const configData = (0, config_1.getOrCreateConfigData)(this.config.configDir);
|
|
12
13
|
const url = configData[config_1.urlKey];
|
|
13
14
|
this.log(`
|
|
14
15
|
curl -v ${url}/query \\
|
|
@@ -19,8 +20,8 @@ curl -v ${url}/query \\
|
|
|
19
20
|
`);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
exports.default = CurlExample;
|
|
23
23
|
CurlExample.description = 'Prints out an example cURL command containing the parameters the CLI uses to query the Opal server.';
|
|
24
24
|
CurlExample.flags = {
|
|
25
25
|
help: flags_1.SHARED_FLAGS.help,
|
|
26
26
|
};
|
|
27
|
+
exports.default = CurlExample;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export default class StartIAMRoleSession extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
help: import("@oclif/
|
|
7
|
-
id:
|
|
8
|
-
sessionId:
|
|
9
|
-
refresh: import("@oclif/
|
|
10
|
-
profileName:
|
|
6
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
7
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
sessionId: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
refresh: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
profileName: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
11
|
};
|
|
12
12
|
run(): Promise<void>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
4
|
const handler_1 = require("../../handler");
|
|
5
5
|
const cmd_1 = require("../../lib/cmd");
|
|
6
6
|
const apollo_1 = require("../../lib/apollo");
|
|
@@ -17,18 +17,18 @@ const IamSessionMetadataFragment = `
|
|
|
17
17
|
awsLoginUrl
|
|
18
18
|
federatedArn
|
|
19
19
|
}`;
|
|
20
|
-
class StartIAMRoleSession extends
|
|
20
|
+
class StartIAMRoleSession extends core_1.Command {
|
|
21
21
|
async run() {
|
|
22
|
-
cmd_1.setMostRecentCommand(this);
|
|
23
|
-
const { flags } = this.parse(StartIAMRoleSession);
|
|
22
|
+
(0, cmd_1.setMostRecentCommand)(this);
|
|
23
|
+
const { flags } = await this.parse(StartIAMRoleSession);
|
|
24
24
|
if (flags.sessionId && flags.refresh) {
|
|
25
|
-
return apollo_1.handleError(this, 'Cannot use both --sessionId and --refresh');
|
|
25
|
+
return (0, apollo_1.handleError)(this, 'Cannot use both --sessionId and --refresh');
|
|
26
26
|
}
|
|
27
27
|
let roleId = flags.id;
|
|
28
28
|
let roleName = null;
|
|
29
29
|
const sessionId = flags.sessionId;
|
|
30
30
|
if (!roleId) {
|
|
31
|
-
const selectedRole = await resources_1.promptUserForResource(this, 'AWS_IAM_ROLE', 'Select an IAM role to assume');
|
|
31
|
+
const selectedRole = await (0, resources_1.promptUserForResource)(this, 'AWS_IAM_ROLE', 'Select an IAM role to assume');
|
|
32
32
|
if (!selectedRole) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -36,7 +36,7 @@ class StartIAMRoleSession extends command_1.Command {
|
|
|
36
36
|
roleName = selectedRole.name;
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
const { resp, error } = await handler_1.runQuery({
|
|
39
|
+
const { resp, error } = await (0, handler_1.runQuery)({
|
|
40
40
|
command: this,
|
|
41
41
|
query: get_1.GetResourceDocument,
|
|
42
42
|
variables: {
|
|
@@ -44,36 +44,35 @@ class StartIAMRoleSession extends command_1.Command {
|
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
46
|
if (error) {
|
|
47
|
-
return apollo_1.handleError(this, error, resp);
|
|
47
|
+
return (0, apollo_1.handleError)(this, error, resp);
|
|
48
48
|
}
|
|
49
49
|
if (!(resp === null || resp === void 0 ? void 0 : resp.data.resource.resource)) {
|
|
50
|
-
return apollo_1.handleError(this, `Resource not found for ID: ${roleId}`);
|
|
50
|
+
return (0, apollo_1.handleError)(this, `Resource not found for ID: ${roleId}`);
|
|
51
51
|
}
|
|
52
52
|
roleName = (resp === null || resp === void 0 ? void 0 : resp.data.resource.resource.name) || 'iam-role';
|
|
53
53
|
}
|
|
54
54
|
if (flags.profileName && flags.profileName !== '') {
|
|
55
55
|
roleName = flags.profileName;
|
|
56
56
|
}
|
|
57
|
-
const session = await sessions_1.getOrCreateSession(this, roleId, resources_1.DEFAULT_ACCESS_LEVEL, sessionId, IamSessionMetadataFragment, flags.refresh);
|
|
57
|
+
const session = await (0, sessions_1.getOrCreateSession)(this, roleId, resources_1.DEFAULT_ACCESS_LEVEL, sessionId, IamSessionMetadataFragment, flags.refresh);
|
|
58
58
|
if (!session) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
const metadata = session.metadata;
|
|
62
62
|
switch (metadata === null || metadata === void 0 ? void 0 : metadata.__typename) {
|
|
63
63
|
case 'AwsIamFederatedRoleSession': {
|
|
64
|
-
const updateAwsConfigCommand = aws_1.getAwsConfigUpdateCmd(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
|
|
64
|
+
const updateAwsConfigCommand = (0, aws_1.getAwsConfigUpdateCmd)(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
|
|
65
65
|
const startSessionCmd = `${updateAwsConfigCommand}`;
|
|
66
66
|
const roleText = roleName ? `"${roleName}" role` : 'role';
|
|
67
|
-
const expirationMessage = sessions_1.getSessionExpirationMessage(session);
|
|
68
|
-
cmd_1.runCommandExec(startSessionCmd, `Now set to use ${roleText}. (session expires in ${expirationMessage})${aws_1.getAwsEnvVarMessage()}`, `Failed to use ${roleText}.`);
|
|
67
|
+
const expirationMessage = (0, sessions_1.getSessionExpirationMessage)(session);
|
|
68
|
+
(0, cmd_1.runCommandExec)(startSessionCmd, `Now set to use ${roleText}. (session expires in ${expirationMessage})${(0, aws_1.getAwsEnvVarMessage)()}`, `Failed to use ${roleText}.`);
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
default:
|
|
72
|
-
return apollo_1.handleError(this, undefined, session);
|
|
72
|
+
return (0, apollo_1.handleError)(this, undefined, session);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
exports.default = StartIAMRoleSession;
|
|
77
76
|
StartIAMRoleSession.description = 'Starts a session to assume an IAM role.';
|
|
78
77
|
StartIAMRoleSession.examples = [
|
|
79
78
|
'opal iam-roles:start',
|
|
@@ -85,8 +84,9 @@ StartIAMRoleSession.flags = {
|
|
|
85
84
|
id: flags_1.SHARED_FLAGS.id,
|
|
86
85
|
sessionId: flags_1.SHARED_FLAGS.sessionId,
|
|
87
86
|
refresh: flags_1.SHARED_FLAGS.refresh,
|
|
88
|
-
profileName:
|
|
87
|
+
profileName: core_1.Flags.string({
|
|
89
88
|
multiple: false,
|
|
90
89
|
description: 'Uses a custom AWS profile name for the IAM role. Default value is the role\'s name.',
|
|
91
90
|
}),
|
|
92
91
|
};
|
|
92
|
+
exports.default = StartIAMRoleSession;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Command } from '@oclif/
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export default class StartKubeIAMRoleSession extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
help: import("@oclif/
|
|
7
|
-
id: import("@oclif/
|
|
8
|
-
accessLevelRemoteId: import("@oclif/
|
|
9
|
-
sessionId: import("@oclif/
|
|
10
|
-
refresh: import("@oclif/
|
|
6
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
7
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
accessLevelRemoteId: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
sessionId: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
refresh: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
11
|
};
|
|
12
12
|
run(): Promise<void>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
4
|
const cmd_1 = require("../../lib/cmd");
|
|
5
5
|
const apollo_1 = require("../../lib/apollo");
|
|
6
6
|
const aws_1 = require("../../lib/aws");
|
|
@@ -15,28 +15,28 @@ const EksSessionMetadataFragment = `
|
|
|
15
15
|
clusterName
|
|
16
16
|
clusterRegion
|
|
17
17
|
}`;
|
|
18
|
-
class StartKubeIAMRoleSession extends
|
|
18
|
+
class StartKubeIAMRoleSession extends core_1.Command {
|
|
19
19
|
async run() {
|
|
20
|
-
cmd_1.setMostRecentCommand(this);
|
|
21
|
-
const { flags } = this.parse(StartKubeIAMRoleSession);
|
|
20
|
+
(0, cmd_1.setMostRecentCommand)(this);
|
|
21
|
+
const { flags } = await this.parse(StartKubeIAMRoleSession);
|
|
22
22
|
if (flags.sessionId && flags.refresh) {
|
|
23
|
-
return apollo_1.handleError(this, 'Cannot use both --sessionId and --refresh');
|
|
23
|
+
return (0, apollo_1.handleError)(this, 'Cannot use both --sessionId and --refresh');
|
|
24
24
|
}
|
|
25
25
|
let clusterId = flags.id;
|
|
26
26
|
const sessionId = flags.sessionId;
|
|
27
27
|
if (!clusterId) {
|
|
28
|
-
const selectedCluster = await resources_1.promptUserForResource(this, 'AWS_EKS_CLUSTER', 'Select an EKS Kubernetes cluster to connect to');
|
|
28
|
+
const selectedCluster = await (0, resources_1.promptUserForResource)(this, 'AWS_EKS_CLUSTER', 'Select an EKS Kubernetes cluster to connect to');
|
|
29
29
|
if (!selectedCluster) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
clusterId = selectedCluster.id;
|
|
33
33
|
}
|
|
34
34
|
// Fetch all access levels for resource
|
|
35
|
-
const accessLevel = await resources_1.promptUserForAccessLevels(this, clusterId, 'Kubernetes cluster', flags.accessLevelRemoteId);
|
|
35
|
+
const accessLevel = await (0, resources_1.promptUserForAccessLevels)(this, clusterId, 'Kubernetes cluster', flags.accessLevelRemoteId);
|
|
36
36
|
if (!accessLevel) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const session = await sessions_1.getOrCreateSession(this, clusterId, accessLevel, sessionId, EksSessionMetadataFragment, flags.refresh);
|
|
39
|
+
const session = await (0, sessions_1.getOrCreateSession)(this, clusterId, accessLevel, sessionId, EksSessionMetadataFragment, flags.refresh);
|
|
40
40
|
if (!session) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -44,20 +44,19 @@ class StartKubeIAMRoleSession extends command_1.Command {
|
|
|
44
44
|
switch (metadata === null || metadata === void 0 ? void 0 : metadata.__typename) {
|
|
45
45
|
case 'AwsIamFederatedEksSession': {
|
|
46
46
|
const roleName = accessLevel.accessLevelName;
|
|
47
|
-
const updateAwsConfigCommand = aws_1.getAwsConfigUpdateCmd(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
|
|
47
|
+
const updateAwsConfigCommand = (0, aws_1.getAwsConfigUpdateCmd)(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
|
|
48
48
|
const updateKubeConfigCmd = `aws eks update-kubeconfig --name ${metadata.clusterName} --region ${metadata.clusterRegion} --alias ${metadata.clusterName} --profile opal`;
|
|
49
49
|
const startSessionCmd = `${updateAwsConfigCommand} && ${updateKubeConfigCmd}`;
|
|
50
50
|
const roleText = roleName ? `"${roleName}" role` : 'role';
|
|
51
|
-
const expirationMessage = sessions_1.getSessionExpirationMessage(session);
|
|
52
|
-
cmd_1.runCommandExec(startSessionCmd, `Now set to use ${roleText} with updated Kube config pointing to "${metadata.clusterName}" cluster. (session expires in ${expirationMessage})${aws_1.getAwsEnvVarMessage()}`, `Failed to assume ${roleText} and update Kube config.`);
|
|
51
|
+
const expirationMessage = (0, sessions_1.getSessionExpirationMessage)(session);
|
|
52
|
+
(0, cmd_1.runCommandExec)(startSessionCmd, `Now set to use ${roleText} with updated Kube config pointing to "${metadata.clusterName}" cluster. (session expires in ${expirationMessage})${(0, aws_1.getAwsEnvVarMessage)()}`, `Failed to assume ${roleText} and update Kube config.`);
|
|
53
53
|
break;
|
|
54
54
|
}
|
|
55
55
|
default:
|
|
56
|
-
return apollo_1.handleError(this, undefined, session);
|
|
56
|
+
return (0, apollo_1.handleError)(this, undefined, session);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
exports.default = StartKubeIAMRoleSession;
|
|
61
60
|
StartKubeIAMRoleSession.description = 'Starts a session to assume a Kubernetes cluster IAM role.';
|
|
62
61
|
StartKubeIAMRoleSession.examples = [
|
|
63
62
|
'opal kube-roles:start',
|
|
@@ -71,3 +70,4 @@ StartKubeIAMRoleSession.flags = {
|
|
|
71
70
|
sessionId: flags_1.SHARED_FLAGS.sessionId,
|
|
72
71
|
refresh: flags_1.SHARED_FLAGS.refresh,
|
|
73
72
|
};
|
|
73
|
+
exports.default = StartKubeIAMRoleSession;
|
package/lib/commands/login.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export declare const CLISignInMethodName = "CLISignInMethod";
|
|
3
3
|
export declare const CLIAuthSessionCheckName = "CLIAuthSessionCheck";
|
|
4
4
|
export declare const CLIAuthSessionCheckDocument = "\nquery CLIAuthSessionCheck {\n organizationSettings {\n ... on OrganizationSettingsResult {\n settings {\n id\n }\n }\n }\n}\n";
|
|
@@ -6,9 +6,9 @@ export default class Login extends Command {
|
|
|
6
6
|
static description: string;
|
|
7
7
|
static examples: string[];
|
|
8
8
|
static flags: {
|
|
9
|
-
help: import("@oclif/
|
|
10
|
-
email:
|
|
9
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
|
+
email: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
11
|
};
|
|
12
|
-
static args:
|
|
12
|
+
static args: {};
|
|
13
13
|
run(): Promise<void>;
|
|
14
14
|
}
|
package/lib/commands/login.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CLIAuthSessionCheckDocument = exports.CLIAuthSessionCheckName = exports.CLISignInMethodName = void 0;
|
|
4
|
-
const
|
|
5
|
-
const keytar = require("keytar");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
6
5
|
const open = require("open");
|
|
7
6
|
const openid_client_1 = require("openid-client");
|
|
8
7
|
const apollo_1 = require("../lib/apollo");
|
|
@@ -55,26 +54,25 @@ query CLIAuthSessionCheck {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
`;
|
|
58
|
-
class Login extends
|
|
57
|
+
class Login extends core_1.Command {
|
|
59
58
|
async run() {
|
|
60
59
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
61
60
|
try {
|
|
62
|
-
await apollo_1.initClient(this);
|
|
63
|
-
const { flags } = this.parse(Login);
|
|
61
|
+
await (0, apollo_1.initClient)(this, false);
|
|
62
|
+
const { flags } = await this.parse(Login);
|
|
64
63
|
const configDir = this.config.configDir;
|
|
65
|
-
const configData = config_1.getOrCreateConfigData(configDir);
|
|
64
|
+
const configData = (0, config_1.getOrCreateConfigData)(configDir);
|
|
66
65
|
let email = flags.email;
|
|
67
66
|
let organizationID;
|
|
68
67
|
let clientIdCandidate;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
await credentials_1.cred.removeCredentials(-1);
|
|
68
|
+
const existingCreds = await (0, credentials_1.getOpalCredentials)(this, false);
|
|
69
|
+
// Only use the previous email + organizationID if email isn't explicitly specified.
|
|
70
|
+
if (!email) {
|
|
71
|
+
email = existingCreds.email;
|
|
72
|
+
organizationID = existingCreds.organizationID;
|
|
73
|
+
clientIdCandidate = existingCreds.clientIDCandidate;
|
|
77
74
|
}
|
|
75
|
+
await (0, credentials_1.removeOpalCredentials)(this);
|
|
78
76
|
this.log('Welcome to Opal! ⚡️\n');
|
|
79
77
|
this.log('Connecting to Opal server URL:', configData[config_1.urlKey]);
|
|
80
78
|
this.log('If this is incorrect, please run `opal set-url --help`\n');
|
|
@@ -92,14 +90,14 @@ class Login extends command_1.Command {
|
|
|
92
90
|
}
|
|
93
91
|
if (!organizationID) {
|
|
94
92
|
let signInOrganizationsLegacyResponse;
|
|
95
|
-
const { resp: signInOrganizationsResponse, error } = await handler_1.runQuery({
|
|
93
|
+
const { resp: signInOrganizationsResponse, error } = await (0, handler_1.runQuery)({
|
|
96
94
|
command: this,
|
|
97
95
|
query: CLISignInMethodDocument,
|
|
98
96
|
variables: { input: { email } },
|
|
99
97
|
});
|
|
100
|
-
if (error) {
|
|
98
|
+
if (error && error.networkError) {
|
|
101
99
|
if ('statusCode' in error.networkError && error.networkError.statusCode === 422) {
|
|
102
|
-
const { resp, error: legacyError } = await handler_1.runQuery({
|
|
100
|
+
const { resp, error: legacyError } = await (0, handler_1.runQuery)({
|
|
103
101
|
command: this,
|
|
104
102
|
query: CLISignInMethodDocumentLegacy,
|
|
105
103
|
variables: { input: { email } },
|
|
@@ -107,15 +105,16 @@ class Login extends command_1.Command {
|
|
|
107
105
|
signInOrganizationsLegacyResponse = resp;
|
|
108
106
|
if (legacyError) {
|
|
109
107
|
this.log(''); // Intentional newline
|
|
110
|
-
return apollo_1.handleError(this, 'Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)');
|
|
108
|
+
return (0, apollo_1.handleError)(this, 'Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)');
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
else {
|
|
114
112
|
this.log(''); // Intentional newline
|
|
115
|
-
return apollo_1.handleError(this, 'Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)');
|
|
113
|
+
return (0, apollo_1.handleError)(this, 'Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)');
|
|
116
114
|
}
|
|
117
115
|
}
|
|
118
|
-
const signInOrganizations = signInOrganizationsResponse ? (_b = (_a = signInOrganizationsResponse === null || signInOrganizationsResponse === void 0 ? void 0 : signInOrganizationsResponse.data) === null || _a === void 0 ? void 0 : _a.signInMethod) === null || _b === void 0 ? void 0 : _b.signInOrganizations :
|
|
116
|
+
const signInOrganizations = signInOrganizationsResponse ? (_b = (_a = signInOrganizationsResponse === null || signInOrganizationsResponse === void 0 ? void 0 : signInOrganizationsResponse.data) === null || _a === void 0 ? void 0 : _a.signInMethod) === null || _b === void 0 ? void 0 : _b.signInOrganizations :
|
|
117
|
+
(_d = (_c = signInOrganizationsLegacyResponse === null || signInOrganizationsLegacyResponse === void 0 ? void 0 : signInOrganizationsLegacyResponse.data) === null || _c === void 0 ? void 0 : _c.signInMethod) === null || _d === void 0 ? void 0 : _d.signInOrganizations;
|
|
119
118
|
if (signInOrganizations && signInOrganizations.length > 0) {
|
|
120
119
|
if (signInOrganizations.length === 1) {
|
|
121
120
|
organizationID = signInOrganizations[0].organizationId;
|
|
@@ -141,7 +140,7 @@ class Login extends command_1.Command {
|
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
let issuer;
|
|
144
|
-
if (config_1.isProduction(this.config.configDir)) {
|
|
143
|
+
if ((0, config_1.isProduction)(this.config.configDir)) {
|
|
145
144
|
issuer = await openid_client_1.Issuer.discover(ISSUER_PROD);
|
|
146
145
|
}
|
|
147
146
|
else {
|
|
@@ -151,7 +150,7 @@ class Login extends command_1.Command {
|
|
|
151
150
|
if (clientIdCandidate) {
|
|
152
151
|
clientId = clientIdCandidate;
|
|
153
152
|
}
|
|
154
|
-
else if (config_1.isProduction(this.config.configDir)) {
|
|
153
|
+
else if ((0, config_1.isProduction)(this.config.configDir)) {
|
|
155
154
|
clientId = CLIENT_ID_PROD;
|
|
156
155
|
}
|
|
157
156
|
else {
|
|
@@ -175,7 +174,7 @@ class Login extends command_1.Command {
|
|
|
175
174
|
this.log(` User Code: ${handle.user_code}\n`);
|
|
176
175
|
// Wait before opening the browser window to ensure the user has time to
|
|
177
176
|
// see the User Code.
|
|
178
|
-
await util_1.sleep(1000);
|
|
177
|
+
await (0, util_1.sleep)(1000);
|
|
179
178
|
await open(handle.verification_uri_complete, { wait: false });
|
|
180
179
|
const tokenSet = await handle.poll();
|
|
181
180
|
const userInfo = await client.userinfo(tokenSet);
|
|
@@ -184,17 +183,17 @@ class Login extends command_1.Command {
|
|
|
184
183
|
// Save the clientIdCandidate only when SAML is set up for the org.
|
|
185
184
|
account = account + '|' + clientIdCandidate;
|
|
186
185
|
}
|
|
187
|
-
await
|
|
186
|
+
await (0, credentials_1.setOpalCredentials)(this, userInfo.email, organizationID, clientIdCandidate, (tokenSet === null || tokenSet === void 0 ? void 0 : tokenSet.access_token) || '');
|
|
188
187
|
// "Representative" authenticated call to check the log-in worked as expected.
|
|
189
|
-
const { resp: authCheckResp, error: authCheckErr } = await handler_1.runQuery({
|
|
188
|
+
const { resp: authCheckResp, error: authCheckErr } = await (0, handler_1.runQuery)({
|
|
190
189
|
command: this,
|
|
191
190
|
query: exports.CLIAuthSessionCheckDocument,
|
|
192
191
|
variables: {},
|
|
193
192
|
});
|
|
194
193
|
if (authCheckErr || !((_g = (_f = (_e = authCheckResp === null || authCheckResp === void 0 ? void 0 : authCheckResp.data) === null || _e === void 0 ? void 0 : _e.organizationSettings) === null || _f === void 0 ? void 0 : _f.settings) === null || _g === void 0 ? void 0 : _g.id)) {
|
|
195
194
|
this.log('Error verifying log in. Authenticated commands may fail. Please double check your URL and use `opal logout; opal login` to try again.\n');
|
|
196
|
-
await credentials_1.
|
|
197
|
-
apollo_1.handleError(this, authCheckErr);
|
|
195
|
+
await (0, credentials_1.removeOpalCredentials)(this);
|
|
196
|
+
(0, apollo_1.handleError)(this, authCheckErr);
|
|
198
197
|
}
|
|
199
198
|
this.log('🎉 You have successfully authenticated with Opal! You can now run authenticated commands.\n');
|
|
200
199
|
}
|
|
@@ -203,14 +202,14 @@ class Login extends command_1.Command {
|
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
|
-
exports.default = Login;
|
|
207
205
|
Login.description = 'Authenticates you with the Opal server.';
|
|
208
206
|
Login.examples = ['$ opal login'];
|
|
209
207
|
Login.flags = {
|
|
210
208
|
help: flags_1.SHARED_FLAGS.help,
|
|
211
|
-
email:
|
|
209
|
+
email: core_1.Flags.string({
|
|
212
210
|
multiple: false,
|
|
213
211
|
description: 'Email address to login with.',
|
|
214
212
|
}),
|
|
215
213
|
};
|
|
216
|
-
Login.args =
|
|
214
|
+
Login.args = {};
|
|
215
|
+
exports.default = Login;
|
package/lib/commands/logout.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Command } from '@oclif/
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export default class Logout extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
help: import("@oclif/
|
|
6
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
|
-
static args:
|
|
8
|
+
static args: {};
|
|
9
9
|
run(): Promise<void>;
|
|
10
10
|
}
|
package/lib/commands/logout.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
4
|
const credentials_1 = require("../lib/credentials");
|
|
5
5
|
const flags_1 = require("../lib/flags");
|
|
6
|
-
class Logout extends
|
|
6
|
+
class Logout extends core_1.Command {
|
|
7
7
|
async run() {
|
|
8
8
|
try {
|
|
9
|
-
await credentials_1.
|
|
9
|
+
await (0, credentials_1.removeOpalCredentials)(this);
|
|
10
10
|
this.log('Successfully removed the saved Account ID and Auth Token from this computer');
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
@@ -14,10 +14,10 @@ class Logout extends command_1.Command {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
exports.default = Logout;
|
|
18
17
|
Logout.description = 'Clears locally stored Opal server authentication credentials.';
|
|
19
18
|
Logout.examples = ['$ opal logout'];
|
|
20
19
|
Logout.flags = {
|
|
21
20
|
help: flags_1.SHARED_FLAGS.help,
|
|
22
21
|
};
|
|
23
|
-
Logout.args =
|
|
22
|
+
Logout.args = {};
|
|
23
|
+
exports.default = Logout;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const keytar = require("keytar");
|
|
5
|
+
const credentials_1 = require("../lib/credentials");
|
|
6
|
+
const flags_1 = require("../lib/flags");
|
|
7
|
+
const OPAL_KEYTAR_CREDS_KEY = 'opal';
|
|
8
|
+
/**
|
|
9
|
+
* This command helps users migrate from the old credential store w/ keytar to the new credential store
|
|
10
|
+
* It should only be recommended to users on OSX, since keytar does not reliably work on linux/WSL
|
|
11
|
+
*
|
|
12
|
+
* TODO: delete this after some time has passed, and users have likely migrated their credentials over
|
|
13
|
+
*/
|
|
14
|
+
const removeKeytarCreds = async () => {
|
|
15
|
+
const keyContents = await keytar.findCredentials(OPAL_KEYTAR_CREDS_KEY);
|
|
16
|
+
keyContents === null || keyContents === void 0 ? void 0 : keyContents.forEach(credential => keytar.deletePassword(OPAL_KEYTAR_CREDS_KEY, credential.account));
|
|
17
|
+
};
|
|
18
|
+
const getKeytarCreds = async () => {
|
|
19
|
+
const keyContents = await keytar.findCredentials(OPAL_KEYTAR_CREDS_KEY);
|
|
20
|
+
if (!keyContents[0]) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const { account, password } = keyContents[0];
|
|
24
|
+
const parts = account.split('|') || [];
|
|
25
|
+
return {
|
|
26
|
+
email: parts[0],
|
|
27
|
+
organizationID: parts[1],
|
|
28
|
+
clientIDCandidate: parts[2],
|
|
29
|
+
accessToken: password
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
class MigrateCreds extends core_1.Command {
|
|
33
|
+
async run() {
|
|
34
|
+
const creds = await getKeytarCreds();
|
|
35
|
+
if (!creds) {
|
|
36
|
+
this.log("No credentials found in system keystore that need to be migrated");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
(0, credentials_1.setOpalCredentials)(this, creds.email, creds.organizationID, creds.clientIDCandidate, creds.accessToken);
|
|
40
|
+
await removeKeytarCreds();
|
|
41
|
+
this.log("Successfully migrated credentials from system keystore to new store. You should now be able to use the CLI normally, without re-authenticating");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
MigrateCreds.description = 'Migrates credentials from old keystore to new store. Should only need to be run once';
|
|
45
|
+
MigrateCreds.flags = {
|
|
46
|
+
help: flags_1.SHARED_FLAGS.help,
|
|
47
|
+
};
|
|
48
|
+
exports.default = MigrateCreds;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
2
|
export default class StartPostgresInstanceSession extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
help: import("@oclif/
|
|
7
|
-
id:
|
|
8
|
-
accessLevelRemoteId:
|
|
9
|
-
sessionId:
|
|
10
|
-
refresh: import("@oclif/
|
|
11
|
-
action:
|
|
6
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
7
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
accessLevelRemoteId: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
sessionId: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
refresh: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
action: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
12
12
|
};
|
|
13
13
|
run(): Promise<void>;
|
|
14
14
|
}
|