@cloud-copilot/iam-expand 0.1.6 → 0.1.7
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 +44 -19
- package/dist/cjs/cli.js +7 -4
- package/dist/cjs/cli.js.map +1 -1
- package/dist/esm/cli.js +7 -4
- package/dist/esm/cli.js.map +1 -1
- package/examples/README.md +3 -0
- package/examples/download-and-expand-authorization-details.sh +8 -0
- package/examples/download-and-expand-policies.sh +22 -0
- package/package.json +1 -1
- package/src/cli.ts +8 -4
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# Expand IAM Actions
|
|
2
|
-
|
|
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
5
|
1) Expand out wildcards in actions when you are not allowed to use wildcards in your IAM policy.
|
|
8
6
|
2) Get an exhaustive list of actions that are included in a policy and quickly search it for interesting actions.
|
|
9
7
|
3) Investigate where dangerous or dubious actions are being used in your policies.
|
|
10
8
|
|
|
9
|
+
Published in ESM and CommonJS plus available as a [CLI](#cli).
|
|
10
|
+
|
|
11
|
+
All information is sourced from the [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data) which is updated daily.
|
|
12
|
+
|
|
11
13
|
## Installation
|
|
12
14
|
```bash
|
|
13
15
|
npm install -g @cloud-copilot/iam-expand
|
|
@@ -15,9 +17,9 @@ npm install -g @cloud-copilot/iam-expand
|
|
|
15
17
|
|
|
16
18
|
### AWS CloudShell Installation
|
|
17
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.
|
|
18
|
-
|
|
19
20
|
```bash
|
|
20
21
|
sudo npm install -g @cloud-copilot/iam-expand
|
|
22
|
+
iam-expand
|
|
21
23
|
```
|
|
22
24
|
|
|
23
25
|
## Typescript/NodeJS Usage
|
|
@@ -58,7 +60,7 @@ expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
|
|
|
58
60
|
`expandIamActions` an optional second argument that is an object with the following options:
|
|
59
61
|
|
|
60
62
|
### `expandAsterisk`
|
|
61
|
-
By default, a single `*` not be expanded.
|
|
63
|
+
By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this option to `true`.
|
|
62
64
|
|
|
63
65
|
```typescript
|
|
64
66
|
import { expandIamActions } from '@cloud-copilot/iam-expand';
|
|
@@ -134,7 +136,7 @@ expandIamActions(['s3:GetObject*','s3:Get*Tagging'],{distinct:true})
|
|
|
134
136
|
```
|
|
135
137
|
|
|
136
138
|
### `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`.
|
|
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`.
|
|
138
140
|
|
|
139
141
|
```typescript
|
|
140
142
|
import { expandIamActions } from '@cloud-copilot/iam-expand';
|
|
@@ -201,10 +203,36 @@ expandIamActions('r2:Get*Tagging', { errorOnMissingService: true })
|
|
|
201
203
|
//Uncaught Error: Service not found: r2
|
|
202
204
|
```
|
|
203
205
|
|
|
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
|
|
223
|
+
|
|
224
|
+
//Include invalid action
|
|
225
|
+
expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: InvalidActionBehavior.Include })
|
|
226
|
+
['ec2:DestroyAvailabilityZone']
|
|
227
|
+
```
|
|
228
|
+
|
|
204
229
|
## CLI
|
|
205
|
-
There is a 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.
|
|
231
|
+
|
|
232
|
+
### Installation
|
|
233
|
+
You can install it globally and use the command `iam-expand` or add it to a single project and use `npx`.
|
|
206
234
|
|
|
207
|
-
|
|
235
|
+
#### Install Globally
|
|
208
236
|
```bash
|
|
209
237
|
npm install -g @cloud-copilot/iam-expand
|
|
210
238
|
```
|
|
@@ -214,16 +242,14 @@ yarn global add @cloud-copilot/iam-data
|
|
|
214
242
|
yarn global add @cloud-copilot/iam-expand
|
|
215
243
|
```
|
|
216
244
|
|
|
217
|
-
### AWS CloudShell Installation
|
|
218
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.
|
|
219
246
|
|
|
220
247
|
```bash
|
|
221
248
|
sudo npm install -g @cloud-copilot/iam-expand
|
|
222
249
|
```
|
|
223
|
-
|
|
224
|
-
### Run the script in a project that has the package installed
|
|
250
|
+
#### Install in a project
|
|
225
251
|
```bash
|
|
226
|
-
|
|
252
|
+
npm install @cloud-copilot/iam-expand
|
|
227
253
|
```
|
|
228
254
|
|
|
229
255
|
### Simple Usage
|
|
@@ -234,13 +260,13 @@ iam-expand s3:Get* s3:*Tag*
|
|
|
234
260
|
|
|
235
261
|
You can pass in all options available through the api as dash separated flags.
|
|
236
262
|
|
|
237
|
-
_Prints all matching actions for s3:Get*Tagging
|
|
263
|
+
_Prints all matching actions for `s3:Get*Tagging`, `s3:*Tag*`, and `ec2:*` in alphabetical order with duplicates removed:_
|
|
238
264
|
```bash
|
|
239
265
|
iam-expand s3:Get*Tagging s3:*Tag* ec2:* --expand-service-asterisk --distinct --sort
|
|
240
266
|
```
|
|
241
267
|
|
|
242
268
|
### Help
|
|
243
|
-
|
|
269
|
+
Run the command with no options to show usage:
|
|
244
270
|
```bash
|
|
245
271
|
iam-expand
|
|
246
272
|
```
|
|
@@ -249,7 +275,7 @@ iam-expand
|
|
|
249
275
|
If no actions are passed as arguments, the CLI will read from stdin.
|
|
250
276
|
|
|
251
277
|
#### Expanding JSON input
|
|
252
|
-
If the input is a valid json document, the CLI will find every instance of `Action` and
|
|
278
|
+
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
279
|
|
|
254
280
|
Given `policy.json`
|
|
255
281
|
```json
|
|
@@ -315,14 +341,13 @@ Gives this file in `expanded-policy.json`
|
|
|
315
341
|
|
|
316
342
|
You can also use this to expand the actions from the output of commands.
|
|
317
343
|
```bash
|
|
318
|
-
aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-
|
|
344
|
+
aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-authorization-details.json
|
|
319
345
|
# Now you can search the output for actions you are interested in
|
|
320
346
|
grep -n "kms:DisableKey" expanded-inline-policies.json
|
|
321
347
|
```
|
|
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
348
|
|
|
324
349
|
#### Expanding arbitrary input
|
|
325
|
-
If the input from stdin is not json, the content is searched for actions
|
|
350
|
+
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
351
|
|
|
327
352
|
You can echo some content:
|
|
328
353
|
```bash
|
|
@@ -346,7 +371,7 @@ cat template.yaml | iam-expand
|
|
|
346
371
|
|
|
347
372
|
Or even some HTML:
|
|
348
373
|
```bash
|
|
349
|
-
curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/
|
|
374
|
+
curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/ReadOnlyAccess.html" | iam-expand
|
|
350
375
|
```
|
|
351
376
|
|
|
352
377
|
Or the output of any command.
|
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);
|
|
@@ -35,7 +36,7 @@ function printUsage() {
|
|
|
35
36
|
console.log(' --invalid-action-behavior=error: Throw an error if an invalid action is encountered');
|
|
36
37
|
console.log('CLI Behavior Options:');
|
|
37
38
|
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
|
|
39
|
+
console.log(' --read-wait-time: Millisenconds to wait for the first byte from stdin before timing out.');
|
|
39
40
|
console.log(' Example: --read-wait-time=10_000');
|
|
40
41
|
process.exit(1);
|
|
41
42
|
}
|
|
@@ -54,9 +55,11 @@ async function run() {
|
|
|
54
55
|
const options = (0, cli_utils_js_1.convertOptions)(optionStrings);
|
|
55
56
|
if (options.showDataVersion) {
|
|
56
57
|
const version = await (0, iam_data_1.iamDataVersion)();
|
|
57
|
-
const updatedAt =
|
|
58
|
-
console.log(
|
|
59
|
-
console.log(`
|
|
58
|
+
const updatedAt = console.log(`${dataPackage} version: ${version}`);
|
|
59
|
+
console.log(`Data last updated: ${await (0, iam_data_1.iamDataUpdatedAt)()}`);
|
|
60
|
+
console.log(`Update with either:`);
|
|
61
|
+
console.log(` npm update ${dataPackage}`);
|
|
62
|
+
console.log(` npm update -g ${dataPackage}`);
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
62
65
|
if (actionStrings.length === 0) {
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -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;
|
|
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,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AG,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/esm/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { iamDataUpdatedAt, iamDataVersion } from "@cloud-copilot/iam-data";
|
|
|
3
3
|
import { convertOptions, parseStdIn } from "./cli_utils.js";
|
|
4
4
|
import { expandIamActions } from "./expand.js";
|
|
5
5
|
const commandName = 'iam-expand';
|
|
6
|
+
const dataPackage = '@cloud-copilot/iam-data';
|
|
6
7
|
async function expandAndPrint(actionStrings, options) {
|
|
7
8
|
try {
|
|
8
9
|
const result = await expandIamActions(actionStrings, options);
|
|
@@ -33,7 +34,7 @@ function printUsage() {
|
|
|
33
34
|
console.log(' --invalid-action-behavior=error: Throw an error if an invalid action is encountered');
|
|
34
35
|
console.log('CLI Behavior Options:');
|
|
35
36
|
console.log(' --show-data-version: Print the version of the iam-data package being used and exit');
|
|
36
|
-
console.log(' --read-wait-time: Millisenconds to wait for
|
|
37
|
+
console.log(' --read-wait-time: Millisenconds to wait for the first byte from stdin before timing out.');
|
|
37
38
|
console.log(' Example: --read-wait-time=10_000');
|
|
38
39
|
process.exit(1);
|
|
39
40
|
}
|
|
@@ -52,9 +53,11 @@ async function run() {
|
|
|
52
53
|
const options = convertOptions(optionStrings);
|
|
53
54
|
if (options.showDataVersion) {
|
|
54
55
|
const version = await iamDataVersion();
|
|
55
|
-
const updatedAt =
|
|
56
|
-
console.log(
|
|
57
|
-
console.log(`
|
|
56
|
+
const updatedAt = console.log(`${dataPackage} version: ${version}`);
|
|
57
|
+
console.log(`Data last updated: ${await iamDataUpdatedAt()}`);
|
|
58
|
+
console.log(`Update with either:`);
|
|
59
|
+
console.log(` npm update ${dataPackage}`);
|
|
60
|
+
console.log(` npm update -g ${dataPackage}`);
|
|
58
61
|
return;
|
|
59
62
|
}
|
|
60
63
|
if (actionStrings.length === 0) {
|
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,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;
|
|
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,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,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
: <<'END_COMMENT'
|
|
4
|
+
This script will download all the account authorization details which contains
|
|
5
|
+
inline policies and expand them then save them to a file.
|
|
6
|
+
END_COMMENT
|
|
7
|
+
|
|
8
|
+
aws iam get-account-authorization-details --output json | iam-expand --expand-service-asterisk --read-wait-time=20_000 > expanded-authorization-details.json
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
: <<'END_COMMENT'
|
|
4
|
+
This script will download all customer-managed policies in the account, expand them, and save them to files
|
|
5
|
+
in the `policies` directory. The file name will be the policy name with the path as a prefix.
|
|
6
|
+
END_COMMENT
|
|
7
|
+
|
|
8
|
+
mkdir -p policies
|
|
9
|
+
|
|
10
|
+
# List all managed policies that are attached to any entity
|
|
11
|
+
policies=$(aws iam list-policies --scope All --only-attached --query 'Policies[].{Arn:Arn,VersionId:DefaultVersionId,Path:Path,Name:PolicyName}' --output json)
|
|
12
|
+
|
|
13
|
+
# Loop through each policy to get the default version and save it
|
|
14
|
+
echo "$policies" | jq -c '.[]' | while read -r line; do
|
|
15
|
+
arn=$(echo "$line" | jq -r '.Arn')
|
|
16
|
+
version_id=$(echo "$line" | jq -r '.VersionId')
|
|
17
|
+
path=$(echo "$line" | jq -r '.Path' | tr '/' '_')
|
|
18
|
+
name=$(echo "$line" | jq -r '.Name')
|
|
19
|
+
|
|
20
|
+
file_name="policies/${path}${name}.json"
|
|
21
|
+
aws iam get-policy-version --policy-arn "$arn" --version-id "$version_id" --query 'PolicyVersion.Document' --output json 2>/dev/null | iam-expand --read-wait-time=10_000 > $file_name
|
|
22
|
+
done
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { convertOptions, parseStdIn } from "./cli_utils.js";
|
|
|
5
5
|
import { expandIamActions, ExpandIamActionsOptions } from "./expand.js";
|
|
6
6
|
|
|
7
7
|
const commandName = 'iam-expand'
|
|
8
|
+
const dataPackage = '@cloud-copilot/iam-data'
|
|
8
9
|
|
|
9
10
|
async function expandAndPrint(actionStrings: string[], options: Partial<ExpandIamActionsOptions>) {
|
|
10
11
|
try {
|
|
@@ -36,7 +37,7 @@ function printUsage() {
|
|
|
36
37
|
console.log(' --invalid-action-behavior=error: Throw an error if an invalid action is encountered')
|
|
37
38
|
console.log('CLI Behavior Options:')
|
|
38
39
|
console.log(' --show-data-version: Print the version of the iam-data package being used and exit')
|
|
39
|
-
console.log(' --read-wait-time: Millisenconds to wait for
|
|
40
|
+
console.log(' --read-wait-time: Millisenconds to wait for the first byte from stdin before timing out.')
|
|
40
41
|
console.log(' Example: --read-wait-time=10_000')
|
|
41
42
|
process.exit(1)
|
|
42
43
|
}
|
|
@@ -57,9 +58,12 @@ async function run() {
|
|
|
57
58
|
const options = convertOptions(optionStrings)
|
|
58
59
|
if(options.showDataVersion) {
|
|
59
60
|
const version = await iamDataVersion()
|
|
60
|
-
const updatedAt =
|
|
61
|
-
console.log(
|
|
62
|
-
console.log(`Data last updated: ${
|
|
61
|
+
const updatedAt =
|
|
62
|
+
console.log(`${dataPackage} version: ${version}`)
|
|
63
|
+
console.log(`Data last updated: ${await iamDataUpdatedAt()}`)
|
|
64
|
+
console.log(`Update with either:`)
|
|
65
|
+
console.log(` npm update ${dataPackage}`)
|
|
66
|
+
console.log(` npm update -g ${dataPackage}`)
|
|
63
67
|
return
|
|
64
68
|
}
|
|
65
69
|
|