opal-security 2.0.20 → 2.1.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.
Files changed (44) hide show
  1. package/README.md +100 -59
  2. package/lib/commands/aws/identity.js +2 -1
  3. package/lib/commands/curl-example.js +2 -1
  4. package/lib/commands/iam-roles/start.d.ts +1 -0
  5. package/lib/commands/iam-roles/start.js +38 -134
  6. package/lib/commands/kube-roles/start.d.ts +5 -4
  7. package/lib/commands/kube-roles/start.js +32 -135
  8. package/lib/commands/login.d.ts +2 -1
  9. package/lib/commands/login.js +36 -25
  10. package/lib/commands/logout.js +2 -1
  11. package/lib/commands/postgres-instances/start.d.ts +2 -0
  12. package/lib/commands/postgres-instances/start.js +84 -151
  13. package/lib/commands/resources/get.d.ts +3 -3
  14. package/lib/commands/resources/get.js +22 -6
  15. package/lib/commands/set-custom-header.js +2 -1
  16. package/lib/commands/set-token.js +2 -1
  17. package/lib/commands/set-url.d.ts +6 -3
  18. package/lib/commands/set-url.js +39 -13
  19. package/lib/commands/ssh/copyFrom.js +24 -78
  20. package/lib/commands/ssh/copyTo.js +24 -78
  21. package/lib/commands/ssh/start.d.ts +5 -3
  22. package/lib/commands/ssh/start.js +41 -89
  23. package/lib/handler.d.ts +1 -2
  24. package/lib/handler.js +0 -27
  25. package/lib/lib/apollo.d.ts +2 -1
  26. package/lib/lib/apollo.js +61 -31
  27. package/lib/lib/aws.js +3 -2
  28. package/lib/lib/cmd.d.ts +0 -11
  29. package/lib/lib/cmd.js +3 -15
  30. package/lib/lib/flags.d.ts +8 -0
  31. package/lib/lib/flags.js +26 -0
  32. package/lib/lib/resources.d.ts +13 -5
  33. package/lib/lib/resources.js +84 -24
  34. package/lib/lib/sessions.d.ts +4 -0
  35. package/lib/lib/sessions.js +165 -0
  36. package/lib/lib/ssh.d.ts +1 -3
  37. package/lib/lib/ssh.js +3 -49
  38. package/lib/lib/util.d.ts +4 -0
  39. package/lib/lib/util.js +38 -0
  40. package/lib/types.d.ts +1 -0
  41. package/oclif.manifest.json +1 -1
  42. package/package.json +2 -1
  43. package/lib/lib/common.d.ts +0 -3
  44. package/lib/lib/common.js +0 -20
package/README.md CHANGED
@@ -22,7 +22,7 @@ $ npm install -g opal-security
22
22
  $ opal COMMAND
23
23
  running command...
24
24
  $ opal (-v|--version|version)
25
- opal-security/2.0.20 darwin-x64 node-v14.16.1
25
+ opal-security/2.1.1 darwin-x64 node-v14.16.1
26
26
  $ opal --help [COMMAND]
27
27
  USAGE
28
28
  $ opal COMMAND
