@cloud-copilot/iam-expand 0.1.7 → 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
@@ -2,273 +2,164 @@
2
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.
3
3
 
4
4
  Use this to:
5
- 1) Expand out wildcards in actions when you are not allowed to use wildcards in your IAM policy.
6
- 2) Get an exhaustive list of actions that are included in a policy and quickly search it for interesting actions.
7
- 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
8
 
9
- Published in ESM and CommonJS plus available as a [CLI](#cli).
9
+ Published as an [npm package](#typescriptnodejs-usage) in ESM and CommonJS plus available as a [CLI](#cli).
10
10
 
11
- All information is sourced from the [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data) which is updated daily.
11
+ All information is sourced from [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data) which is updated daily.
12
12
 
13
- ## Installation
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.
15
+
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!
14
21
  ```bash
15
22
  npm install -g @cloud-copilot/iam-expand
16
23
  ```
24
+ *Depending on your configuration sudo may be required to install globally.*
17
25
 
18
- ### AWS CloudShell Installation
19
- 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.
26
+ ### Install CLI In a Project
27
+ You can also install the CLI in a project and run it with `npx`.
20
28
  ```bash
21
- sudo npm install -g @cloud-copilot/iam-expand
22
- iam-expand
29
+ npm install @cloud-copilot/iam-expand
30
+ # Run with npx inside your project
31
+ npx @cloud-copilot/iam-expand
23
32
  ```
24
33
 
25
- ## Typescript/NodeJS Usage
26
- ```typescript
27
- import { expandIamActions } from '@cloud-copilot/iam-expand';
28
-
29
- expandIamActions('s3:Get*Tagging')
30
- [
31
- 's3:GetBucketTagging',
32
- 's3:GetJobTagging',
33
- 's3:GetObjectTagging',
34
- 's3:GetObjectVersionTagging',
35
- 's3:GetStorageLensConfigurationTagging'
36
- ]
37
-
38
- expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
39
- [
40
- 's3:GetBucketTagging',
41
- 's3:GetJobTagging',
42
- 's3:GetObjectTagging',
43
- 's3:GetObjectVersionTagging',
44
- 's3:GetStorageLensConfigurationTagging',
45
- 's3:PutBucketTagging',
46
- 's3:PutJobTagging',
47
- 's3:PutObjectTagging',
48
- 's3:PutObjectVersionTagging',
49
- 's3:PutStorageLensConfigurationTagging'
50
- ]
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
51
44
  ```
52
45
 
53
- ## API
54
- `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.
55
-
56
- ## Only Valid Values
57
- `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.
58
-
59
- ## Options
60
- `expandIamActions` an optional second argument that is an object with the following options:
61
-
62
- ### `expandAsterisk`
63
- By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this option to `true`.
64
-
65
- ```typescript
66
- import { expandIamActions } from '@cloud-copilot/iam-expand';
67
-
68
- //Returns the unexpanded value
69
- expandIamActions('*')
70
- ['*']
71
-
72
- //Returns the expanded value
73
- expandIamActions('*', { expandAsterisk: true })
74
- [
75
- //Many many strings. 🫢
76
- ]
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
77
59
  ```
78
- ### `expandServiceAsterisk`
79
- 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`.
80
-
81
- ```typescript
82
- import { expandIamActions } from '@cloud-copilot/iam-expand';
83
60
 
84
- //Returns the unexpanded value
85
- expandIamActions('s3:*')
86
- ['s3:*']
87
-
88
- //Returns the expanded value
89
- expandIamActions('s3:*', { expandServiceAsterisk: true })
90
- [
91
- //All the s3 actions. 🫢
92
- ]
61
+ ### Help
62
+ Run the command with no options to show usage:
63
+ ```bash
64
+ iam-expand
93
65
  ```
94
66
 
95
- ### `distinct`
96
- 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`.
67
+ ### Options
97
68
 
98
- ```typescript
99
- import { expandIamActions } from '@cloud-copilot/iam-expand';
100
-
101
- //Returns duplication values (s3:GetObjectTagging)
102
- expandIamActions(['s3:GetObject*','s3:Get*Tagging'])
103
- [
104
- 's3:GetObject',
105
- 's3:GetObjectAcl',
106
- 's3:GetObjectAttributes',
107
- 's3:GetObjectLegalHold',
108
- 's3:GetObjectRetention',
109
- 's3:GetObjectTagging',
110
- ...
111
- 's3:GetObjectTagging',
112
- 's3:GetObjectVersionTagging',
113
- 's3:GetStorageLensConfigurationTagging'
114
- ]
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
+ *
115
75
 
116
- //Duplicates removed and order maintained
117
- expandIamActions(['s3:GetObject*','s3:Get*Tagging'],{distinct:true})
118
- [
119
- 's3:GetObject',
120
- 's3:GetObjectAcl',
121
- 's3:GetObjectAttributes',
122
- 's3:GetObjectLegalHold',
123
- 's3:GetObjectRetention',
124
- 's3:GetObjectTagging',
125
- 's3:GetObjectTorrent',
126
- 's3:GetObjectVersion',
127
- 's3:GetObjectVersionAcl',
128
- 's3:GetObjectVersionAttributes',
129
- 's3:GetObjectVersionForReplication',
130
- 's3:GetObjectVersionTagging',
131
- 's3:GetObjectVersionTorrent',
132
- 's3:GetBucketTagging',
133
- 's3:GetJobTagging',
134
- 's3:GetStorageLensConfigurationTagging'
135
- ]
76
+ iam-expand --expand-asterisk "*"
77
+ # Returns very many strings, very very fast. 📚 🚀
136
78
  ```
137
79
 
138
- ### `sort`
139
- By default, the output will be sorted based on the order of the input. If you want the consolidated output to be sorted alphabetically you can set this option to `true`.
140
-
141
- ```typescript
142
- import { expandIamActions } from '@cloud-copilot/iam-expand';
143
-
144
- //By default the output is sorted based on the order of the input
145
- expandIamActions(['s3:Get*Tagging','ec2:*Tags'])
146
- [
147
- 's3:GetBucketTagging',
148
- 's3:GetJobTagging',
149
- 's3:GetObjectTagging',
150
- 's3:GetObjectVersionTagging',
151
- 's3:GetStorageLensConfigurationTagging',
152
- 'ec2:CreateTags',
153
- 'ec2:DeleteTags',
154
- 'ec2:DescribeTags'
155
- ]
156
-
157
- //Output is sorted alphabetically
158
- expandIamActions(['s3:Get*Tagging','ec2:*Tags'], {sort: true})
159
- [
160
- 'ec2:CreateTags',
161
- 'ec2:DeleteTags',
162
- 'ec2:DescribeTags',
163
- 's3:GetBucketTagging',
164
- 's3:GetJobTagging',
165
- 's3:GetObjectTagging',
166
- 's3:GetObjectVersionTagging',
167
- 's3:GetStorageLensConfigurationTagging'
168
- ]
169
-
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
+ ...
170
93
  ```
171
94
 
172
- ### `errorOnInvalidFormat`
95
+ #### `--error-on-invalid-format`
173
96
  By default, if an invalid format is passed in, such as:
174
97
  * `s3Get*Tagging` (missing a separator) or
175
98
  * `s3:Get:Tagging*` (too many separators)
176
99
 
177
- 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`.
178
-
179
- ```typescript
180
- 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.
181
101
 
182
- //Ignore invalid format
183
- expandIamActions('s3Get*Tagging')
184
- []
102
+ ```bash
103
+ iam-expand "s3Get*Tagging"
104
+ # Returns nothing
185
105
 
186
- //Throw an error on invalid format
187
- expandIamActions('s3Get*Tagging', { errorOnInvalidFormat: true })
188
- //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
189
109
  ```
190
110
 
191
- ### `errorOnMissingService`
192
- 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`.
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.
193
113
 
194
- ```typescript
195
- import { expandIamActions } from '@cloud-copilot/iam-expand';
196
-
197
- //Ignore missing service
198
- expandIamActions('r2:Get*Tagging')
199
- []
114
+ ```bash
115
+ iam-expand "r2:Get*Tagging"
116
+ # Returns nothing
200
117
 
201
- //Throw an error on missing service
202
- expandIamActions('r2:Get*Tagging', { errorOnMissingService: true })
203
- //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
204
121
  ```
205
122
 
206
- ## `invalidActionBehavior`
207
- 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`.
208
-
209
- ```typescript
210
- import { expandIamActions, InvalidActionBehavior } from '@cloud-copilot/iam-expand';
211
-
212
- //Ignore invalid action by default
213
- expandIamActions('ec2:DestroyAvailabilityZone')
214
- []
215
-
216
- //Ignore invalid action explicitly
217
- expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Remove })
218
- []
219
-
220
- //Throw an error on invalid action
221
- expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Error })
222
- //Uncaught Error: Invalid action: ec2:DestroyAvailabilityZone
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`.
223
125
 
224
- //Include invalid action
225
- expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Include })
226
- ['ec2:DestroyAvailabilityZone']
227
- ```
126
+ ```bash
127
+ iam-expand "ec2:DestroyAvailabilityZone"
128
+ # Returns nothing
228
129
 
