@cloud-copilot/iam-expand 0.1.6 → 0.1.8

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 CHANGED
@@ -1,255 +1,172 @@
1
1
  # Expand IAM Actions
2
- This will expand the actions of the IAM policy to show the individual actions. Useful for when you want to see the individual actions that are included in a wildcard action or are not allowed to use wildcards for security or compliance reasons.
3
-
4
- Published in ESM and CommonJS and available as a [CLI](#cli).
2
+ Built in the Unix philosophy, this is a small tool that does one thing well: expand IAM actions with wildcards to their list of matching actions.
5
3
 
6
4
  Use this to:
7
- 1) Expand out wildcards in actions when you are not allowed to use wildcards in your IAM policy.
8
- 2) Get an exhaustive list of actions that are included in a policy and quickly search it for interesting actions.
9
- 3) Investigate where dangerous or dubious actions are being used in your policies.
5
+ 1) Expand wildcards when you are not allowed to use them in your policies.
6
+ 2) Get an exhaustive list of actions that are included in a policy to quickly search it for interesting actions.
7
+ 3) Investigate where interesting or dubious actions are being used in your policies.
8
+
9
+ Published as an [npm package](#typescriptnodejs-usage) in ESM and CommonJS plus available as a [CLI](#cli).
10
+
11
+ All information is sourced from [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data) which is updated daily.
12
+
13
+ ## Only Valid Values
14
+ `iam-expand` intends to only return valid, actual actions, if any invalid values are passed in such as an invalid format or a service/action that does not exist, they will be left out of the output. There are options to override this behavior.
10
15
 
11
- ## Installation
16
+ ## CLI
17
+ There is a CLI! The [examples folder](examples/README.md) has examples showing how to use the CLI to find interesting actions in your IAM policies.
18
+
19
+ ### Global CLI Installation
20
+ You can install it globally. This also works in the default AWS CloudShell!
12
21
  ```bash
13
22
  npm install -g @cloud-copilot/iam-expand
14
23
  ```
24
+ *Depending on your configuration sudo may be required to install globally.*
15
25
 
16
- ### AWS CloudShell Installation
17
- The AWS CloudShell automatically has node and npm installed, so you can install this and run it straight from the console. You'll need to use sudo to install it globally.
18
-
26
+ ### Install CLI In a Project
27
+ You can also install the CLI in a project and run it with `npx`.
19
28
  ```bash
20
- sudo npm install -g @cloud-copilot/iam-expand
29
+ npm install @cloud-copilot/iam-expand
30
+ # Run with npx inside your project
31
+ npx @cloud-copilot/iam-expand
21
32
  ```
22
33
 
23
- ## Typescript/NodeJS Usage
24
- ```typescript
25
- import { expandIamActions } from '@cloud-copilot/iam-expand';
26
-
27
- expandIamActions('s3:Get*Tagging')
28
- [
29
- 's3:GetBucketTagging',
30
- 's3:GetJobTagging',
31
- 's3:GetObjectTagging',
32
- 's3:GetObjectVersionTagging',
33
- 's3:GetStorageLensConfigurationTagging'
34
- ]
35
-
36
- expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
37
- [
38
- 's3:GetBucketTagging',
39
- 's3:GetJobTagging',
40
- 's3:GetObjectTagging',
41
- 's3:GetObjectVersionTagging',
42
- 's3:GetStorageLensConfigurationTagging',
43
- 's3:PutBucketTagging',
44
- 's3:PutJobTagging',
45
- 's3:PutObjectTagging',
46
- 's3:PutObjectVersionTagging',
47
- 's3:PutStorageLensConfigurationTagging'
48
- ]
34
+ ### Expand Actions
35
+ The simplest usage is to pass in the actions you want to expand.
36
+ ```bash
37
+ iam-expand s3:Get*Tagging
38
+ # Outputs all Get*Tagging actions
39
+ s3:GetBucketTagging
40
+ s3:GetJobTagging
41
+ s3:GetObjectTagging
42
+ s3:GetObjectVersionTagging
43
+ s3:GetStorageLensConfigurationTaggin
49
44
  ```
50
45
 
51
- ## API
52
- `expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>)` is the main function that will expand the actions of the IAM policy. Takes a string or array of strings and returns an array of strings that the input matches.
53
-
54
- ## Only Valid Values
55
- `expandIamActions` intends to only return valid actual actions, if any invalid values are passed in such as an invalid format or a service/action that does not exist, they will be left out of the output. There are options to override this behavior.
56
-
57
- ## Options
58
- `expandIamActions` an optional second argument that is an object with the following options:
59
-
60
- ### `expandAsterisk`
61
- By default, a single `*` not be expanded. We assume that if you want a list of all IAM actions there are other sources you will check, such as [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data). If you want to expand a single `*` you can set this option to `true`.
62
-
63
- ```typescript
64
- import { expandIamActions } from '@cloud-copilot/iam-expand';
65
-
66
- //Returns the unexpanded value
67
- expandIamActions('*')
68
- ['*']
69
-
70
- //Returns the expanded value
71
- expandIamActions('*', { expandAsterisk: true })
72
- [
73
- //Many many strings. 🫢
74
- ]
46
+ ```bash
47
+ iam-expand s3:Get*Tagging s3:Put*Tagging
48
+ # Outputs the combination of Get*Tagging and Put*Tagging actions deduplicated and sorted
49
+ s3:GetBucketTagging
50
+ s3:GetJobTagging
51
+ s3:GetObjectTagging
52
+ s3:GetObjectVersionTagging
53
+ s3:GetStorageLensConfigurationTagging
54
+ s3:PutBucketTagging
55
+ s3:PutJobTagging
56
+ s3:PutObjectTagging
57
+ s3:PutObjectVersionTagging
58
+ s3:PutStorageLensConfigurationTaggin
75
59
  ```