@@ -45,7 +45,7 @@ USAGE
45
45
  * [`opal resources:get`](#opal-resourcesget)
46
46
  * [`opal set-custom-header`](#opal-set-custom-header)
47
47
  * [`opal set-token`](#opal-set-token)
48
- * [`opal set-url`](#opal-set-url)
48
+ * [`opal set-url [URL]`](#opal-set-url-url)
49
49
  * [`opal ssh:copyFrom`](#opal-sshcopyfrom)
50
50
  * [`opal ssh:copyTo`](#opal-sshcopyto)
51
51
  * [`opal ssh:start`](#opal-sshstart)
@@ -88,7 +88,7 @@ EXAMPLE
88
88
  opal aws:identity
89
89
  ```
90
90
 
91
- _See code: [src/commands/aws/identity.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/aws/identity.ts)_
91
+ _See code: [src/commands/aws/identity.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/aws/identity.ts)_
92
92
 
93
93
  ## `opal curl-example`
94
94
 
@@ -102,7 +102,7 @@ OPTIONS
102
102
  -h, --help show CLI help
103
103
  ```
104
104
 
105
- _See code: [src/commands/curl-example.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/curl-example.ts)_
105
+ _See code: [src/commands/curl-example.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/curl-example.ts)_
106
106
 
107
107
  ## `opal help [COMMAND]`
108
108
 
@@ -131,9 +131,16 @@ USAGE
131
131
 
132
132
  OPTIONS
133
133
  -h, --help show CLI help
134
- --id=id The ID of the Opal role resource.
134
+
135
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
136
+ https://opal.dev/resources/[ID]
137
+
138
+ -r, --refresh Starts a new session even if one already exists. Useful if a session is about to expire.
139
+
140
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that was created via the
141
+ web flow.
142
+
135
143
  --profileName=profileName Uses a custom AWS profile name for the IAM role. Default value is the role's name.
136
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
137
144
 
138
145
  EXAMPLES
139
146
  opal iam-roles:start
@@ -141,7 +148,7 @@ EXAMPLES
141
148
  opal iam-roles:start --id 51f7176b-0464-4a6f-8369-e951e187b398 --profileName "custom-profile"
142
149
  ```
143
150
 
144
- _See code: [src/commands/iam-roles/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/iam-roles/start.ts)_
151
+ _See code: [src/commands/iam-roles/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/iam-roles/start.ts)_
145
152
 
146
153
  ## `opal kube-roles:start`
147
154
 
@@ -152,10 +159,17 @@ USAGE
152
159
  $ opal kube-roles:start
153
160
 
154
161
  OPTIONS
155
- -h, --help show CLI help
156
- --accessLevelRemoteId=accessLevelRemoteId The remote ID of the access level with which to access the cluster.
157
- --id=id The ID of the Opal role resource.
158
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
162
+ -a, --accessLevelRemoteId=accessLevelRemoteId The remote ID of the access level with which to access the resource.
163
+ -h, --help show CLI help
164
+
165
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
166
+ https://opal.dev/resources/[ID]
167
+
168
+ -r, --refresh Starts a new session even if one already exists. Useful if a session is
169
+ about to expire.
170
+
171
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that
172
+ was created via the web flow.
159
173
 
160
174
  EXAMPLES
161
175
  opal kube-roles:start
@@ -164,7 +178,7 @@ EXAMPLES
164
178
  "arn:aws:iam::712234975475:role/acme-eks-cluster-admin-role"
165
179
  ```
166
180
 
167
- _See code: [src/commands/kube-roles/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/kube-roles/start.ts)_
181
+ _See code: [src/commands/kube-roles/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/kube-roles/start.ts)_
168
182
 
169
183
  ## `opal login`
170
184
 
@@ -175,13 +189,14 @@ USAGE
175
189
  $ opal login
176
190
 
177
191
  OPTIONS
178
- -h, --help show CLI help
192
+ -h, --help show CLI help
193
+ --email=email Email address to login with.
179
194
 
180
195
  EXAMPLE
181
196
  $ opal login
182
197
  ```
183
198
 
184
- _See code: [src/commands/login.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/login.ts)_
199
+ _See code: [src/commands/login.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/login.ts)_
185
200
 
186
201
  ## `opal logout`
187
202
 
@@ -198,29 +213,42 @@ EXAMPLE
198
213
  $ opal logout
199
214
  ```
200
215
 
201
- _See code: [src/commands/logout.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/logout.ts)_
216
+ _See code: [src/commands/logout.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/logout.ts)_
202
217
 
203
218
  ## `opal postgres-instances:start`
204
219
 
205
- Starts a session to query a Postgres database.
220
+ Starts a session to connect to a Postgres database.
206
221
 
207
222
  ```
208
223
  USAGE
209
224
  $ opal postgres-instances:start
210
225
 
211
226
  OPTIONS
212
- -h, --help show CLI help
213
- --accessLevelRemoteId=accessLevelRemoteId The remote ID of the access level with which to access the database.
214
- --id=id The ID of the Opal instance resource.
215
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
227
+ -a, --accessLevelRemoteId=accessLevelRemoteId The remote ID of the access level with which to access the resource.
228
+ -h, --help show CLI help
229
+
230
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
231
+ https://opal.dev/resources/[ID]
232
+
233
+ -r, --refresh Starts a new session even if one already exists. Useful if a session is
234
+ about to expire.
235
+
236
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that
237
+ was created via the web flow.
238
+
239
+ --action=open|psql|view Method of connecting to the database.
240
+ - open: Open external database app
241
+ - psql: Start psql session in shell
242
+ - view: View connection configuration details
216
243
 
217
244
  EXAMPLES
218
245
  opal postgres-instances:start
219
246
  opal postgres-instances:start --id 51f7176b-0464-4a6f-8369-e951e187b398
220
- opal postgres-instances:start --id 51f7176b-0464-4a6f-8369-e951e187b398 --accessLevelRemoteId "fullaccess"
247
+ opal postgres-instances:start --id 51f7176b-0464-4a6f-8369-e951e187b398 --accessLevelRemoteId fullaccess
248
+ opal postgres-instances:start --id 51f7176b-0464-4a6f-8369-e951e187b398 --accessLevelRemoteId fullaccess --action view
221
249
  ```
222
250
 
223
- _See code: [src/commands/postgres-instances/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/postgres-instances/start.ts)_
251
+ _See code: [src/commands/postgres-instances/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/postgres-instances/start.ts)_
224
252
 
225
253
  ## `opal resources:get`
226
254
 
@@ -231,14 +259,14 @@ USAGE
231
259
  $ opal resources:get
232
260
 
233
261
  OPTIONS
234
- -h, --help show CLI help
235
- --id=id (required)
262
+ -h, --help show CLI help
263
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g. https://opal.dev/resources/[ID]
236
264
 
237
265
  EXAMPLE
238
266
  opal resources:get --id 54052a3e-5375-4392-aeaf-0c6c44c131d4
239
267
  ```
240
268
 
241
- _See code: [src/commands/resources/get.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/resources/get.ts)_
269
+ _See code: [src/commands/resources/get.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/resources/get.ts)_
242
270
 
243
271
  ## `opal set-custom-header`
244
272
 
@@ -256,7 +284,7 @@ EXAMPLE
256
284
  $ opal set-custom-header --header 'cf-access-token: $TOKEN'
257
285
  ```
258
286
 
259
- _See code: [src/commands/set-custom-header.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/set-custom-header.ts)_
287
+ _See code: [src/commands/set-custom-header.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/set-custom-header.ts)_
260
288
 
261
289
  ## `opal set-token`
262
290
 
@@ -273,31 +301,28 @@ EXAMPLE
273
301
  $ opal set-token
274
302
  ```
275
303
 
276
- _See code: [src/commands/set-token.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/set-token.ts)_
304
+ _See code: [src/commands/set-token.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/set-token.ts)_
277
305
 
278
- ## `opal set-url`
306
+ ## `opal set-url [URL]`
279
307
 
280
308
  Sets the url of the Opal server. Defaults to https://app.opal.dev.
281
309
 
282
310
  ```
283
311
  USAGE
284
- $ opal set-url
312
+ $ opal set-url [URL]
313
+
314
+ ARGUMENTS
315
+ URL URL of the Opal server to use. If unspecified, defaults to https://app.opal.dev
285
316
 
286
317
  OPTIONS
287
318
  -h, --help show CLI help
288
319
  --allowSelfSignedCerts
289
- --custom=custom
290
- --demo
291
- --dev
292
- --devLocal
293
- --prod
294
- --staging
295
320
 
296
321
  EXAMPLE
297
322
  $ opal set-url
298
323
  ```
299
324
 
300
- _See code: [src/commands/set-url.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/set-url.ts)_
325
+ _See code: [src/commands/set-url.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/set-url.ts)_
301
326
 
302
327
  ## `opal ssh:copyFrom`
303
328
 
@@ -308,23 +333,28 @@ USAGE
308
333
  $ opal ssh:copyFrom
309
334
 
310
335
  OPTIONS
311
- -h, --help show CLI help
312
- --dest=dest [default: .] Pick which directory you want your files to be copied to.
313
- --id=id The ID of the Opal instance resource.
314
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
336
+ -h, --help show CLI help
337
+
338
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
339
+ https://opal.dev/resources/[ID]
315
340
 
316
- --src=src (required) The path of the directory or file you would like to copy over SCP. Note we only
317
- support one file or directory at a time.
341
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that was created via the
342
+ web flow.
318
343
 
319
- --user=user [default: ssm-user] Pick which user you want to run SCP over. Keep in mind not all users will
320
- have access to each other's home directory.
344
+ --dest=dest [default: .] The directory you want your files to be copied to.
345
+
346
+ --src=src (required) The directory or file you would like to copy over SCP. Note we only support one
347
+ file or directory at a time.
348
+
349
+ --user=user [default: ssm-user] The user you want to run SCP over. Keep in mind not all users will have
350
+ access to each other's home directory.
321
351
 
322
352
  EXAMPLES
323
353
  opal ssh:copyFrom --src instance/dir --dest my/dir
324
354
  opal ssh:copyFrom --src instance/dir --dest my/dir --id 51f7176b-0464-4a6f-8369-e951e187b398
325
355
  ```
326
356
 
327
- _See code: [src/commands/ssh/copyFrom.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/ssh/copyFrom.ts)_
357
+ _See code: [src/commands/ssh/copyFrom.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/ssh/copyFrom.ts)_
328
358
 
329
359
  ## `opal ssh:copyTo`
330
360
 
@@ -335,41 +365,52 @@ USAGE
335
365
  $ opal ssh:copyTo
336
366
 
337
367
  OPTIONS
338
- -h, --help show CLI help
339
- --dest=dest [default: .] Pick which directory you want your files to be copied to.
340
- --id=id The ID of the Opal instance resource.
341
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
368
+ -h, --help show CLI help
342
369
 
343
- --src=src (required) The path of the directory or file you would like to copy over SCP. Note we only
344
- support one file or directory at a time.
370
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
371
+ https://opal.dev/resources/[ID]
345
372
 
346
- --user=user [default: ssm-user] Pick which user you want to run SCP over. Keep in mind not all users will
347
- have access to each other's home directory.
373
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that was created via the
374
+ web flow.
375
+
376
+ --dest=dest [default: .] The directory you want your files to be copied to.
377
+
378
+ --src=src (required) The directory or file you would like to copy over SCP. Note we only support one
379
+ file or directory at a time.
380
+
381
+ --user=user [default: ssm-user] The user you want to run SCP over. Keep in mind not all users will have
382
+ access to each other's home directory.
348
383
 
349
384
  EXAMPLES
350
385
  opal ssh:copyTo --src my/dir --dest instance/dir
351
386
  opal ssh:copyTo --src my/dir --dest instance/dir --id 51f7176b-0464-4a6f-8369-e951e187b398
352
387
  ```
353
388
 
354
- _See code: [src/commands/ssh/copyTo.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/ssh/copyTo.ts)_
389
+ _See code: [src/commands/ssh/copyTo.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/ssh/copyTo.ts)_
355
390
 
356
391
  ## `opal ssh:start`
357
392
 
358
- Start an SSH session to access a particular compute instance.
393
+ Starts an SSH session to access a compute instance.
359
394
 
360
395
  ```
361
396
  USAGE
362
397
  $ opal ssh:start
363
398
 
364
399
  OPTIONS
365
- -h, --help show CLI help
366
- --id=id The ID of the Opal instance resource.
367
- --sessionId=sessionId SessionId of a session that has already been created via the web flow.
400
+ -h, --help show CLI help
401
+
402
+ -i, --id=id The Opal ID of the resource. You can find this from the URL, e.g.
403
+ https://opal.dev/resources/[ID]
404
+
405
+ -r, --refresh Starts a new session even if one already exists. Useful if a session is about to expire.
406
+
407
+ -s, --sessionId=sessionId The Opal ID of the session to connect to. Uses an existing session that was created via the
408
+ web flow.
368
409
 
369
410
  EXAMPLES
370
411
  opal ssh:start
371
412
  opal ssh:start --id 51f7176b-0464-4a6f-8369-e951e187b398
372
413
  ```
373
414
 
374
- _See code: [src/commands/ssh/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.0.20/src/commands/ssh/start.ts)_
415
+ _See code: [src/commands/ssh/start.ts](https://github.com/opalsecurity/opal-cli/blob/v2.1.1/src/commands/ssh/start.ts)_
375
416
  <!-- commandsstop -->
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@oclif/command");
4
4
  const cmd_1 = require("../../lib/cmd");
5
+ const flags_1 = require("../../lib/flags");
5
6
  class Identity extends command_1.Command {
6
7
  async run() {
7
8
  cmd_1.setMostRecentCommand(this);
@@ -13,5 +14,5 @@ exports.default = Identity;
13
14
  Identity.description = 'Gets the current caller identity for the "opal" AWS profile.';
14
15
  Identity.examples = ['opal aws:identity'];
15
16
  Identity.flags = {
16
- help: command_1.flags.help({ char: 'h' }),
17
+ help: flags_1.SHARED_FLAGS.help,
17
18
  };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@oclif/command");
4
4
  const config_1 = require("../lib/config");
5
5
  const credentials_1 = require("../lib/credentials");
6
+ const flags_1 = require("../lib/flags");
6
7
  class CurlExample extends command_1.Command {
7
8
  async run() {
8
9
  const accessToken = await credentials_1.cred.accessToken;
@@ -21,5 +22,5 @@ curl -v ${url}/query \\
21
22
  exports.default = CurlExample;
22
23
  CurlExample.description = 'Prints out an example cURL command containing the parameters the CLI uses to query the Opal server.';
23
24
  CurlExample.flags = {
24
- help: command_1.flags.help({ char: 'h' }),
25
+ help: flags_1.SHARED_FLAGS.help,
25
26
  };
@@ -6,6 +6,7 @@ export default class StartIAMRoleSession extends Command {
6
6
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
7
7
  id: flags.IOptionFlag<string | undefined>;
8
8
  sessionId: flags.IOptionFlag<string | undefined>;
9
+ refresh: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
10
  profileName: flags.IOptionFlag<string | undefined>;
10
11
  };
11
12
  run(): Promise<void>;
@@ -4,160 +4,69 @@ const command_1 = require("@oclif/command");
4
4
  const handler_1 = require("../../handler");
5
5
  const cmd_1 = require("../../lib/cmd");
6
6
  const apollo_1 = require("../../lib/apollo");
7
- const inquirer = require("inquirer");
8
7
  const aws_1 = require("../../lib/aws");
9
8
  const resources_1 = require("../../lib/resources");
10
9
  const get_1 = require("../../commands/resources/get");
11
- const common_1 = require("../../lib/common");
12
- const StartIAMRoleSessionDocument = `
13
- mutation StartIAMRoleSession($id: ResourceId!, $accessLevel: ResourceAccessLevelInput!, $sessionId: SessionId) {
14
- createSession(input: {resourceId: $id, accessLevel: $accessLevel, sessionId: $sessionId}) {
15
- __typename
16
- ... on CreateSessionResult {
17
- session {
18
- id
19
- endTime
20
- metadata {
21
- ... on AwsIamFederatedRoleSession {
22
- awsAccessKeyId
23
- awsSecretAccessKey
24
- awsSessionToken
25
- awsLoginUrl
26
- federatedArn
27
- }
28
- }
29
- }
30
- }
31
- ... on SessionNotFoundError {
32
- message
33
- }
34
- ... on MfaInvalidError {
35
- message
36
- }
37
- ... on OidcIDTokenNotFoundError {
38
- message
39
- }
40
- ... on ResourceNotFoundError {
41
- message
42
- }
43
- ... on EndSystemAuthorizationError {
44
- message
45
- }
46
- }
47
- }`;
48
- const ListIamRolesDocument = `
49
- query ListIAMRoles {
50
- resources(input: {resourceTypes: [AWS_IAM_ROLE], onlyMine: true, maxNumEntries: 1000}) {
51
- __typename
52
- ... on ResourcesResult {
53
- resources {
54
- name
55
- id
56
- }
57
- cursor
58
- }
59
- }
10
+ const sessions_1 = require("../../lib/sessions");
11
+ const flags_1 = require("../../lib/flags");
12
+ const IamSessionMetadataFragment = `
13
+ ... on AwsIamFederatedRoleSession {
14
+ awsAccessKeyId
15
+ awsSecretAccessKey
16
+ awsSessionToken
17
+ awsLoginUrl
18
+ federatedArn
60
19
  }`;
61
20
  class StartIAMRoleSession extends command_1.Command {
62
21
  async run() {
63
22
  cmd_1.setMostRecentCommand(this);
64
23
  const { flags } = this.parse(StartIAMRoleSession);
24
+ if (flags.sessionId && flags.refresh) {
25
+ return apollo_1.handleError(this, 'Cannot use both --sessionId and --refresh');
26
+ }
65
27
  let roleId = flags.id;
66
28
  let roleName = null;
67
29
  const sessionId = flags.sessionId;
68
30
  if (!roleId) {
69
- const { resp: iamRolesResp, error } = await handler_1.runQuery({
70
- command: this,
71
- query: ListIamRolesDocument,
72
- variables: {},
73
- });
74
- if (error) {
75
- apollo_1.printRequestOutput(this, iamRolesResp, error);
76
- return;
77
- }
78
- const resourceInfos = iamRolesResp === null || iamRolesResp === void 0 ? void 0 : iamRolesResp.data.resources.resources.map((resource) => {
79
- return {
80
- id: resource.id,
81
- name: resource.name,
82
- };
83
- });
84
- const noResourcesFound = resources_1.resourcesAreEmpty(this, resourceInfos);
85
- if (noResourcesFound) {
31
+ const selectedRole = await resources_1.promptUserForResource(this, 'AWS_IAM_ROLE', 'Select an IAM role to assume');
32
+ if (!selectedRole) {
86
33
  return;
87
34
  }
88
- const resourceInfoByName = {};
89
- resourceInfos.forEach(resourceInfo => {
90
- resourceInfoByName[resourceInfo.name] = resourceInfo;
91
- });
92
- inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
93
- const selectedIamRoleInfo = await inquirer.prompt([
94
- {
95
- name: 'role',
96
- message: 'Select an IAM role to assume',
97
- type: 'autocomplete',
98
- source: (answers, input) => cmd_1.filterChoices(input, resourceInfos),
99
- },
100
- ]);
101
- const selectedIamRole = resourceInfoByName[selectedIamRoleInfo.role];
102
- if (!selectedIamRole) {
103
- return;
104
- }
105
- roleId = selectedIamRole.id;
106
- roleName = selectedIamRole.name;
35
+ roleId = selectedRole.id;
36
+ roleName = selectedRole.name;
107
37
  }
108
38
  else {
109
- const { resp: sshInstanceResp, error } = await handler_1.runQuery({
39
+ const { resp, error } = await handler_1.runQuery({
110
40
  command: this,
111
41
  query: get_1.GetResourceDocument,
112
42
  variables: {
113
43
  id: roleId,
114
44
  },
115
45
  });
116
- if (error || !(sshInstanceResp === null || sshInstanceResp === void 0 ? void 0 : sshInstanceResp.data.resource.resource)) {
117
- apollo_1.printRequestOutput(this, sshInstanceResp, error);
118
- return;
46
+ if (error) {
47
+ return apollo_1.handleError(this, error, resp);
119
48
  }
120
- roleName = (sshInstanceResp === null || sshInstanceResp === void 0 ? void 0 : sshInstanceResp.data.resource.resource.name) || 'iam-role';
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}`);
51
+ }
52
+ roleName = (resp === null || resp === void 0 ? void 0 : resp.data.resource.resource.name) || 'iam-role';
121
53
  }
122
54
  if (flags.profileName && flags.profileName !== '') {
123
55
  roleName = flags.profileName;
124
56
  }
125
- const { resp, error } = await handler_1.runMutation({
126
- command: this,
127
- query: StartIAMRoleSessionDocument,
128
- variables: {
129
- id: roleId,
130
- accessLevel: cmd_1.DEFAULT_ACCESS_LEVEL,
131
- sessionId: sessionId,
132
- },
133
- });
134
- switch (resp === null || resp === void 0 ? void 0 : resp.data.createSession.__typename) {
135
- case 'CreateSessionResult': {
136
- const metadata = resp.data.createSession.session.metadata;
137
- switch (metadata === null || metadata === void 0 ? void 0 : metadata.__typename) {
138
- case 'AwsIamFederatedRoleSession': {
139
- const updateAwsConfigCommand = aws_1.getAwsConfigUpdateCmd(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
140
- const startSessionCmd = `${updateAwsConfigCommand}`;
141
- const awsEnvVarMessage = aws_1.getAwsEnvVarMessage();
142
- cmd_1.runCommandExec(startSessionCmd, `Now set to use ${roleName ? `"${roleName}" role` : 'role'}.${awsEnvVarMessage}`, `Failed to use ${roleName ? `"${roleName}" role` : 'role'}.`);
143
- this.log();
144
- break;
145
- }
146
- default:
147
- apollo_1.printRequestOutput(this, resp, error);
148
- }
149
- break;
150
- }
151
- case 'MfaInvalidError': {
152
- common_1.handleMfaRedirect(this, roleId);
153
- break;
154
- }
155
- case 'OidcIDTokenNotFoundError': {
156
- common_1.handleOidcRedirect(this, roleId);
57
+ const session = await sessions_1.getOrCreateSession(this, roleId, resources_1.DEFAULT_ACCESS_LEVEL, sessionId, IamSessionMetadataFragment, flags.refresh);
58
+ const metadata = session.metadata;
59
+ switch (metadata === null || metadata === void 0 ? void 0 : metadata.__typename) {
60
+ case 'AwsIamFederatedRoleSession': {
61
+ const updateAwsConfigCommand = aws_1.getAwsConfigUpdateCmd(roleName, metadata.awsAccessKeyId, metadata.awsSecretAccessKey, metadata.awsSessionToken);
62
+ const startSessionCmd = `${updateAwsConfigCommand}`;
63
+ const roleText = roleName ? `"${roleName}" role` : 'role';
64
+ const expirationMessage = sessions_1.getSessionExpirationMessage(session);
65
+ cmd_1.runCommandExec(startSessionCmd, `Now set to use ${roleText}. (session expires in ${expirationMessage})${aws_1.getAwsEnvVarMessage()}`, `Failed to use ${roleText}.`);
157
66
  break;
158
67
  }
159
68
  default:
160
- apollo_1.printRequestOutput(this, resp, error);
69
+ return apollo_1.handleError(this, undefined, session);
161
70
  }
162
71
  }
163
72
  }
@@ -169,17 +78,12 @@ StartIAMRoleSession.examples = [
169
78
  'opal iam-roles:start --id 51f7176b-0464-4a6f-8369-e951e187b398 --profileName "custom-profile"',
170
79
  ];
171
80
  StartIAMRoleSession.flags = {
172
- help: command_1.flags.help({ char: 'h' }),
173
- id: command_1.flags.string({
174
- multiple: false,
175
- description: 'The ID of the Opal role resource.',
176
- }),
177
- sessionId: command_1.flags.string({
178
- multiple: false,
179
- description: 'SessionId of a session that has already been created via the web flow.',
180
- }),
81
+ help: flags_1.SHARED_FLAGS.help,
82
+ id: flags_1.SHARED_FLAGS.id,
83
+ sessionId: flags_1.SHARED_FLAGS.sessionId,
84
+ refresh: flags_1.SHARED_FLAGS.refresh,
181
85
  profileName: command_1.flags.string({
182
86
  multiple: false,
183
- description: "Uses a custom AWS profile name for the IAM role. Default value is the role's name.",
87
+ description: 'Uses a custom AWS profile name for the IAM role. Default value is the role\'s name.',
184
88
  }),
185
89
  };
@@ -1,12 +1,13 @@
1
- import { Command, flags } from '@oclif/command';
1
+ import { Command } from '@oclif/command';
2
2
  export default class StartKubeIAMRoleSession extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
7
- id: flags.IOptionFlag<string | undefined>;
8
- accessLevelRemoteId: flags.IOptionFlag<string | undefined>;
9
- sessionId: flags.IOptionFlag<string | undefined>;
7
+ id: import("@oclif/command/lib/flags").IOptionFlag<string | undefined>;
8
+ accessLevelRemoteId: import("@oclif/command/lib/flags").IOptionFlag<string | undefined>;
9
+ sessionId: import("@oclif/command/lib/flags").IOptionFlag<string | undefined>;
10
+ refresh: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
10
11
  };
11
12
  run(): Promise<void>;
12
13
  }