229
- ## CLI
230
- 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.
130
+ iam-expand --invalid-action-behavior=remove "ec2:DestroyAvailabilityZone"
131
+ # Returns nothing
231
132
 
232
- ### Installation
233
- You can install it globally and use the command `iam-expand` or add it to a single project and use `npx`.
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
234
136
 
235
- #### Install Globally
236
- ```bash
237
- npm install -g @cloud-copilot/iam-expand
238
- ```
239
- yarn (yarn does not automatically add peer dependencies, so need to add the data package explicitly)
137
+ iam-expand --invalid-action-behavior=include "ec2:DestroyAvailabilityZone"
138
+ # Returns the invalid action
139
+ ec2:DestroyAvailabilityZone
240
140
  ```
241
- yarn global add @cloud-copilot/iam-data
242
- yarn global add @cloud-copilot/iam-expand
243
- ```
244
-
245
- 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.
246
141
 
247
- ```bash
248
- sudo npm install -g @cloud-copilot/iam-expand
249
- ```
250
- #### Install in a project
251
- ```bash
252
- npm install @cloud-copilot/iam-expand
253
- ```
142
+ #### `--show-data-version`
143
+ Show the version of the data that is being used to expand the actions and exit.
254
144
 
255
- ### Simple Usage
256
- The simplest usage is to pass in the actions you want to expand.
257
145
  ```bash
258
- 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
259
152
  ```