76
- ### `expandServiceAsterisk`
77
- By default, a service name followed by a `*` (such as `s3:*` or `lambda:*`) will not be expanded. If you want to expand these you can set this option to `true`.
78
60
 
79
- ```typescript
80
- import { expandIamActions } from '@cloud-copilot/iam-expand';
81
-
82
- //Returns the unexpanded value
83
- expandIamActions('s3:*')
84
- ['s3:*']
85
-
86
- //Returns the expanded value
87
- expandIamActions('s3:*', { expandServiceAsterisk: true })
88
- [
89
- //All the s3 actions. 🫢
90
- ]
61
+ ### Help
62
+ Run the command with no options to show usage:
63
+ ```bash
64
+ iam-expand
91
65
  ```
92
66
 
93
- ### `distinct`
94
- If you include multiple patterns that have overlapping matching actions, the same action will be included multiple times in the output. If you want to remove duplicates you can set this option to `true`.
95
-
96
- ```typescript
97
- import { expandIamActions } from '@cloud-copilot/iam-expand';
67
+ ### Options
98
68
 
99
- //Returns duplication values (s3:GetObjectTagging)
100
- expandIamActions(['s3:GetObject*','s3:Get*Tagging'])
101
- [
102
- 's3:GetObject',
103
- 's3:GetObjectAcl',
104
- 's3:GetObjectAttributes',
105
- 's3:GetObjectLegalHold',
106
- 's3:GetObjectRetention',
107
- 's3:GetObjectTagging',
108
- ...
109
- 's3:GetObjectTagging',
110
- 's3:GetObjectVersionTagging',
111
- 's3:GetStorageLensConfigurationTagging'
112
- ]
69
+ #### `--expand-asterisk`
70
+ By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this flag.
71
+ ```bash
72
+ iam-expand "*"
73
+ # Returns the asterisk
74
+ *
113
75
 
114
- //Duplicates removed and order maintained
115
- expandIamActions(['s3:GetObject*','s3:Get*Tagging'],{distinct:true})
116
- [
117
- 's3:GetObject',
118
- 's3:GetObjectAcl',
119
- 's3:GetObjectAttributes',
120
- 's3:GetObjectLegalHold',
121
- 's3:GetObjectRetention',
122
- 's3:GetObjectTagging',
123
- 's3:GetObjectTorrent',
124
- 's3:GetObjectVersion',
125
- 's3:GetObjectVersionAcl',
126
- 's3:GetObjectVersionAttributes',
127
- 's3:GetObjectVersionForReplication',
128
- 's3:GetObjectVersionTagging',
129
- 's3:GetObjectVersionTorrent',
130
- 's3:GetBucketTagging',
131
- 's3:GetJobTagging',
132
- 's3:GetStorageLensConfigurationTagging'
133
- ]
76
+ iam-expand --expand-asterisk "*"
77
+ # Returns very many strings, very very fast. 📚 🚀
134
78
  ```
