@infrascan/cli 0.5.0 → 0.7.0
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 +24 -2
- package/dist/commands/graph.mjs +12 -3
- package/dist/commands/render.mjs +4 -1
- package/dist/commands/scan.mjs +4 -0
- package/dist/index.mjs +20 -4
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The Infrascan CLI is a thin wrapper around the Infrascan SDK which outputs its state to the local file system.
|
|
4
4
|
|
|
5
|
-
The Infrascan CLI exposes two commands: scan and graph. A scan will read in all of the information that it can from your AWS account, and write it to your local file system. You can then run the graph command to take that scan output and convert it into an infrastructure diagram.
|
|
5
|
+
The Infrascan CLI exposes two commands: scan and graph. A scan will read in all of the information that it can from your AWS account, and write it to your local file system. You can then run the graph command to take that scan output and convert it into an infrastructure diagram.
|
|
6
6
|
|
|
7
7
|
## Prerequisite
|
|
8
8
|
|
|
@@ -10,6 +10,28 @@ Infrascan requires read access to your AWS account to generate its graphs. Read
|
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
13
|
+
### Fastest Possible
|
|
14
|
+
|
|
15
|
+
Run a scan:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
infrascan scan --region us-east-1
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Generate a graph
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
infrascan graph
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
View it in browser:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
infrascan render --browser
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or paste it into [render.infrascan.io](https://render.infrascan.io)
|
|
34
|
+
|
|
13
35
|
### Scan
|
|
14
36
|
|
|
15
37
|
To run a scan command, we first need to create the config file. The config file will tell the CLI which regions to scan, and how to authenticate with AWS. The config file format is:
|
|
@@ -45,4 +67,4 @@ infrascan graph --input ./state
|
|
|
45
67
|
|
|
46
68
|
The graph output will be saved to a `graph.json` file in the state directory. The graph file contains an array of JSON objects representing the Nodes and Edges of the graph. This is formatted to be used with [cytoscape](https://js.cytoscape.org/), however it can be translated into any graphing library (Note: the graphs usually require on being able to create parent-child relationships)
|
|
47
69
|
|
|
48
|
-
You can view your graph by pasting the contents of your `graph.json` file into: [render.infrascan.io](https://render.infrascan.io).
|
|
70
|
+
You can view your graph by pasting the contents of your `graph.json` file into: [render.infrascan.io](https://render.infrascan.io).
|
package/dist/commands/graph.mjs
CHANGED
|
@@ -5,9 +5,8 @@ import {
|
|
|
5
5
|
CommandLineAction
|
|
6
6
|
} from "@rushstack/ts-command-line";
|
|
7
7
|
import buildFsConnector from "@infrascan/fs-connector";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
} from "@infrascan/cytoscape-serializer";
|
|
8
|
+
import { serializeGraph as serializeVisualGraph } from "@infrascan/cytoscape-serializer";
|
|
9
|
+
import { serializeGraph as serializeInformationalGraph } from "@infrascan/informational-serializer";
|
|
11
10
|
function readScanMetadata(outputPath) {
|
|
12
11
|
const scanMetadata = readFileSync(
|
|
13
12
|
join(resolve(outputPath), "metadata.json"),
|
|
@@ -22,6 +21,9 @@ function writeGraphOutput(outputPath, graphState) {
|
|
|
22
21
|
);
|
|
23
22
|
}
|
|
24
23
|
var GraphCmd = class extends CommandLineAction {
|
|
24
|
+
_outputDirectory;
|
|
25
|
+
_serializer;
|
|
26
|
+
infrascanClient;
|
|
25
27
|
constructor(infrascanClient) {
|
|
26
28
|
super({
|
|
27
29
|
actionName: "graph",
|
|
@@ -38,6 +40,12 @@ var GraphCmd = class extends CommandLineAction {
|
|
|
38
40
|
description: "Location to read scan state from. This should be the same as the directory given to the scan command.",
|
|
39
41
|
defaultValue: "./state"
|
|
40
42
|
});
|
|
43
|
+
this._serializer = this.defineChoiceParameter({
|
|
44
|
+
required: false,
|
|
45
|
+
parameterLongName: "--serializer",
|
|
46
|
+
description: "Choice of graph serializer. Visual will output a cytoscape compatible graph intended for visual consumption. Informational will preserve the maximum amount of structured data to explore in other formats.",
|
|
47
|
+
alternatives: ["visual", "informational"]
|
|
48
|
+
});
|
|
41
49
|
}
|
|
42
50
|
async onExecute() {
|
|
43
51
|
const scanMetadata = readScanMetadata(
|
|
@@ -52,6 +60,7 @@ var GraphCmd = class extends CommandLineAction {
|
|
|
52
60
|
nServicesScanned += 1;
|
|
53
61
|
}
|
|
54
62
|
});
|
|
63
|
+
const serializeGraph = this._serializer.value === "informational" ? serializeInformationalGraph : serializeVisualGraph;
|
|
55
64
|
const graphData = await this.infrascanClient.generateGraph(scanMetadata, connector, serializeGraph);
|
|
56
65
|
console.log(
|
|
57
66
|
`Graph Complete. Found resources in ${nServicesScanned} services.`
|
package/dist/commands/render.mjs
CHANGED
|
@@ -68,7 +68,10 @@ var RenderCmd = class extends CommandLineAction {
|
|
|
68
68
|
try {
|
|
69
69
|
return readFileSync(this.#graphPath.value, "utf8");
|
|
70
70
|
} catch (err) {
|
|
71
|
-
|
|
71
|
+
const errMessage = err instanceof Error && "message" in err ? err.message : "unknown error occurred";
|
|
72
|
+
console.error(
|
|
73
|
+
`Failed to read graph data from: ${this.#graphPath.value}. ${errMessage}`
|
|
74
|
+
);
|
|
72
75
|
return null;
|
|
73
76
|
}
|
|
74
77
|
}
|
package/dist/commands/scan.mjs
CHANGED
|
@@ -56,6 +56,10 @@ function resolveCredentialProvider(profile, roleToAssume) {
|
|
|
56
56
|
return (region) => fromNodeProviderChain({ clientConfig: { region } });
|
|
57
57
|
}
|
|
58
58
|
var ScanCmd = class extends CommandLineAction {
|
|
59
|
+
_config;
|
|
60
|
+
infrascanClient;
|
|
61
|
+
_outputDirectory;
|
|
62
|
+
_regions;
|
|
59
63
|
constructor(infrascanClient) {
|
|
60
64
|
super({
|
|
61
65
|
actionName: "scan",
|
package/dist/index.mjs
CHANGED
|
@@ -12,9 +12,8 @@ import {
|
|
|
12
12
|
CommandLineAction
|
|
13
13
|
} from "@rushstack/ts-command-line";
|
|
14
14
|
import buildFsConnector from "@infrascan/fs-connector";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
} from "@infrascan/cytoscape-serializer";
|
|
15
|
+
import { serializeGraph as serializeVisualGraph } from "@infrascan/cytoscape-serializer";
|
|
16
|
+
import { serializeGraph as serializeInformationalGraph } from "@infrascan/informational-serializer";
|
|
18
17
|
function readScanMetadata(outputPath) {
|
|
19
18
|
const scanMetadata = readFileSync(
|
|
20
19
|
join(resolve(outputPath), "metadata.json"),
|
|
@@ -29,6 +28,9 @@ function writeGraphOutput(outputPath, graphState) {
|
|
|
29
28
|
);
|
|
30
29
|
}
|
|
31
30
|
var GraphCmd = class extends CommandLineAction {
|
|
31
|
+
_outputDirectory;
|
|
32
|
+
_serializer;
|
|
33
|
+
infrascanClient;
|
|
32
34
|
constructor(infrascanClient) {
|
|
33
35
|
super({
|
|
34
36
|
actionName: "graph",
|
|
@@ -45,6 +47,12 @@ var GraphCmd = class extends CommandLineAction {
|
|
|
45
47
|
description: "Location to read scan state from. This should be the same as the directory given to the scan command.",
|
|
46
48
|
defaultValue: "./state"
|
|
47
49
|
});
|
|
50
|
+
this._serializer = this.defineChoiceParameter({
|
|
51
|
+
required: false,
|
|
52
|
+
parameterLongName: "--serializer",
|
|
53
|
+
description: "Choice of graph serializer. Visual will output a cytoscape compatible graph intended for visual consumption. Informational will preserve the maximum amount of structured data to explore in other formats.",
|
|
54
|
+
alternatives: ["visual", "informational"]
|
|
55
|
+
});
|
|
48
56
|
}
|
|
49
57
|
async onExecute() {
|
|
50
58
|
const scanMetadata = readScanMetadata(
|
|
@@ -59,6 +67,7 @@ var GraphCmd = class extends CommandLineAction {
|
|
|
59
67
|
nServicesScanned += 1;
|
|
60
68
|
}
|
|
61
69
|
});
|
|
70
|
+
const serializeGraph = this._serializer.value === "informational" ? serializeInformationalGraph : serializeVisualGraph;
|
|
62
71
|
const graphData = await this.infrascanClient.generateGraph(scanMetadata, connector, serializeGraph);
|
|
63
72
|
console.log(
|
|
64
73
|
`Graph Complete. Found resources in ${nServicesScanned} services.`
|
|
@@ -137,7 +146,10 @@ var RenderCmd = class extends CommandLineAction2 {
|
|
|
137
146
|
try {
|
|
138
147
|
return readFileSync2(this.#graphPath.value, "utf8");
|
|
139
148
|
} catch (err) {
|
|
140
|
-
|
|
149
|
+
const errMessage = err instanceof Error && "message" in err ? err.message : "unknown error occurred";
|
|
150
|
+
console.error(
|
|
151
|
+
`Failed to read graph data from: ${this.#graphPath.value}. ${errMessage}`
|
|
152
|
+
);
|
|
141
153
|
return null;
|
|
142
154
|
}
|
|
143
155
|
}
|
|
@@ -201,6 +213,10 @@ function resolveCredentialProvider(profile, roleToAssume) {
|
|
|
201
213
|
return (region) => fromNodeProviderChain({ clientConfig: { region } });
|
|
202
214
|
}
|
|
203
215
|
var ScanCmd = class extends CommandLineAction3 {
|
|
216
|
+
_config;
|
|
217
|
+
infrascanClient;
|
|
218
|
+
_outputDirectory;
|
|
219
|
+
_regions;
|
|
204
220
|
constructor(infrascanClient) {
|
|
205
221
|
super({
|
|
206
222
|
actionName: "scan",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infrascan/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Thin command line wrapper around the infrascan sdk",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
"license": "MPL-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@aws-sdk/credential-providers": "3.624.0",
|
|
29
|
-
"@infrascan/aws": "^0.4
|
|
30
|
-
"@infrascan/cytoscape-serializer": "^0.
|
|
31
|
-
"@infrascan/fs-connector": "^0.
|
|
32
|
-
"@infrascan/
|
|
29
|
+
"@infrascan/aws": "^0.5.4",
|
|
30
|
+
"@infrascan/cytoscape-serializer": "^0.3.4",
|
|
31
|
+
"@infrascan/fs-connector": "^0.3.0",
|
|
32
|
+
"@infrascan/informational-serializer": "^0.2.0",
|
|
33
|
+
"@infrascan/sdk": "^0.6.0",
|
|
33
34
|
"@rushstack/ts-command-line": "^4.15.2",
|
|
34
35
|
"@smithy/shared-ini-file-loader": "^2.2.2",
|
|
35
36
|
"ejs": "^3.1.9",
|
|
@@ -38,10 +39,10 @@
|
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@aws-sdk/types": "3.609.0",
|
|
41
|
-
"@infrascan/shared-types": "^0.
|
|
42
|
+
"@infrascan/shared-types": "^0.7.0",
|
|
42
43
|
"@smithy/types": "^2.4.0",
|
|
43
44
|
"@types/ejs": "^3.1.5",
|
|
44
45
|
"ts-node": "^10.9.1",
|
|
45
|
-
"typescript": "^5.
|
|
46
|
+
"typescript": "^5.4.5"
|
|
46
47
|
}
|
|
47
48
|
}
|