260
153
 
261
- 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.
262
156
 
263
- _Prints all matching actions for `s3:Get*Tagging`, `s3:*Tag*`, and `ec2:*` in alphabetical order with duplicates removed:_
264
157
  ```bash
265
- iam-expand s3:Get*Tagging s3:*Tag* ec2:* --expand-service-asterisk --distinct --sort
266
- ```
158
+ cat policy.json | iam-expand
159
+ # Will wait for 10 seconds for input, which is plenty of time for a local file.
267
160
 
268
- ### Help
269
- Run the command with no options to show usage:
270
- ```bash
271
- 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
272
163
  ```
273
164
 
274
165
  ### Read from stdin
@@ -349,7 +240,7 @@ grep -n "kms:DisableKey" expanded-inline-policies.json
349
240
  #### Expanding arbitrary input
350
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.
351
242
 
352
- You can echo some content:
243
+ You can echo content:
353
244
  ```bash
354
245
  echo "s3:Get*Tagging" | iam-expand
355
246
  ```
@@ -379,3 +270,138 @@ Or the output of any command.
379
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.
380
271
 
381
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
@@ -24,12 +24,10 @@ function printUsage() {
24
24
  console.log(` ${commandName} [options] [action1] [action2] ...`);
25
25
  console.log(` <input from stdout> | ${commandName} [options]`);
26
26
  console.log('Action Expanding Options:');
27
- console.log(' --distinct: Remove duplicate actions');
28
- console.log(' --sort: Sort the actions');
29
27
  console.log(' --expand-asterisk: Expand the * action to all actions');
30
28
  console.log(' --expand-service-asterisk: Expand service:* to all actions for that service');
31
- console.log(' --error-on-missing-service: Throw an error if a service is not found');
32
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');
33
31
  console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:');
34
32
  console.log(' --invalid-action-behavior=remove: Remove the invalid action');
35
33
  console.log(' --invalid-action-behavior=include: Include the invalid action');
@@ -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;AAChC,MAAM,WAAW,GAAG,yBAAyB,CAAA;AAE7C,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,WAAW,oCAAoC,CAAC,CAAA;IACjE,OAAO,CAAC,GAAG,CAAC,2BAA2B,WAAW,YAAY,CAAC,CAAA;IAC/D,OAAO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E,OAAO,CAAC,CAAA;QAC5C,OAAM;IACR,CAAC;IAED,UAAU,EAAE,CAAA;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,qBAAqB,EAAE,OAAO,CAAA;IAE9B;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAA;IAGjB;;;;;;;OAOG;IACH,qBAAqB,EAAE,qBAAqB,CAAA;IAE5C;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAA;CACd;AAcD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0GtJ"}
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,qBAAqB,EAAE,OAAO,CAAA;IAE9B;;;;;;;OAOG;IACH,qBAAqB,EAAE,qBAAqB,CAAA;CAC7C;AAYD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4FtJ"}
@@ -13,10 +13,8 @@ const defaultOptions = {
13
13
  expandAsterisk: false,
14
14
  expandServiceAsterisk: false,
15
15
  errorOnInvalidFormat: false,
16
- errorOnMissingService: false,
16
+ errorOnInvalidService: false,
17
17
  invalidActionBehavior: InvalidActionBehavior.Remove,
18
- distinct: false,
19
- sort: false
20
18
  };
21
19
  const allAsterisksPattern = /^\*+$/i;
22
20
  /**
@@ -40,20 +38,8 @@ async function expandIamActions(actionStringOrStrings, overrideOptions) {
40
38
  const actionLists = await Promise.all(actionStringOrStrings.map(async (actionString) => {
41
39
  return expandIamActions(actionString, options);
42
40
  }));
43
- let allMatches = actionLists.flat();
44
- if (options.distinct) {
45
- const aSet = new Set();
46
- allMatches = allMatches.filter((value) => {
47
- if (aSet.has(value)) {
48
- return false;
49
- }
50
- aSet.add(value);
51
- return true;
52
- });
53
- }
54
- if (options.sort) {
55
- allMatches.sort();
56
- }
41
+ const allMatches = Array.from(new Set(actionLists.flat()));
42
+ allMatches.sort();
57
43
  return allMatches;
58
44
  }
59
45
  const actionString = actionStringOrStrings.trim();
@@ -85,7 +71,7 @@ async function expandIamActions(actionStringOrStrings, overrideOptions) {
85
71
  }
86
72
  const [service, wildcardActions] = parts.map(part => part.toLowerCase());
87
73
  if (!await (0, iam_data_1.iamServiceExists)(service)) {
88
- if (options.errorOnMissingService) {
74
+ if (options.errorOnInvalidService) {
89
75
  throw new Error(`Service not found: ${service}`);
90
76
  }
91
77
  return [];
@@ -121,9 +107,7 @@ async function expandIamActions(actionStringOrStrings, overrideOptions) {
121
107
  const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$";
122
108
  const regex = new RegExp(pattern, 'i');
123
109
  const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`);
124
- if (options.sort) {
125
- matchingActions.sort();
126
- }
110
+ matchingActions.sort();
127
111
  return matchingActions;
128
112
  }
129
113
  //# sourceMappingURL=expand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"expand.js","sourceRoot":"","sources":["../../src/expand.ts"],"names":[],"mappings":";;;AA0FA,4CA0GC;AApMD,sDAAmI;AAEnI,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,0CAAiB,CAAA;IACjB,wCAAe,CAAA;IACf,4CAAmB,CAAA;AACrB,CAA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,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACtC,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,CAAA;IAC7G,eAAe,CAAC,IAAI,EAAE,CAAA;IAEtB,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -16,7 +16,7 @@ async function expandJsonDocument(options, document, key) {
16
16
  return await (0, expand_js_1.expandIamActions)(document, options);
17
17
  }
18
18
  if (Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
19
- const value = await (0, expand_js_1.expandIamActions)(document, { ...options, distinct: true });
19
+ const value = await (0, expand_js_1.expandIamActions)(document, { ...options });
20
20
  return value;
21
21
  }
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"expand_file.js","sourceRoot":"","sources":["../../src/expand_file.ts"],"names":[],"mappings":";;AAUA,gDA4BC;AAtCD,2CAAuE;AAEvE;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAyC,EAAE,QAAa,EAAE,GAAY;IAC7G,IAAG,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;QAC3C,IAAG,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,MAAM,IAAA,4BAAgB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,IAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACrF,MAAM,KAAK,GAAI,MAAM,IAAA,4BAAgB,EAAC,QAAQ,EAAE,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAA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Q,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACrF,MAAM,KAAK,GAAI,MAAM,IAAA,4BAAgB,EAAC,QAAQ,EAAE,EAAC,GAAG,OAAO,EAAC,CAAC,CAAA;YAC7D,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,IAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC7C,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAC,CAAA;IACL,CAAC;IAED,IAAG,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAClC,MAAM,SAAS,GAAQ,EAAE,CAAA;QACzB,KAAI,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC3B,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;QAChE,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
package/dist/esm/cli.js CHANGED
@@ -22,12 +22,10 @@ function printUsage() {
22
22
  console.log(` ${commandName} [options] [action1] [action2] ...`);
23
23
  console.log(` <input from stdout> | ${commandName} [options]`);
24
24
  console.log('Action Expanding Options:');
25
- console.log(' --distinct: Remove duplicate actions');
26
- console.log(' --sort: Sort the actions');
27
25
  console.log(' --expand-asterisk: Expand the * action to all actions');
28
26
  console.log(' --expand-service-asterisk: Expand service:* to all actions for that service');
29
- console.log(' --error-on-missing-service: Throw an error if a service is not found');
30
27
  console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format');
28
+ console.log(' --error-on-invalid-service: Throw an error if a service is not found');
31
29
  console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:');
32
30
  console.log(' --invalid-action-behavior=remove: Remove the invalid action');
33
31
  console.log(' --invalid-action-behavior=include: Include the invalid action');
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAA2B,MAAM,aAAa,CAAC;AAExE,MAAM,WAAW,GAAG,YAAY,CAAA;AAChC,MAAM,WAAW,GAAG,yBAAyB,CAAA;AAE7C,KAAK,UAAU,cAAc,CAAC,aAAuB,EAAE,OAAyC;IAC9F,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,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,WAAW,oCAAoC,CAAC,CAAA;IACjE,OAAO,CAAC,GAAG,CAAC,2BAA2B,WAAW,YAAY,CAAC,CAAA;IAC/D,OAAO,CAAC,GAAG,CAAC,2BAA2B,C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E,CAAC;QAC5B,MAAM,cAAc,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;QAC5C,OAAM;IACR,CAAC;IAED,UAAU,EAAE,CAAA;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,qBAAqB,EAAE,OAAO,CAAA;IAE9B;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAA;IAGjB;;;;;;;OAOG;IACH,qBAAqB,EAAE,qBAAqB,CAAA;IAE5C;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAA;CACd;AAcD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0GtJ"}
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,qBAAqB,EAAE,OAAO,CAAA;IAE9B;;;;;;;OAOG;IACH,qBAAqB,EAAE,qBAAqB,CAAA;CAC7C;AAYD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4FtJ"}
@@ -9,10 +9,8 @@ const defaultOptions = {
9
9
  expandAsterisk: false,
10
10
  expandServiceAsterisk: false,
11
11
  errorOnInvalidFormat: false,
12
- errorOnMissingService: false,
12
+ errorOnInvalidService: false,
13
13
  invalidActionBehavior: InvalidActionBehavior.Remove,
14
- distinct: false,
15
- sort: false
16
14
  };
17
15
  const allAsterisksPattern = /^\*+$/i;
18
16
  /**
@@ -36,20 +34,8 @@ export async function expandIamActions(actionStringOrStrings, overrideOptions) {
36
34
  const actionLists = await Promise.all(actionStringOrStrings.map(async (actionString) => {
37
35
  return expandIamActions(actionString, options);
38
36
  }));
39
- let allMatches = actionLists.flat();
40
- if (options.distinct) {
41
- const aSet = new Set();
42
- allMatches = allMatches.filter((value) => {
43
- if (aSet.has(value)) {
44
- return false;
45
- }
46
- aSet.add(value);
47
- return true;
48
- });
49
- }
50
- if (options.sort) {
51
- allMatches.sort();
52
- }
37
+ const allMatches = Array.from(new Set(actionLists.flat()));
38
+ allMatches.sort();
53
39
  return allMatches;
54
40
  }
55
41
  const actionString = actionStringOrStrings.trim();
@@ -81,7 +67,7 @@ export async function expandIamActions(actionStringOrStrings, overrideOptions) {
81
67
  }
82
68
  const [service, wildcardActions] = parts.map(part => part.toLowerCase());
83
69
  if (!await iamServiceExists(service)) {
84
- if (options.errorOnMissingService) {
70
+ if (options.errorOnInvalidService) {
85
71
  throw new Error(`Service not found: ${service}`);
86
72
  }
87
73
  return [];
@@ -117,9 +103,7 @@ export async function expandIamActions(actionStringOrStrings, overrideOptions) {
117
103
  const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$";
118
104
  const regex = new RegExp(pattern, 'i');
119
105
  const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`);
120
- if (options.sort) {
121
- matchingActions.sort();
122
- }
106
+ matchingActions.sort();
123
107
  return matchingActions;
124
108
  }
125
109
  //# sourceMappingURL=expand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"expand.js","sourceRoot":"","sources":["../../src/expand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE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IACtD,MAAM,OAAO,GAAG,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAA;IACjE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACtC,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC,CAAA;IAC7G,eAAe,CAAC,IAAI,EAAE,CAAA;IAEtB,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -13,7 +13,7 @@ export async function expandJsonDocument(options, document, key) {
13
13
  return await expandIamActions(document, options);
14
14
  }
15
15
  if (Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
16
- const value = await expandIamActions(document, { ...options, distinct: true });
16
+ const value = await expandIamActions(document, { ...options });
17
17
  return value;
18
18
  }
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"expand_file.js","sourceRoot":"","sources":["../../src/expand_file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,aAAa,CAAA;AAEvE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAyC,EAAE,QAAa,EAAE,GAAY;IAC7G,IAAG,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;QAC3C,IAAG,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,MAAM,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,IAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAA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,QAAQ,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,IAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACrF,MAAM,KAAK,GAAI,MAAM,gBAAgB,CAAC,QAAQ,EAAE,EAAC,GAAG,OAAO,EAAC,CAAC,CAAA;YAC7D,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,IAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC7C,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAC,CAAA;IACL,CAAC;IAED,IAAG,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAClC,MAAM,SAAS,GAAQ,EAAE,CAAA;QACzB,KAAI,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC3B,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;QAChE,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-copilot/iam-expand",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Expand AWS IAM Actions with Wildcards",
5
5
  "repository": {
6
6
  "type": "git",
package/src/cli.ts CHANGED
@@ -25,12 +25,10 @@ function printUsage() {
25
25
  console.log(` ${commandName} [options] [action1] [action2] ...`)
26
26
  console.log(` <input from stdout> | ${commandName} [options]`)
27
27
  console.log('Action Expanding Options:')
28
- console.log(' --distinct: Remove duplicate actions')
29
- console.log(' --sort: Sort the actions')
30
28
  console.log(' --expand-asterisk: Expand the * action to all actions')
31
29
  console.log(' --expand-service-asterisk: Expand service:* to all actions for that service')
32
- console.log(' --error-on-missing-service: Throw an error if a service is not found')
33
30
  console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format')
31
+ console.log(' --error-on-invalid-service: Throw an error if a service is not found')
34
32
  console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:')
35
33
  console.log(' --invalid-action-behavior=remove: Remove the invalid action')
36
34
  console.log(' --invalid-action-behavior=include: Include the invalid action')
@@ -211,11 +211,11 @@ describe("expand", () => {
211
211
  })
212
212
 
213
213
  describe("when the service in the action string does not exist", () => {
214
- it("should return an empty array when errorOnMissingService is false", async () => {
214
+ it("should return an empty array when errorOnInvalidService is false", async () => {
215
215
  //Given actionString contains a service that does not exist
216
216
  const actionString = 'fake:GetObject*'
217
217
  //And errorOnMissingService is false
218
- const options = { errorOnMissingService: false }
218
+ const options = { errorOnInvalidService: false }
219
219
 
220
220
  //When expand is called with actionString
221
221
  const result = await expandIamActions(actionString, options)
@@ -224,11 +224,11 @@ describe("expand", () => {
224
224
  expect(result).toEqual([])
225
225
  })
226
226
 
227
- it("should throw an error when errorOnMissingService is true", async () => {
227
+ it("should throw an error when errorOnInvalidService is true", async () => {
228
228
  //Given actionString contains a service that does not exist
229
229
  const actionString = 'fake:GetObject*'
230
230
  //And errorOnMissingService is true
231
- const options = { errorOnMissingService: true }
231
+ const options = { errorOnInvalidService: true }
232
232
 
233
233
  //When expand is called with actionString
234
234
  //Then an error should be thrown
@@ -327,7 +327,7 @@ describe("expand", () => {
327
327
  //Given actionString is 's3:*Object'
328
328
  const actionString = 's3:*Object'
329
329
  //And s3 service exists
330
- vi.mocked(iamServiceExists).mockReturnValue(true)
330
+ vi.mocked(iamServiceExists).mockResolvedValue(true)
331
331
  //And there are matching actions
332
332
  vi.mocked(iamActionsForService).mockResolvedValue([
333
333
  'GetObject',
@@ -369,8 +369,8 @@ describe("expand", () => {
369
369
  const result = await expandIamActions(actionString)
370
370
  //Then result should be an array of actions
371
371
  expect(result).toEqual([
372
- 's3:GetObjectTagging',
373
- 's3:GetBanskyTagging'
372
+ 's3:GetBanskyTagging',
373
+ 's3:GetObjectTagging'
374
374
  ])
375
375
  })
376
376
 
@@ -397,10 +397,10 @@ describe("expand", () => {
397
397
  const result = await expandIamActions(actionString)
398
398
  //Then result should be an array of actions
399
399
  expect(result).toEqual([
400
- 's3:GetObjectTagging',
401
400
  's3:GetBanskyTagging',
402
- 's3:GetTagging',
403
- 's3:GetSomethingTaggingSomething'
401
+ 's3:GetObjectTagging',
402
+ 's3:GetSomethingTaggingSomething',
403
+ 's3:GetTagging'
404
404
  ])
405
405
  })
406
406
  })
@@ -449,81 +449,41 @@ describe("expand", () => {
449
449
  })
450
450
  })
451
451
 
452
- describe("distinct option", () => {
453
- it('should return all values when distinct is false', async () => {
454
- //Given two action strings
455
- const actionString = ['s3:Get*','s3:*Object']
456
- //And s3 service exists
457
- vi.mocked(iamServiceExists).mockResolvedValue(true)
458
- //And there are matching actions
459
- vi.mocked(iamActionsForService).mockResolvedValue(['GetObject', 'PutObject', 'GetOtherObject'])
460
-
461
- //When expand is called with actionString and distinct is false
462
- const result = await expandIamActions(actionString, { distinct: false })
463
-
464
- //Then result should be an array of actions, even if they are duplicates
465
- expect(result).toEqual(['s3:GetObject', 's3:GetOtherObject', 's3:GetObject', 's3:PutObject', 's3:GetOtherObject'])
466
- })
467
-
468
- it('should return only unique values when distinct is true, and maintain order', async () => {
469
- //Given two action strings
470
- const actionString = ['s3:Get*','s3:*Object']
471
- //And s3 service exists
472
- vi.mocked(iamServiceExists).mockResolvedValue(true)
473
- //And there are matching actions
474
- vi.mocked(iamActionsForService).mockResolvedValue(['GetObject', 'PutObject', 'GetOtherObject'])
452
+ it('should return only unique values', async () => {
453
+ //Given two action strings
454
+ const actionString = ['s3:Get*','s3:*Object']
455
+ //And s3 service exists
456
+ vi.mocked(iamServiceExists).mockResolvedValue(true)
457
+ //And there are matching actions
458
+ vi.mocked(iamActionsForService).mockResolvedValue(['GetObject', 'PutObject', 'GetOtherObject'])
475
459
 
476
- //When expand is called with actionStrings and distinct is true
477
- const result = await expandIamActions(actionString, { distinct: true })
478
- //Then result should be an array of unique actions
479
- expect(result).toEqual(['s3:GetObject', 's3:GetOtherObject', 's3:PutObject'])
480
- })
460
+ //When expand is called with actionStrings and distinct is true
461
+ const result = await expandIamActions(actionString)
462
+ //Then result should be an array of unique actions
463
+ expect(result).toEqual(['s3:GetObject', 's3:GetOtherObject', 's3:PutObject'])
481
464
  })
482
465
 
483
- describe("sort option", () => {
484
- it('should return values in the order they were expanded when sort is false', async () => {
485
- //Given two action strings
486
- const actionString = ['s3:Get*','ec2:Describe*']
487
- //And s3 service exists
488
- vi.mocked(iamServiceExists).mockResolvedValue(true)
489
- //And there are matching actions
490
- vi.mocked(iamActionsForService).mockImplementation(async (service) => {
491
- if(service === 's3') {
492
- return ['GetObject', 'GetBucket']
493
- }
494
- if(service === 'ec2') {
495
- return ['DescribeInstances', 'DescribeVolumes']
496
- }
497
- return []
498
- })
499
-
500
- //When expand is called with actionStrings and sort is false
501
- const result = await expandIamActions(actionString, { sort: false })
502
- //Then result should be an array of actions in the order they were expanded
503
- expect(result).toEqual(['s3:GetObject', 's3:GetBucket', 'ec2:DescribeInstances', 'ec2:DescribeVolumes'])
466
+ it('should return values sorted', async () => {
467
+ //Given two action strings
468
+ const actionString = ['s3:Get*','ec2:Describe*']
469
+ //And s3 service exists
470
+ vi.mocked(iamServiceExists).mockResolvedValue(true)
471
+ //And there are matching actions
472
+ vi.mocked(iamActionsForService).mockImplementation(async (service) => {
473
+ if(service === 's3') {
474
+ return ['GetObject', 'GetBucket']
475
+ }
476
+ if(service === 'ec2') {
477
+ return ['DescribeInstances', 'DescribeVolumes']
478
+ }
479
+ return []
504
480
  })
505
481
 
506
- it('should return values sorted when sort is true', async () => {
507
- //Given two action strings
508
- const actionString = ['s3:Get*','ec2:Describe*']
509
- //And s3 service exists
510
- vi.mocked(iamServiceExists).mockResolvedValue(true)
511
- //And there are matching actions
512
- vi.mocked(iamActionsForService).mockImplementation(async (service) => {
513
- if(service === 's3') {
514
- return ['GetObject', 'GetBucket']
515
- }
516
- if(service === 'ec2') {
517
- return ['DescribeInstances', 'DescribeVolumes']
518
- }
519
- return []
520
- })
482
+ //When expand is called with actionStrings
483
+ const result = await expandIamActions(actionString)
521
484
 
522
- //When expand is called with actionStrings and sort is false
523
- const result = await expandIamActions(actionString, { sort: true })
524
- //Then result should be an array of actions in the order they were expanded
525
- expect(result).toEqual(['ec2:DescribeInstances', 'ec2:DescribeVolumes', 's3:GetBucket', 's3:GetObject'])
526
- })
485
+ //Then result should be an array of sorted actions
486
+ expect(result).toEqual(['ec2:DescribeInstances', 'ec2:DescribeVolumes', 's3:GetBucket', 's3:GetObject'])
527
487
  })
528
488
 
529
489
  })
package/src/expand.ts CHANGED
@@ -37,15 +37,7 @@ export interface ExpandIamActionsOptions {
37
37
  * If false, an empty array will be returned
38
38
  * Default: false
39
39
  */
40
- errorOnMissingService: boolean
41
-
42
- /**
43
- * If true, only unique values will be returned, while maintaining order
44
- * If false, all values will be returned, even if they are duplicates
45
- * Default: false
46
- */
47
- distinct: boolean
48
-
40
+ errorOnInvalidService: boolean
49
41
 
50
42
  /**
51
43
  * The behavior to use when an invalid action is encountered without wildcards
@@ -56,23 +48,14 @@ export interface ExpandIamActionsOptions {
56
48
  * Default: InvalidActionBehavior.Remove
57
49
  */
58
50
  invalidActionBehavior: InvalidActionBehavior
59
-
60
- /**
61
- * If true, the returned array will be sorted
62
- * If false, the returned array will be in the order they were expanded
63
- * Default: false
64
- */
65
- sort: boolean
66
51
  }
