@infrascan/cli 0.2.3 → 0.3.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/dist/index.mjs +57 -16
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -69,44 +69,63 @@ var GraphCmd = class extends CommandLineAction {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// src/commands/scan.ts
|
|
72
|
-
import {
|
|
73
|
-
import { resolve as
|
|
72
|
+
import { writeFileSync as writeFileSync2 } from "fs";
|
|
73
|
+
import { resolve as resolve3, join as join2 } from "path";
|
|
74
74
|
import {
|
|
75
75
|
CommandLineAction as CommandLineAction2
|
|
76
76
|
} from "@rushstack/ts-command-line";
|
|
77
77
|
import buildFsConnector2 from "@infrascan/fs-connector";
|
|
78
78
|
import {
|
|
79
79
|
fromIni,
|
|
80
|
+
fromNodeProviderChain,
|
|
80
81
|
fromTemporaryCredentials
|
|
81
82
|
} from "@aws-sdk/credential-providers";
|
|
83
|
+
import {
|
|
84
|
+
loadSharedConfigFiles
|
|
85
|
+
} from "@smithy/shared-ini-file-loader";
|
|
86
|
+
|
|
87
|
+
// src/config.ts
|
|
88
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
89
|
+
import { resolve as resolve2 } from "path";
|
|
90
|
+
import { env } from "process";
|
|
91
|
+
import { DEFAULT_PROFILE } from "@smithy/shared-ini-file-loader";
|
|
82
92
|
function getConfig(path) {
|
|
83
93
|
const resolvedConfigPath = resolve2(path);
|
|
84
94
|
return JSON.parse(readFileSync2(resolvedConfigPath, "utf8"));
|
|
85
95
|
}
|
|
96
|
+
function getDefaultRegion(parsedAwsConfig, currentProfile) {
|
|
97
|
+
const profile = currentProfile ?? env.AWS_PROFILE ?? DEFAULT_PROFILE;
|
|
98
|
+
return env.AWS_REGION ?? parsedAwsConfig?.[profile]?.region;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/commands/scan.ts
|
|
86
102
|
function writeScanMetadata(outputDirectory, metadata) {
|
|
87
103
|
writeFileSync2(
|
|
88
|
-
join2(
|
|
104
|
+
join2(resolve3(outputDirectory), "metadata.json"),
|
|
89
105
|
JSON.stringify(metadata),
|
|
90
106
|
"utf8"
|
|
91
107
|
);
|
|
92
108
|
}
|
|
93
|
-
function
|
|
109
|
+
function resolveCredentialProvider(profile, roleToAssume) {
|
|
94
110
|
if (profile) {
|
|
95
|
-
return fromIni({
|
|
96
|
-
profile
|
|
111
|
+
return (region) => fromIni({
|
|
112
|
+
profile,
|
|
113
|
+
clientConfig: { region }
|
|
97
114
|
});
|
|
98
115
|
}
|
|
99
116
|
if (roleToAssume) {
|
|
100
|
-
return fromTemporaryCredentials({
|
|
117
|
+
return (region) => fromTemporaryCredentials({
|
|
101
118
|
params: {
|
|
102
119
|
RoleArn: roleToAssume,
|
|
103
120
|
RoleSessionName: "infrascan-cli-scan"
|
|
104
|
-
}
|
|
121
|
+
},
|
|
122
|
+
clientConfig: { region }
|
|
105
123
|
});
|
|
106
124
|
}
|
|
107
|
-
|
|
108
|
-
"
|
|
125
|
+
console.log(
|
|
126
|
+
"No profile or role given, falling back to default provider chain."
|
|
109
127
|
);
|
|
128
|
+
return (region) => fromNodeProviderChain({ clientConfig: { region } });
|
|
110
129
|
}
|
|
111
130
|
var ScanCmd = class extends CommandLineAction2 {
|
|
112
131
|
constructor(infrascanClient) {
|
|
@@ -122,8 +141,7 @@ var ScanCmd = class extends CommandLineAction2 {
|
|
|
122
141
|
parameterLongName: "--config",
|
|
123
142
|
parameterShortName: "-c",
|
|
124
143
|
argumentName: "PATH_TO_CONFIG",
|
|
125
|
-
description: "Config to use for the scan."
|
|
126
|
-
defaultValue: "./config.json"
|
|
144
|
+
description: "Config to use for the scan."
|
|
127
145
|
});
|
|
128
146
|
this._outputDirectory = this.defineStringParameter({
|
|
129
147
|
parameterLongName: "--output",
|
|
@@ -132,20 +150,43 @@ var ScanCmd = class extends CommandLineAction2 {
|
|
|
132
150
|
description: "Location to save scan output to.",
|
|
133
151
|
defaultValue: "./state"
|
|
134
152
|
});
|
|
153
|
+
this._regions = this.defineStringListParameter({
|
|
154
|
+
parameterLongName: "--region",
|
|
155
|
+
argumentName: "REGION_TO_SCAN",
|
|
156
|
+
description: "The region to scan. This flag can be provided many times e.g. --region us-east-1 --region eu-west-1"
|
|
157
|
+
});
|
|
135
158
|
}
|
|
136
159
|
async onExecute() {
|
|
137
|
-
const
|
|
160
|
+
const awsConfig = await loadSharedConfigFiles().catch((err) => {
|
|
161
|
+
console.warn(
|
|
162
|
+
`Failed to load AWS config file, falling back to @infrascan/sdk defaults. (${err.message})`
|
|
163
|
+
);
|
|
164
|
+
return void 0;
|
|
165
|
+
});
|
|
166
|
+
const defaultRegionFromEnv = getDefaultRegion(awsConfig?.configFile);
|
|
167
|
+
const runtimeRegionsToScan = this._regions.values.length > 0 ? this._regions.values : void 0;
|
|
168
|
+
const scanConfig = this._config.value ? getConfig(this._config.value) : [
|
|
169
|
+
{
|
|
170
|
+
defaultRegion: defaultRegionFromEnv
|
|
171
|
+
}
|
|
172
|
+
];
|
|
138
173
|
const connector = buildFsConnector2(this._outputDirectory.value, {
|
|
139
174
|
createTargetDirectory: true
|
|
140
175
|
});
|
|
141
176
|
const metadata = [];
|
|
142
177
|
for (const accountConfig of scanConfig) {
|
|
143
|
-
const {
|
|
144
|
-
|
|
178
|
+
const {
|
|
179
|
+
profile,
|
|
180
|
+
roleToAssume,
|
|
181
|
+
regions,
|
|
182
|
+
defaultRegion: configDefaultRegion
|
|
183
|
+
} = accountConfig;
|
|
184
|
+
const credentials = resolveCredentialProvider(profile, roleToAssume);
|
|
185
|
+
const defaultRegion = configDefaultRegion ?? getDefaultRegion(awsConfig?.configFile, profile);
|
|
145
186
|
const accountMetadata = await this.infrascanClient.performScan(
|
|
146
187
|
credentials,
|
|
147
188
|
connector,
|
|
148
|
-
{ regions }
|
|
189
|
+
{ regions: runtimeRegionsToScan ?? regions, defaultRegion }
|
|
149
190
|
);
|
|
150
191
|
metadata.push(accountMetadata);
|
|
151
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infrascan/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Thin command line wrapper around the infrascan sdk",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -39,13 +39,15 @@
|
|
|
39
39
|
"@aws-sdk/credential-providers": "3.428.0",
|
|
40
40
|
"@infrascan/aws": "^0.3.0",
|
|
41
41
|
"@infrascan/fs-connector": "^0.2.2",
|
|
42
|
-
"@infrascan/sdk": "^0.
|
|
42
|
+
"@infrascan/sdk": "^0.3.1",
|
|
43
43
|
"@rushstack/ts-command-line": "^4.15.2",
|
|
44
|
+
"@smithy/shared-ini-file-loader": "^2.2.2",
|
|
44
45
|
"minimatch": "^6.1.6"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@aws-sdk/types": "3.428.0",
|
|
48
49
|
"@infrascan/shared-types": "^0.2.2",
|
|
50
|
+
"@smithy/types": "^2.4.0",
|
|
49
51
|
"ts-node": "^10.9.1",
|
|
50
52
|
"typescript": "^5.1.3"
|
|
51
53
|
}
|