135
79
 
136
- ### `sort`
137
- By default, the output will be sorted based on the order of the input. If you want the output to be sorted alphabetically you can set this option to `true`.
138
-
139
- ```typescript
140
- import { expandIamActions } from '@cloud-copilot/iam-expand';
141
-
142
- //By default the output is sorted based on the order of the input
143
- expandIamActions(['s3:Get*Tagging','ec2:*Tags'])
144
- [
145
- 's3:GetBucketTagging',
146
- 's3:GetJobTagging',
147
- 's3:GetObjectTagging',
148
- 's3:GetObjectVersionTagging',
149
- 's3:GetStorageLensConfigurationTagging',
150
- 'ec2:CreateTags',
151
- 'ec2:DeleteTags',
152
- 'ec2:DescribeTags'
153
- ]
154
-
155
- //Output is sorted alphabetically
156
- expandIamActions(['s3:Get*Tagging','ec2:*Tags'], {sort: true})
157
- [
158
- 'ec2:CreateTags',
159
- 'ec2:DeleteTags',
160
- 'ec2:DescribeTags',
161
- 's3:GetBucketTagging',
162
- 's3:GetJobTagging',
163
- 's3:GetObjectTagging',
164
- 's3:GetObjectVersionTagging',
165
- 's3:GetStorageLensConfigurationTagging'
166
- ]
167
-
80
+ #### `--expand-service-asterisk`
81
+ By default, a service name followed by a `*` (such as `s3:*` or `lambda:*`) will not be expanded. If you want to expand these you can set this flag.
82
+ ```bash
83
+ iam-expand "s3:*"
84
+ # Returns the service:* action
85
+ s3:*
86
+
87
+ iam-expand --expand-service-asterisk "s3:*"
88
+ # Returns all the s3 actions in order. 🪣
89
+ s3:AbortMultipartUpload
90
+ s3:AssociateAccessGrantsIdentityCenter
91
+ s3:BypassGovernanceRetention
92
+ ...
168
93
  ```
169
94
 
170
- ### `errorOnInvalidFormat`
95
+ #### `--error-on-invalid-format`
171
96
  By default, if an invalid format is passed in, such as:
172
97
  * `s3Get*Tagging` (missing a separator) or
173
98
  * `s3:Get:Tagging*` (too many separators)
174
99
 
175
- it will be silenty ignored and left out of the output. If you want to throw an error when an invalid format is passed in you can set this option to `true`.
176
-
177
- ```typescript
178
- import { expandIamActions } from '@cloud-copilot/iam-expand';
100
+ it will be silenty ignored and left out of the output. If you want to throw an error when an invalid format is passed in you can set this flag.
179
101
 
180
- //Ignore invalid format
181
- expandIamActions('s3Get*Tagging')
182
- []
102
+ ```bash
103
+ iam-expand "s3Get*Tagging"
104
+ # Returns nothing
183
105
 
184
- //Throw an error on invalid format
185
- expandIamActions('s3Get*Tagging', { errorOnInvalidFormat: true })
186
- //Uncaught Error: Invalid action format: s3Get*Tagging
106
+ iam-expand --error-on-invalid-format "s3Get*Tagging"
107
+ # Throws an error and returns a non zero exit code
108
+ # Error: Invalid action format: s3Get*Tagging
187
109
  ```
188
110
 
189
- ### `errorOnMissingService`
190
- By default, if a service is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. If you want to throw an error when a service is passed in that does not exist you can set this option to `true`.
191
-
192
- ```typescript
193
- import { expandIamActions } from '@cloud-copilot/iam-expand';
111
+ #### `--error-on-invalid-service`
112
+ By default, if a service is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. If you want to throw an error when a service is passed in that does not exist you can set this flag.
194
113
 
195
- //Ignore missing service
196
- expandIamActions('r2:Get*Tagging')
197
- []
114
+ ```bash
115
+ iam-expand "r2:Get*Tagging"
116
+ # Returns nothing
198
117
 