67
52
 
68
53
  const defaultOptions: ExpandIamActionsOptions = {
69
54
  expandAsterisk: false,
70
55
  expandServiceAsterisk: false,
71
56
  errorOnInvalidFormat: false,
72
- errorOnMissingService: false,
57
+ errorOnInvalidService: false,
73
58
  invalidActionBehavior: InvalidActionBehavior.Remove,
74
- distinct: false,
75
- sort: false
76
59
  }
77
60
 
78
61
  const allAsterisksPattern = /^\*+$/i
@@ -101,21 +84,9 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
101
84
  return expandIamActions(actionString, options);
102
85
  }))
103
86
 
104
- let allMatches = actionLists.flat()
105
-
106
- if(options.distinct) {
107
- const aSet = new Set<string>()
108
- allMatches = allMatches.filter((value) => {
109
- if(aSet.has(value)) {
110
- return false
111
- }
112
- aSet.add(value)
113
- return true
114
- })
115
- }
116
- if(options.sort) {
117
- allMatches.sort()
118
- }
87
+ const allMatches = Array.from(new Set(actionLists.flat()))
88
+ allMatches.sort()
89
+
119
90
  return allMatches
120
91
  }
121
92
 
@@ -152,7 +123,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
152
123
 
153
124
  const [service, wildcardActions] = parts.map(part => part.toLowerCase())
