@cloud-copilot/iam-expand 0.1.4 → 0.1.6
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 +99 -21
- package/dist/cjs/cli.js +21 -10
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/cli_utils.d.ts +4 -1
- package/dist/cjs/cli_utils.d.ts.map +1 -1
- package/dist/cjs/cli_utils.js +10 -4
- package/dist/cjs/cli_utils.js.map +1 -1
- package/dist/cjs/expand.d.ts +3 -3
- package/dist/cjs/expand.d.ts.map +1 -1
- package/dist/cjs/expand.js +26 -15
- package/dist/cjs/expand.js.map +1 -1
- package/dist/cjs/expand_file.d.ts +11 -0
- package/dist/cjs/expand_file.d.ts.map +1 -0
- package/dist/cjs/expand_file.js +39 -0
- package/dist/cjs/expand_file.js.map +1 -0
- package/dist/esm/cli.js +23 -12
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/cli_utils.d.ts +4 -1
- package/dist/esm/cli_utils.d.ts.map +1 -1
- package/dist/esm/cli_utils.js +9 -3
- package/dist/esm/cli_utils.js.map +1 -1
- package/dist/esm/expand.d.ts +3 -3
- package/dist/esm/expand.d.ts.map +1 -1
- package/dist/esm/expand.js +26 -15
- package/dist/esm/expand.js.map +1 -1
- package/dist/esm/expand_file.d.ts +11 -0
- package/dist/esm/expand_file.d.ts.map +1 -0
- package/dist/esm/expand_file.js +36 -0
- package/dist/esm/expand_file.js.map +1 -0
- package/package.json +4 -3
- package/src/cli.ts +22 -12
- package/src/cli_utils.test.ts +26 -11
- package/src/cli_utils.ts +10 -4
- package/src/expand.test.ts +112 -106
- package/src/expand.ts +30 -19
- package/src/expand_file.test.ts +186 -0
- package/src/expand_file.ts +39 -0
package/README.md
CHANGED
|
@@ -13,6 +13,14 @@ Use this to:
|
|
|
13
13
|
npm install -g @cloud-copilot/iam-expand
|
|
14
14
|
```
|
|
15
15
|
|
|
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
|
+
|
|
19
|
+
```bash
|
|
20
|
+
sudo npm install -g @cloud-copilot/iam-expand
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Typescript/NodeJS Usage
|
|
16
24
|
```typescript
|
|
17
25
|
import { expandIamActions } from '@cloud-copilot/iam-expand';
|
|
18
26
|
|
|
@@ -49,7 +57,7 @@ expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
|
|
|
49
57
|
## Options
|
|
50
58
|
`expandIamActions` an optional second argument that is an object with the following options:
|
|
51
59
|
|
|
52
|
-
### `
|
|
60
|
+
### `expandAsterisk`
|
|
53
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`.
|
|
54
62
|
|
|
55
63
|
```typescript
|
|
@@ -60,12 +68,12 @@ expandIamActions('*')
|
|
|
60
68
|
['*']
|
|
61
69
|
|
|
62
70
|
//Returns the expanded value
|
|
63
|
-
expandIamActions('*', {
|
|
71
|
+
expandIamActions('*', { expandAsterisk: true })
|
|
64
72
|
[
|
|
65
73
|
//Many many strings. 🫢
|
|
66
74
|
]
|
|
67
75
|
```
|
|
68
|
-
### `
|
|
76
|
+
### `expandServiceAsterisk`
|
|
69
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`.
|
|
70
78
|
|
|
71
79
|
```typescript
|
|
@@ -76,7 +84,7 @@ expandIamActions('s3:*')
|
|
|
76
84
|
['s3:*']
|
|
77
85
|
|
|
78
86
|
//Returns the expanded value
|
|
79
|
-
expandIamActions('s3:*', {
|
|
87
|
+
expandIamActions('s3:*', { expandServiceAsterisk: true })
|
|
80
88
|
[
|
|
81
89
|
//All the s3 actions. 🫢
|
|
82
90
|
]
|
|
@@ -206,7 +214,14 @@ yarn global add @cloud-copilot/iam-data
|
|
|
206
214
|
yarn global add @cloud-copilot/iam-expand
|
|
207
215
|
```
|
|
208
216
|
|
|
209
|
-
###
|
|
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.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
sudo npm install -g @cloud-copilot/iam-expand
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Run the script in a project that has the package installed
|
|
210
225
|
```bash
|
|
211
226
|
npx @cloud-copilot/iam-expand
|
|
212
227
|
```
|
|
@@ -221,7 +236,7 @@ You can pass in all options available through the api as dash separated flags.
|
|
|
221
236
|
|
|
222
237
|
_Prints all matching actions for s3:Get*Tagging, s3:*Tag*, and ec2:* in alphabetical order with duplicates removed:_
|
|
223
238
|
```bash
|
|
224
|
-
iam-expand s3:Get*Tagging s3:*Tag* ec2:* --expand-service-
|
|
239
|
+
iam-expand s3:Get*Tagging s3:*Tag* ec2:* --expand-service-asterisk --distinct --sort
|
|
225
240
|
```
|
|
226
241
|
|
|
227
242
|
### Help
|
|
@@ -231,10 +246,84 @@ iam-expand
|
|
|
231
246
|
```
|
|
232
247
|
|
|
233
248
|
### Read from stdin
|
|
234
|
-
The CLI is able to read from stdin, and 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.
|
|
235
|
-
|
|
236
249
|
If no actions are passed as arguments, the CLI will read from stdin.
|
|
237
250
|
|
|
251
|
+
#### 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.
|
|
253
|
+
|
|
254
|
+
Given `policy.json`
|
|
255
|
+
```json
|
|
256
|
+
|
|
257
|
+
{
|
|
258
|
+
"Version": "2012-10-17",
|
|
259
|
+
"Statement": [
|
|
260
|
+
{
|
|
261
|
+
"Effect": "Allow",
|
|
262
|
+
"Action": "s3:Get*Tagging",
|
|
263
|
+
"Resource": "*"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"Effect": "Deny",
|
|
267
|
+
"NotAction": ["s3:Get*Tagging", "s3:Put*Tagging"],
|
|
268
|
+
"Resource": "*"
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
cat policy.json | iam-expand > expanded-policy.json
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Gives this file in `expanded-policy.json`
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"Version": "2012-10-17",
|
|
282
|
+
"Statement": [
|
|
283
|
+
{
|
|
284
|
+
"Effect": "Allow",
|
|
285
|
+
// Was "s3:Get*Tagging"
|
|
286
|
+
"Action": [
|
|
287
|
+
"s3:GetBucketTagging",
|
|
288
|
+
"s3:GetJobTagging",
|
|
289
|
+
"s3:GetObjectTagging",
|
|
290
|
+
"s3:GetObjectVersionTagging",
|
|
291
|
+
"s3:GetStorageLensConfigurationTagging"
|
|
292
|
+
],
|
|
293
|
+
"Resource": "*"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"Effect": "Deny",
|
|
297
|
+
// Was ["s3:Get*Tagging", "s3:Put*Tagging"]
|
|
298
|
+
"NotAction": [
|
|
299
|
+
"s3:GetBucketTagging",
|
|
300
|
+
"s3:GetJobTagging",
|
|
301
|
+
"s3:GetObjectTagging",
|
|
302
|
+
"s3:GetObjectVersionTagging",
|
|
303
|
+
"s3:GetStorageLensConfigurationTagging",
|
|
304
|
+
"s3:PutBucketTagging",
|
|
305
|
+
"s3:PutJobTagging",
|
|
306
|
+
"s3:PutObjectTagging",
|
|
307
|
+
"s3:PutObjectVersionTagging",
|
|
308
|
+
"s3:PutStorageLensConfigurationTagging"
|
|
309
|
+
],
|
|
310
|
+
"Resource": "*"
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
You can also use this to expand the actions from the output of commands.
|
|
317
|
+
```bash
|
|
318
|
+
aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-inline-policies.json
|
|
319
|
+
# Now you can search the output for actions you are interested in
|
|
320
|
+
grep -n "kms:DisableKey" expanded-inline-policies.json
|
|
321
|
+
```
|
|
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
|
+
|
|
324
|
+
#### 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.
|
|
326
|
+
|
|
238
327
|
You can echo some content:
|
|
239
328
|
```bash
|
|
240
329
|
echo "s3:Get*Tagging" | iam-expand
|
|
@@ -245,11 +334,6 @@ You can pull out part of a json file and pipe it in:
|
|
|
245
334
|
cat policy.json | jq '.Statement[].Action' | iam-expand
|
|
246
335
|
```
|
|
247
336
|
|
|
248
|
-
Or just send in the whole file:
|
|
249
|
-
```bash
|
|
250
|
-
cat policy.json | iam-expand
|
|
251
|
-
```
|
|
252
|
-
|
|
253
337
|
Or some Terraform:
|
|
254
338
|
```bash
|
|
255
339
|
cat main.tf | iam-expand
|
|
@@ -265,14 +349,8 @@ Or even some HTML:
|
|
|
265
349
|
curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/SecurityAudit.html" | iam-expand
|
|
266
350
|
```
|
|
267
351
|
|
|
268
|
-
Or the output of
|
|
269
|
-
|
|
270
|
-
This will search for all inline policies that have have
|
|
271
|
-
```bash
|
|
272
|
-
aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterik --read-wait-time=20_000 | grep kms:DisableKey
|
|
273
|
-
```
|
|
274
|
-
_--expand-service-asterik 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_
|
|
352
|
+
Or the output of any command.
|
|
275
353
|
|
|
276
|
-
Because of the likelyhood of finding an aseterik `*` in the input
|
|
354
|
+
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.
|
|
277
355
|
|
|
278
356
|
Please give this anything you can think of and open an issue if you see an opportunity for improvement.
|
package/dist/cjs/cli.js
CHANGED
|
@@ -5,9 +5,9 @@ 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
|
-
function expandAndPrint(actionStrings, options) {
|
|
8
|
+
async function expandAndPrint(actionStrings, options) {
|
|
9
9
|
try {
|
|
10
|
-
const result = (0, expand_js_1.expandIamActions)(actionStrings, options);
|
|
10
|
+
const result = await (0, expand_js_1.expandIamActions)(actionStrings, options);
|
|
11
11
|
for (const action of result) {
|
|
12
12
|
console.log(action);
|
|
13
13
|
}
|
|
@@ -25,8 +25,8 @@ function printUsage() {
|
|
|
25
25
|
console.log('Action Expanding Options:');
|
|
26
26
|
console.log(' --distinct: Remove duplicate actions');
|
|
27
27
|
console.log(' --sort: Sort the actions');
|
|
28
|
-
console.log(' --expand-
|
|
29
|
-
console.log(' --expand-service-
|
|
28
|
+
console.log(' --expand-asterisk: Expand the * action to all actions');
|
|
29
|
+
console.log(' --expand-service-asterisk: Expand service:* to all actions for that service');
|
|
30
30
|
console.log(' --error-on-missing-service: Throw an error if a service is not found');
|
|
31
31
|
console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format');
|
|
32
32
|
console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:');
|
|
@@ -53,18 +53,29 @@ for (const arg of args) {
|
|
|
53
53
|
async function run() {
|
|
54
54
|
const options = (0, cli_utils_js_1.convertOptions)(optionStrings);
|
|
55
55
|
if (options.showDataVersion) {
|
|
56
|
-
|
|
56
|
+
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}`);
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
62
|
if (actionStrings.length === 0) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
//If no actions are provided, read from stdin
|
|
64
|
+
const stdInResult = await (0, cli_utils_js_1.parseStdIn)(options);
|
|
65
|
+
if (stdInResult.object) {
|
|
66
|
+
console.log(JSON.stringify(stdInResult.object, null, 2));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
else if (stdInResult.strings) {
|
|
70
|
+
const otherActions = stdInResult.strings;
|
|
71
|
+
if (otherActions.length > 0 && options.expandAsterisk) {
|
|
72
|
+
console.warn('Notice: --expand-asterisk is not supported when reading from stdin, ignoring.');
|
|
73
|
+
}
|
|
74
|
+
actionStrings.push(...otherActions);
|
|
63
75
|
}
|
|
64
|
-
actionStrings.push(...otherActions);
|
|
65
76
|
}
|
|
66
77
|
if (actionStrings.length > 0) {
|
|
67
|
-
expandAndPrint(actionStrings, options);
|
|
78
|
+
await expandAndPrint(actionStrings, options);
|
|
68
79
|
return;
|
|
69
80
|
}
|
|
70
81
|
printUsage();
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;AAEA,
|
|
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,OA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AAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YACxD,OAAM;QACR,CAAC;aAAM,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAA;YACxC,IAAG,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;gBACrD,OAAO,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAA;YAC/F,CAAC;YACD,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;IAED,IAAG,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,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"}
|
package/dist/cjs/cli_utils.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export declare function extractActionsFromLineOfInput(line: string): string[];
|
|
|
22
22
|
*
|
|
23
23
|
* @returns an array of strings from stdin
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function parseStdIn(options: Partial<CliOptions>): Promise<{
|
|
26
|
+
strings?: string[];
|
|
27
|
+
object?: any;
|
|
28
|
+
}>;
|
|
26
29
|
export {};
|
|
27
30
|
//# sourceMappingURL=cli_utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli_utils.d.ts","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAyB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"cli_utils.d.ts","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAyB,MAAM,aAAa,CAAC;AAI7E,UAAU,UAAW,SAAQ,uBAAuB;IAClD,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAyBxE;AAGD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMpE;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAC,CAAC,CAgB1G"}
|
package/dist/cjs/cli_utils.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.dashToCamelCase = dashToCamelCase;
|
|
4
4
|
exports.convertOptions = convertOptions;
|
|
5
5
|
exports.extractActionsFromLineOfInput = extractActionsFromLineOfInput;
|
|
6
|
-
exports.
|
|
6
|
+
exports.parseStdIn = parseStdIn;
|
|
7
7
|
const expand_js_1 = require("./expand.js");
|
|
8
|
+
const expand_file_js_1 = require("./expand_file.js");
|
|
8
9
|
const stdin_js_1 = require("./stdin.js");
|
|
9
10
|
/**
|
|
10
11
|
* Convert a dash-case string to camelCase
|
|
@@ -56,14 +57,19 @@ function extractActionsFromLineOfInput(line) {
|
|
|
56
57
|
*
|
|
57
58
|
* @returns an array of strings from stdin
|
|
58
59
|
*/
|
|
59
|
-
async function
|
|
60
|
+
async function parseStdIn(options) {
|
|
60
61
|
const delay = options.readWaitTime ? parseInt(options.readWaitTime.replaceAll(/\D/g, '')) : undefined;
|
|
61
62
|
const data = await (0, stdin_js_1.readStdin)(delay);
|
|
62
63
|
if (data.length === 0) {
|
|
63
|
-
return
|
|
64
|
+
return {};
|
|
64
65
|
}
|
|
66
|
+
try {
|
|
67
|
+
const object = await (0, expand_file_js_1.expandJsonDocument)(options, JSON.parse(data));
|
|
68
|
+
return { object };
|
|
69
|
+
}
|
|
70
|
+
catch (err) { }
|
|
65
71
|
const lines = data.split('\n');
|
|
66
72
|
const actions = lines.flatMap(line => extractActionsFromLineOfInput(line));
|
|
67
|
-
return actions;
|
|
73
|
+
return { strings: actions };
|
|
68
74
|
}
|
|
69
75
|
//# sourceMappingURL=cli_utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli_utils.js","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"cli_utils.js","sourceRoot":"","sources":["../../src/cli_utils.ts"],"names":[],"mappings":";;AAeA,0CAGC;AAQD,wCAyBC;AAGD,sEAMC;AAOD,gCAgBC;AAlFD,2CAA6E;AAC7E,qDAAsD;AACtD,yCAAuC;AAOvC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACtB,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,UAAoB;IACjD,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KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SAC5E,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACvC,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,UAAU,CAAC,OAA4B;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACrG,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAA;IACnC,IAAG,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAA,mCAAkB,EAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;QAClE,OAAO,EAAC,MAAM,EAAC,CAAA;IACjB,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC,CAAA,CAAC;IAGrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1E,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,CAAA;AAC3B,CAAC"}
|
package/dist/cjs/expand.d.ts
CHANGED
|
@@ -13,13 +13,13 @@ export interface ExpandIamActionsOptions {
|
|
|
13
13
|
* If false, a single `*` will be returned as is
|
|
14
14
|
* Default: false
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
expandAsterisk: boolean;
|
|
17
17
|
/**
|
|
18
18
|
* If true, `service:*` will be expanded to all actions for that service
|
|
19
19
|
* If false, `service:*` will be returned as is
|
|
20
20
|
* Default: false
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
expandServiceAsterisk: boolean;
|
|
23
23
|
/**
|
|
24
24
|
* If true, an error will be thrown if the action string is not in the correct format
|
|
25
25
|
* If false, an empty array will be returned
|
|
@@ -65,5 +65,5 @@ export interface ExpandIamActionsOptions {
|
|
|
65
65
|
* @param overrideOptions Options to override the default behavior
|
|
66
66
|
* @returns An array of expanded action strings flattend to a single array
|
|
67
67
|
*/
|
|
68
|
-
export declare function expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>): string[]
|
|
68
|
+
export declare function expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>): Promise<string[]>;
|
|
69
69
|
//# sourceMappingURL=expand.d.ts.map
|
package/dist/cjs/expand.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/cjs/expand.js
CHANGED
|
@@ -10,15 +10,15 @@ var InvalidActionBehavior;
|
|
|
10
10
|
InvalidActionBehavior["Include"] = "Include";
|
|
11
11
|
})(InvalidActionBehavior || (exports.InvalidActionBehavior = InvalidActionBehavior = {}));
|
|
12
12
|
const defaultOptions = {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
expandAsterisk: false,
|
|
14
|
+
expandServiceAsterisk: false,
|
|
15
15
|
errorOnInvalidFormat: false,
|
|
16
16
|
errorOnMissingService: false,
|
|
17
17
|
invalidActionBehavior: InvalidActionBehavior.Remove,
|
|
18
18
|
distinct: false,
|
|
19
19
|
sort: false
|
|
20
20
|
};
|
|
21
|
-
const
|
|
21
|
+
const allAsterisksPattern = /^\*+$/i;
|
|
22
22
|
/**
|
|
23
23
|
* Expands an IAM action string that contains wildcards.
|
|
24
24
|
* If the action string contains no wildcards, it is returned as is.
|
|
@@ -30,14 +30,17 @@ const allAsteriksPattern = /^\*+$/i;
|
|
|
30
30
|
* @param overrideOptions Options to override the default behavior
|
|
31
31
|
* @returns An array of expanded action strings flattend to a single array
|
|
32
32
|
*/
|
|
33
|
-
function expandIamActions(actionStringOrStrings, overrideOptions) {
|
|
33
|
+
async function expandIamActions(actionStringOrStrings, overrideOptions) {
|
|
34
34
|
const options = { ...defaultOptions, ...overrideOptions };
|
|
35
35
|
if (!actionStringOrStrings) {
|
|
36
36
|
//Just in case the user passes in null or undefined
|
|
37
37
|
return [];
|
|
38
38
|
}
|
|
39
39
|
if (Array.isArray(actionStringOrStrings)) {
|
|
40
|
-
|
|
40
|
+
const actionLists = await Promise.all(actionStringOrStrings.map(async (actionString) => {
|
|
41
|
+
return expandIamActions(actionString, options);
|
|
42
|
+
}));
|
|
43
|
+
let allMatches = actionLists.flat();
|
|
41
44
|
if (options.distinct) {
|
|
42
45
|
const aSet = new Set();
|
|
43
46
|
allMatches = allMatches.filter((value) => {
|
|
@@ -54,10 +57,16 @@ function expandIamActions(actionStringOrStrings, overrideOptions) {
|
|
|
54
57
|
return allMatches;
|
|
55
58
|
}
|
|
56
59
|
const actionString = actionStringOrStrings.trim();
|
|
57
|
-
if (actionString.match(
|
|
58
|
-
if (options.
|
|
60
|
+
if (actionString.match(allAsterisksPattern)) {
|
|
61
|
+
if (options.expandAsterisk) {
|
|
59
62
|
//If that's really what you want...
|
|
60
|
-
|
|
63
|
+
const allActions = [];
|
|
64
|
+
const serviceKeys = await (0, iam_data_1.iamServiceKeys)();
|
|
65
|
+
for await (const service of serviceKeys) {
|
|
66
|
+
const serviceActions = await (0, iam_data_1.iamActionsForService)(service);
|
|
67
|
+
allActions.push(...serviceActions.map(action => `${service}:${action}`));
|
|
68
|
+
}
|
|
69
|
+
return allActions;
|
|
61
70
|
}
|
|
62
71
|
return ['*'];
|
|
63
72
|
}
|
|
@@ -75,22 +84,24 @@ function expandIamActions(actionStringOrStrings, overrideOptions) {
|
|
|
75
84
|
return [];
|
|
76
85
|
}
|
|
77
86
|
const [service, wildcardActions] = parts.map(part => part.toLowerCase());
|
|
78
|
-
if (!(0, iam_data_1.iamServiceExists)(service)) {
|
|
87
|
+
if (!await (0, iam_data_1.iamServiceExists)(service)) {
|
|
79
88
|
if (options.errorOnMissingService) {
|
|
80
89
|
throw new Error(`Service not found: ${service}`);
|
|
81
90
|
}
|
|
82
91
|
return [];
|
|
83
92
|
}
|
|
84
|
-
if (wildcardActions.match(
|
|
85
|
-
if (options.
|
|
86
|
-
|
|
93
|
+
if (wildcardActions.match(allAsterisksPattern)) {
|
|
94
|
+
if (options.expandServiceAsterisk) {
|
|
95
|
+
const actionsForService = await (0, iam_data_1.iamActionsForService)(service);
|
|
96
|
+
return actionsForService.map(action => `${service}:${action}`);
|
|
87
97
|
}
|
|
88
98
|
return [`${service}:*`];
|
|
89
99
|
}
|
|
90
100
|
if (!actionString.includes('*')) {
|
|
91
|
-
const actionExists = (0, iam_data_1.iamActionExists)(service, wildcardActions);
|
|
101
|
+
const actionExists = await (0, iam_data_1.iamActionExists)(service, wildcardActions);
|
|
92
102
|
if (actionExists) {
|
|
93
|
-
|
|
103
|
+
const details = await (0, iam_data_1.iamActionDetails)(service, wildcardActions);
|
|
104
|
+
return [service + ":" + details.name];
|
|
94
105
|
}
|
|
95
106
|
if (options.invalidActionBehavior === InvalidActionBehavior.Remove) {
|
|
96
107
|
return [];
|
|
@@ -106,7 +117,7 @@ function expandIamActions(actionStringOrStrings, overrideOptions) {
|
|
|
106
117
|
throw new Error(`Invalid invalidActionBehavior: ${options.invalidActionBehavior}`);
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
|
-
const allActions = (0, iam_data_1.iamActionsForService)(service);
|
|
120
|
+
const allActions = await (0, iam_data_1.iamActionsForService)(service);
|
|
110
121
|
const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$";
|
|
111
122
|
const regex = new RegExp(pattern, 'i');
|
|
112
123
|
const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`);
|
package/dist/cjs/expand.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expand.js","sourceRoot":"","sources":["../../src/expand.ts"],"names":[],"mappings":";;;AA0FA,
|
|
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,CA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AE,CAAC;YAC1E,OAAO,CAAC,YAAY,CAAC,CAAA;QACvB,CAAC;aAAM,IAAG,OAAO,CAAC,qBAAqB,KAAK,qBAAqB,CAAC,KAAK,EAAE,CAAC;YACxE,MAAM,IAAI,KAAK,CAAC,mBAAmB,YAAY,EAAE,CAAC,CAAA;QACpD,CAAC;aAAM,CAAC;YACN,0BAA0B;YAC1B,MAAM,IAAI,KAAK,CAAC,kCAAkC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAA;QACpF,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,IAAA,+BAAoB,EAAC,OAAO,CAAC,CAAA;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,IAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,eAAe,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExpandIamActionsOptions } from "./expand.js";
|
|
2
|
+
/**
|
|
3
|
+
* Takes any JSON document and expands any Action found in the document
|
|
4
|
+
*
|
|
5
|
+
* @param options the options to use when expanding the actions
|
|
6
|
+
* @param document the JSON document to expand
|
|
7
|
+
* @param key the key of the current node in the document
|
|
8
|
+
* @returns the expanded JSON document
|
|
9
|
+
*/
|
|
10
|
+
export declare function expandJsonDocument(options: Partial<ExpandIamActionsOptions>, document: any, key?: string): Promise<any>;
|
|
11
|
+
//# sourceMappingURL=expand_file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand_file.d.ts","sourceRoot":"","sources":["../../src/expand_file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAEvE;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA4B7H"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandJsonDocument = expandJsonDocument;
|
|
4
|
+
const expand_js_1 = require("./expand.js");
|
|
5
|
+
/**
|
|
6
|
+
* Takes any JSON document and expands any Action found in the document
|
|
7
|
+
*
|
|
8
|
+
* @param options the options to use when expanding the actions
|
|
9
|
+
* @param document the JSON document to expand
|
|
10
|
+
* @param key the key of the current node in the document
|
|
11
|
+
* @returns the expanded JSON document
|
|
12
|
+
*/
|
|
13
|
+
async function expandJsonDocument(options, document, key) {
|
|
14
|
+
if (key === 'Action' || key === 'NotAction') {
|
|
15
|
+
if (typeof document === 'string') {
|
|
16
|
+
return await (0, expand_js_1.expandIamActions)(document, options);
|
|
17
|
+
}
|
|
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 });
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(document)) {
|
|
24
|
+
return Promise.all(document.map(async (item) => {
|
|
25
|
+
return expandJsonDocument(options, item);
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
if (typeof document === 'object') {
|
|
29
|
+
const keys = Object.keys(document);
|
|
30
|
+
const newObject = {};
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const value = document[key];
|
|
33
|
+
newObject[key] = await expandJsonDocument(options, value, key);
|
|
34
|
+
}
|
|
35
|
+
return newObject;
|
|
36
|
+
}
|
|
37
|
+
return document;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=expand_file.js.map
|
|
@@ -0,0 +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,CAAA;YAC7E,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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { iamDataVersion } from "@cloud-copilot/iam-data";
|
|
3
|
-
import { convertOptions,
|
|
2
|
+
import { iamDataUpdatedAt, iamDataVersion } from "@cloud-copilot/iam-data";
|
|
3
|
+
import { convertOptions, parseStdIn } from "./cli_utils.js";
|
|
4
4
|
import { expandIamActions } from "./expand.js";
|
|
5
5
|
const commandName = 'iam-expand';
|
|
6
|
-
function expandAndPrint(actionStrings, options) {
|
|
6
|
+
async function expandAndPrint(actionStrings, options) {
|
|
7
7
|
try {
|
|
8
|
-
const result = expandIamActions(actionStrings, options);
|
|
8
|
+
const result = await expandIamActions(actionStrings, options);
|
|
9
9
|
for (const action of result) {
|
|
10
10
|
console.log(action);
|
|
11
11
|
}
|
|
@@ -23,8 +23,8 @@ function printUsage() {
|
|
|
23
23
|
console.log('Action Expanding Options:');
|
|
24
24
|
console.log(' --distinct: Remove duplicate actions');
|
|
25
25
|
console.log(' --sort: Sort the actions');
|
|
26
|
-
console.log(' --expand-
|
|
27
|
-
console.log(' --expand-service-
|
|
26
|
+
console.log(' --expand-asterisk: Expand the * action to all actions');
|
|
27
|
+
console.log(' --expand-service-asterisk: Expand service:* to all actions for that service');
|
|
28
28
|
console.log(' --error-on-missing-service: Throw an error if a service is not found');
|
|
29
29
|
console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format');
|
|
30
30
|
console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:');
|
|
@@ -51,18 +51,29 @@ for (const arg of args) {
|
|
|
51
51
|
async function run() {
|
|
52
52
|
const options = convertOptions(optionStrings);
|
|
53
53
|
if (options.showDataVersion) {
|
|
54
|
-
|
|
54
|
+
const version = await iamDataVersion();
|
|
55
|
+
const updatedAt = await iamDataUpdatedAt();
|
|
56
|
+
console.log(`@cloud-copilot/iam-data version: ${version}`);
|
|
57
|
+
console.log(`Data last updated: ${updatedAt}`);
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
60
|
if (actionStrings.length === 0) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
//If no actions are provided, read from stdin
|
|
62
|
+
const stdInResult = await parseStdIn(options);
|
|
63
|
+
if (stdInResult.object) {
|
|
64
|
+
console.log(JSON.stringify(stdInResult.object, null, 2));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
else if (stdInResult.strings) {
|
|
68
|
+
const otherActions = stdInResult.strings;
|
|
69
|
+
if (otherActions.length > 0 && options.expandAsterisk) {
|
|
70
|
+
console.warn('Notice: --expand-asterisk is not supported when reading from stdin, ignoring.');
|
|
71
|
+
}
|
|
72
|
+
actionStrings.push(...otherActions);
|
|
61
73
|
}
|
|
62
|
-
actionStrings.push(...otherActions);
|
|
63
74
|
}
|
|
64
75
|
if (actionStrings.length > 0) {
|
|
65
|
-
expandAndPrint(actionStrings, options);
|
|
76
|
+
await expandAndPrint(actionStrings, options);
|
|
66
77
|
return;
|
|
67
78
|
}
|
|
68
79
|
printUsage();
|
package/dist/esm/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAA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esm/cli_utils.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export declare function extractActionsFromLineOfInput(line: string): string[];
|
|
|
22
22
|
*
|
|
23
23
|
* @returns an array of strings from stdin
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function parseStdIn(options: Partial<CliOptions>): Promise<{
|
|
26
|
+
strings?: string[];
|
|
27
|
+
object?: any;
|
|
28
|
+
}>;
|
|
26
29
|
export {};
|
|
27
30
|
//# sourceMappingURL=cli_utils.d.ts.map
|