199
- //Throw an error on missing service
200
- expandIamActions('r2:Get*Tagging', { errorOnMissingService: true })
201
- //Uncaught Error: Service not found: r2
118
+ iam-expand --error-on-invalid-service "r2:Get*Tagging"
119
+ # Throws an error and returns a non zero exit code
120
+ # Error: Service not found: r2
202
121
  ```
203
122
 
204
- ## CLI
205
- There is a CLI!
123
+ #### `--invalid-action-behavior`
124
+ By default, if an action is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. There are two options to override this behavior: `error` and `include`.
206
125
 
207
- ### Install Globally
208
126
  ```bash
209
- npm install -g @cloud-copilot/iam-expand
210
- ```
211
- yarn (yarn does not automatically add peer dependencies, so need to add the data package explicitly)
212
- ```
213
- yarn global add @cloud-copilot/iam-data
214
- yarn global add @cloud-copilot/iam-expand
215
- ```
127
+ iam-expand "ec2:DestroyAvailabilityZone"
128
+ # Returns nothing
216
129
 
217
- ### AWS CloudShell Installation
218
- The AWS CloudShell automatically has node and npm installed, so you can install this and run it straight from the console. You'll need to use sudo to install it globally.
130
+ iam-expand --invalid-action-behavior=remove "ec2:DestroyAvailabilityZone"
131
+ # Returns nothing
219
132
 
220
- ```bash
221
- sudo npm install -g @cloud-copilot/iam-expand
222
- ```
133
+ iam-expand --invalid-action-behavior=error "ec2:DestroyAvailabilityZone"
134
+ # Throws an error and returns a non zero exit code
135
+ # Error: Invalid action: ec2:DestroyAvailabilityZone
223
136
 
224
- ### Run the script in a project that has the package installed
225
- ```bash
226
- npx @cloud-copilot/iam-expand
137
+ iam-expand --invalid-action-behavior=include "ec2:DestroyAvailabilityZone"
138
+ # Returns the invalid action
139
+ ec2:DestroyAvailabilityZone
227
140
  ```
228
141
 
229
- ### Simple Usage
230
- The simplest usage is to pass in the actions you want to expand.
142
+ #### `--show-data-version`
143
+ Show the version of the data that is being used to expand the actions and exit.
144
+
231
145
  ```bash
232
- iam-expand s3:Get* s3:*Tag*
146
+ iam-expand --show-data-version
147
+ @cloud-copilot/iam-data version: 0.3.202409051
148
+ Data last updated: Thu Sep 05 2024 04:46:39 GMT+0000 (Coordinated Universal Time)
149
+ Update with either:
150
+ npm update @cloud-copilot/iam-data
151
+ npm update -g @cloud-copilot/iam-data
233
152
  ```
234
153
 
235
- You can pass in all options available through the api as dash separated flags.
154
+ #### `--read-wait-time`
155
+ When reading from stdin (see [below](#read-from-stdin)) the CLI will wait 10 seconds for the first byte to be read before timing out. This is enough time for most operations. If you want to wait longer you can set this flag to the number of milliseconds you want to wait.
236
156
 
237
- _Prints all matching actions for s3:Get*Tagging, s3:*Tag*, and ec2:* in alphabetical order with duplicates removed:_
238
157
  ```bash
239
- iam-expand s3:Get*Tagging s3:*Tag* ec2:* --expand-service-asterisk --distinct --sort
240
- ```
158
+ cat policy.json | iam-expand
159
+ # Will wait for 10 seconds for input, which is plenty of time for a local file.
241
160
 
242
- ### Help
243
- Running the command with no options shows usage help;
244
- ```bash
245
- iam-expand
161
+ curl "https://governmentsecrets.s3.amazonaws.com/bigfile.json" | iam-expand --read-wait-time=20_000
162
+ # Will wait for 20 seconds for the first byte from curl before timing out. Adjust as needed
246
163
  ```
247
164
 
248
165
  ### Read from stdin
249
166
  If no actions are passed as arguments, the CLI will read from stdin.
250
167
 
251
168
  #### Expanding JSON input
252
- If the input is a valid json document, the CLI will find every instance of `Action` and 'NotAcion' that is a string or an array of strings and expand them. This is useful for finding all the actions in a policy document or set of documents.
169
+ If the input is a valid json document, the CLI will find every instance of `Action` and `NotAction` that is a string or an array of strings and expand them. This is useful for finding all the actions in a policy document or set of documents.
253
170
 
254
171
  Given `policy.json`
255
172
  ```json