154
125
  if(!await iamServiceExists(service)) {
155
- if(options.errorOnMissingService) {
126
+ if(options.errorOnInvalidService) {
156
127
  throw new Error(`Service not found: ${service}`)
157
128
  }
158
129
  return []
@@ -189,9 +160,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
189
160
  const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$"
190
161
  const regex = new RegExp(pattern, 'i')
191
162
  const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`)
192
- if(options.sort) {
193
- matchingActions.sort()
194
- }
163
+ matchingActions.sort()
195
164
 
196
165
  return matchingActions
197
166
  }
@@ -55,7 +55,6 @@ describe('expand_file', () => {
55
55
  }
56
56
  }
57
57
  vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
58
- expect(options?.distinct).toBe(true)
59
58
  return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
60
59
  })
61
60
 
@@ -134,7 +133,6 @@ describe('expand_file', () => {
134
133
  }
135
134
  }
136
135
  vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
137
- expect(options?.distinct).toBe(true)
138
136
  return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
139
137
  })
140
138
 
@@ -14,7 +14,7 @@ export async function expandJsonDocument(options: Partial<ExpandIamActionsOption
14
14
  return await expandIamActions(document, options)
15
15
  }
16
16
  if(Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
17
- const value = await expandIamActions(document, {...options, distinct: true})
17
+ const value = await expandIamActions(document, {...options})
18
18
  return value
19
19
  }
20
20
  }