@@ -315,16 +232,15 @@ Gives this file in `expanded-policy.json`
315
232
 
316
233
  You can also use this to expand the actions from the output of commands.
317
234
  ```bash
318
- aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-inline-policies.json
235
+ aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-authorization-details.json
319
236
  # Now you can search the output for actions you are interested in
320
237
  grep -n "kms:DisableKey" expanded-inline-policies.json
321
238
  ```
322
- _--expand-service-asterisk makes sure kms:* is expaneded out so you can find the DisableKey action. --read-wait-time=20_000 gives the cli command more time to return it's first byte of output_
323
239
 
324
240
  #### Expanding arbitrary input
325
- If the input from stdin is not json, the content is searched for actions that are then expanded. This is really meant to be abused. It essentialy greps the content for anything resembling and action and expands it. Throw anything at it and it will find all the actions it can and expand them.
241
+ If the input from stdin is not json, the content is searched for IAM actions then expands them. Throw anything at it and it will find all the actions it can and expand them.
326
242
 
327
- You can echo some content:
243
+ You can echo content:
328
244
  ```bash
329
245
  echo "s3:Get*Tagging" | iam-expand
330
246
  ```
@@ -346,7 +262,7 @@ cat template.yaml | iam-expand
346
262
 
347
263
  Or even some HTML:
348
264
  ```bash
349
- curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/SecurityAudit.html" | iam-expand
265
+ curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/ReadOnlyAccess.html" | iam-expand
350
266
  ```
351
267
 
352
268
  Or the output of any command.
@@ -354,3 +270,138 @@ Or the output of any command.
354
270
  Because of the likelyhood of finding an aseterik `*` in the input; if the value to stdin is not a valid json document the stdin option will not find or expand a single `*` even if `--expand-asterisk` is passed.
355
271
 
356
272
  Please give this anything you can think of and open an issue if you see an opportunity for improvement.
273
+
274
+ ## Typescript/NodeJS Usage
275
+
276
+ ## Add to a project
277
+ ```bash
278
+ npm install @cloud-copilot/iam-expand
279
+ ```
280
+
281
+ ```typescript
282
+ import { expandIamActions } from '@cloud-copilot/iam-expand';
283
+
284
+ expandIamActions('s3:Get*Tagging')
285
+ [
286
+ 's3:GetBucketTagging',
287
+ 's3:GetJobTagging',
288
+ 's3:GetObjectTagging',
289
+ 's3:GetObjectVersionTagging',
290
+ 's3:GetStorageLensConfigurationTagging'
291
+ ]
292
+
293
+ expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
294
+ [
295
+ 's3:GetBucketTagging',
296
+ 's3:GetJobTagging',
297
+ 's3:GetObjectTagging',
298
+ 's3:GetObjectVersionTagging',
299
+ 's3:GetStorageLensConfigurationTagging',
300
+ 's3:PutBucketTagging',
301
+ 's3:PutJobTagging',
302
+ 's3:PutObjectTagging',
303
+ 's3:PutObjectVersionTagging',
304
+ 's3:PutStorageLensConfigurationTagging'
305
+ ]
306
+ ```
307
+
308
+ ## API
309
+ `expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>)` is the main function that will expand the actions of the IAM policy. Takes a string or array of strings and returns an array of strings that the input matches.
310
+
311
+ ## Only Valid Values
312
+ `expandIamActions` intends to only return valid actual actions, if any invalid values are passed in such as an invalid format or a service/action that does not exist, they will be left out of the output. There are options to override this behavior.
313
+
314
+ ## Options
315
+ `expandIamActions` an optional second argument that is an object with the following options:
316
+
317
+ ### `expandAsterisk`
318
+ By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this option to `true`.
319
+
320
+ ```typescript
321
+ import { expandIamActions } from '@cloud-copilot/iam-expand';
322
+
323
+ //Returns the unexpanded value
324
+ expandIamActions('*')
325
+ ['*']
326
+
327
+ //Returns the expanded value
328
+ expandIamActions('*', { expandAsterisk: true })
329
+ [
330
+ //Many many strings. 🫢
331
+ ]
332
+ ```
333
+ ### `expandServiceAsterisk`
334
+ By default, a service name followed by a `*` (such as `s3:*` or `lambda:*`) will not be expanded. If you want to expand these you can set this option to `true`.
335
+
336
+ ```typescript
337
+ import { expandIamActions } from '@cloud-copilot/iam-expand';
338
+
339
+ //Returns the unexpanded value
340
+ expandIamActions('s3:*')
341
+ ['s3:*']
342
+
343
+ //Returns the expanded value
344
+ expandIamActions('s3:*', { expandServiceAsterisk: true })
345
+ [
346
+ //All the s3 actions. 🫢
347
+ ]
348
+ ```
349
+
350
+ ### `errorOnInvalidFormat`
351
+ By default, if an invalid format is passed in, such as:
352
+ * `s3Get*Tagging` (missing a separator) or
353
+ * `s3:Get:Tagging*` (too many separators)
354
+
355
+ it will be silenty ignored and left out of the output. If you want to throw an error when an invalid format is passed in you can set this option to `true`.
356
+
357
+ ```typescript
358
+ import { expandIamActions } from '@cloud-copilot/iam-expand';
359
+
360
+ //Ignore invalid format
361
+ expandIamActions('s3Get*Tagging')
362
+ []
363
+
364
+ //Throw an error on invalid format
365
+ expandIamActions('s3Get*Tagging', { errorOnInvalidFormat: true })
366
+ //Uncaught Error: Invalid action format: s3Get*Tagging
367
+ ```
368
+
369
+ ### `errorOnInvalidService`
370
+ By default, if a service is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. If you want to throw an error when a service is passed in that does not exist you can set this option to `true`.
371
+
372
+ ```typescript
373
+ import { expandIamActions } from '@cloud-copilot/iam-expand';
374
+
375
+ //Ignore invalid service
376
+ expandIamActions('r2:Get*Tagging')
377
+ []
378
+
379
+ //Throw an error on invalid service
380
+ expandIamActions('r2:Get*Tagging', { errorOnInvalidService: true })
381
+ //Uncaught Error: Service not found: r2
382
+ ```
383
+
384
+ ## `invalidActionBehavior`
385
+ By default, if an action is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. There are two options to override this behavior: `Error` and `Include`.
386
+
387
+ ```typescript
388
+ import { expandIamActions, InvalidActionBehavior } from '@cloud-copilot/iam-expand';
389
+
390
+ //Ignore invalid action by default
391
+ expandIamActions('ec2:DestroyAvailabilityZone')
392
+ []
393
+
394
+ //Ignore invalid action explicitly
395
+ expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Remove })
396
+ []
397
+
398
+ //Throw an error on invalid action
399
+ expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Error })
400
+ //Uncaught Error: Invalid action: ec2:DestroyAvailabilityZone
401
+
402
+ //Include invalid action
403
+ expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Include })
404
+ ['ec2:DestroyAvailabilityZone']
405
+ ```
406
+
407
+
package/dist/cjs/cli.js CHANGED
@@ -5,6 +5,7 @@ const iam_data_1 = require("@cloud-copilot/iam-data");
5
5
  const cli_utils_js_1 = require("./cli_utils.js");
6
6
  const expand_js_1 = require("./expand.js");
7
7
  const commandName = 'iam-expand';
8
+ const dataPackage = '@cloud-copilot/iam-data';
8
9
  async function expandAndPrint(actionStrings, options) {
9
10
  try {
10
11
  const result = await (0, expand_js_1.expandIamActions)(actionStrings, options);
@@ -23,19 +24,17 @@ function printUsage() {
23
24
  console.log(` ${commandName} [options] [action1] [action2] ...`);
24
25
  console.log(` <input from stdout> | ${commandName} [options]`);
25
26
  console.log('Action Expanding Options:');
26
- console.log(' --distinct: Remove duplicate actions');
27
- console.log(' --sort: Sort the actions');
28
27
  console.log(' --expand-asterisk: Expand the * action to all actions');
29
28
  console.log(' --expand-service-asterisk: Expand service:* to all actions for that service');
30
- console.log(' --error-on-missing-service: Throw an error if a service is not found');
31
29
  console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format');
30
+ console.log(' --error-on-invalid-service: Throw an error if a service is not found');
32
31
  console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:');
33
32
  console.log(' --invalid-action-behavior=remove: Remove the invalid action');
34
33
  console.log(' --invalid-action-behavior=include: Include the invalid action');
35
34
  console.log(' --invalid-action-behavior=error: Throw an error if an invalid action is encountered');
36
35
  console.log('CLI Behavior Options:');
37
36
  console.log(' --show-data-version: Print the version of the iam-data package being used and exit');
38
- console.log(' --read-wait-time: Millisenconds to wait for input from stdin before timing out.');
37
+ console.log(' --read-wait-time: Millisenconds to wait for the first byte from stdin before timing out.');
39
38
  console.log(' Example: --read-wait-time=10_000');
40
39
  process.exit(1);
41
40
  }
@@ -54,9 +53,11 @@ async function run() {
54
53
  const options = (0, cli_utils_js_1.convertOptions)(optionStrings);
55
54
  if (options.showDataVersion) {
56
55
  const version = await (0, iam_data_1.iamDataVersion)();
57
- const updatedAt = await (0, iam_data_1.iamDataUpdatedAt)();
58
- console.log(`@cloud-copilot/iam-data version: ${version}`);
59
- console.log(`Data last updated: ${updatedAt}`);
56
+ const updatedAt = console.log(`${dataPackage} version: ${version}`);
57
+ console.log(`Data last updated: ${await (0, iam_data_1.iamDataUpdatedAt)()}`);
58
+ console.log(`Update with either:`);
59
+ console.log(` npm update ${dataPackage}`);
60
+ console.log(` npm update -g ${dataPackage}`);
60
61
  return;
61
62
  }
62
63
  if (actionStrings.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;AAEA,sDAA2E;AAC3E,iDAA4D;AAC5D,2CAAwE;AAExE,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,KAAK,UAAU,cAAc,CAAC,aAAuB,EAAE,OAAyC;IAC9F,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAA,4BAAgB,EAAC,aAAa,EAAE,OAAO,CAAC,CAAA;QAC7D,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC;AAED,SAAS,UAAU;IACjB,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAA;IACzD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACrB,OAAO,CAAC,GAAG,CAAC,KAAK,WA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AACd,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IAChB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA"}
@@ -31,13 +31,7 @@ export interface ExpandIamActionsOptions {
31
31
  * If false, an empty array will be returned
32
32
  * Default: false
33
33
  */
34
- errorOnMissingService: boolean;
35
- /**
36
- * If true, only unique values will be returned, while maintaining order
37
- * If false, all values will be returned, even if they are duplicates
38
- * Default: false
39
- */
40
- distinct: boolean;
34
+ errorOnInvalidService: boolean;
41
35
  /**
42
36
  * The behavior to use when an invalid action is encountered without wildcards
43
37
  * @{InvalidActionBehavior.Remove} will remove the invalid action from the output
@@ -47,12 +41,6 @@ export interface ExpandIamActionsOptions {
47
41
  * Default: InvalidActionBehavior.Remove
48
42
  */
49
43
  invalidActionBehavior: InvalidActionBehavior;
50
- /**
51
- * If true, the returned array will be sorted
52
- * If false, the returned array will be in the order they were expanded
53
- * Default: false
54
- */
55
- sort: boolean;
56
44
  }
57
45
  /**
58
46
  * Expands an IAM action string that contains wildcards.
@@ -1 +1 @@
1
- {"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../../src/expand.ts"],"names":[],"mappings":"AAEA,oBAAY,qBAAqB;IAC/B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAA;IAEvB;;;;OAIG;IACH,qBAAqB,EAAE,OAAO,CAAA;IAE9B;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,qB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