@trustify-da/trustify-da-javascript-client 0.3.0-ea.7ed8d8c → 0.3.0-ea.7ee4047
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 +388 -20
- package/dist/package.json +39 -26
- package/dist/src/analysis.d.ts +58 -20
- package/dist/src/analysis.js +134 -78
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +427 -12
- package/dist/src/config.d.ts +120 -0
- package/dist/src/config.js +260 -0
- package/dist/src/cyclone_dx_sbom.d.ts +30 -2
- package/dist/src/cyclone_dx_sbom.js +95 -9
- package/dist/src/index.d.ts +154 -16
- package/dist/src/index.js +372 -36
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +106 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +137 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +16 -3
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +99 -12
- package/dist/src/providers/base_javascript.js +244 -28
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +30 -13
- package/dist/src/providers/golang_gomodules.js +219 -122
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +73 -0
- package/dist/src/providers/java_gradle.js +331 -23
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +44 -9
- package/dist/src/providers/java_maven.js +299 -13
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +14 -1
- package/dist/src/providers/javascript_pnpm.js +55 -5
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +28 -7
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +69 -8
- package/dist/src/providers/python_pip.d.ts +12 -0
- package/dist/src/providers/python_pip.js +18 -8
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +275 -0
- package/dist/src/providers/requirements_parser.js +6 -9
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +682 -0
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/remediate.d.ts +107 -0
- package/dist/src/remediate.js +244 -0
- package/dist/src/remediation.d.ts +81 -0
- package/dist/src/remediation.js +475 -0
- package/dist/src/remediation_report.d.ts +23 -0
- package/dist/src/remediation_report.js +180 -0
- package/dist/src/sbom.d.ts +28 -2
- package/dist/src/sbom.js +26 -4
- package/dist/src/tools.d.ts +53 -11
- package/dist/src/tools.js +147 -13
- package/dist/src/updaters/maven_updater.d.ts +58 -0
- package/dist/src/updaters/maven_updater.js +345 -0
- package/dist/src/updaters/toml_updater.d.ts +62 -0
- package/dist/src/updaters/toml_updater.js +276 -0
- package/dist/src/workspace.d.ts +71 -0
- package/dist/src/workspace.js +257 -0
- package/package.json +40 -27
package/dist/src/cli.js
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import yargs from 'yargs';
|
|
4
5
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
-
import
|
|
6
|
+
import { resolveConfig } from './config.js';
|
|
7
|
+
import { getProjectLicense, getLicenseDetails } from './license/index.js';
|
|
8
|
+
import { runRemediation } from './remediate.js';
|
|
9
|
+
import { generateReport } from './remediation_report.js';
|
|
10
|
+
import client, { selectTrustifyDABackend, generateSbom } from './index.js';
|
|
11
|
+
/**
|
|
12
|
+
* Builds a yargs middleware that loads `.trustify-da.yml` (discovered by walking
|
|
13
|
+
* up from the command's target path, or cwd when no path is available) and fills `--providers`, `--sources`, and
|
|
14
|
+
* `--group-by` with config file values when they were not supplied on the CLI or
|
|
15
|
+
* via environment variables. Precedence: CLI flag > env var > config file > default.
|
|
16
|
+
* @param {string} [pathKey] - positional argument holding the target path; defaults to the current working directory
|
|
17
|
+
* @param {{ groupBy?: boolean }} [options={}] - set `groupBy` when the command exposes `--group-by`
|
|
18
|
+
* @returns {(args: object) => object} yargs middleware
|
|
19
|
+
*/
|
|
20
|
+
function configMiddleware(pathKey, options = {}) {
|
|
21
|
+
return args => {
|
|
22
|
+
const startPath = pathKey === undefined ? process.cwd() : args[pathKey];
|
|
23
|
+
const envVars = options.groupBy
|
|
24
|
+
? process.env
|
|
25
|
+
: Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== 'TRUSTIFY_DA_GROUP_BY'));
|
|
26
|
+
const merged = resolveConfig(startPath, { backendUrl: args.backendUrl, providers: args.providers, sources: args.sources, groupBy: args['group-by'] }, envVars);
|
|
27
|
+
if (merged.backendUrlSource === 'file' && process.env.TRUSTIFY_DA_TOKEN) {
|
|
28
|
+
throw new Error('Refusing to send TRUSTIFY_DA_TOKEN to a backend selected by project configuration. Set --backend-url or TRUSTIFY_DA_BACKEND_URL to explicitly trust it.');
|
|
29
|
+
}
|
|
30
|
+
if (args.providers !== undefined || merged.providers.length) {
|
|
31
|
+
args.providers = merged.providers.join(',');
|
|
32
|
+
}
|
|
33
|
+
if (args.sources !== undefined || merged.sources.length) {
|
|
34
|
+
args.sources = merged.sources.join(',');
|
|
35
|
+
}
|
|
36
|
+
if (merged.backendUrl != null) {
|
|
37
|
+
args.backendUrl = merged.backendUrl;
|
|
38
|
+
}
|
|
39
|
+
if (options.groupBy) {
|
|
40
|
+
args['group-by'] = merged.groupBy;
|
|
41
|
+
}
|
|
42
|
+
return args;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
6
45
|
// command for component analysis take manifest type and content
|
|
7
46
|
const component = {
|
|
8
47
|
command: 'component </path/to/manifest>',
|
|
@@ -11,10 +50,39 @@ const component = {
|
|
|
11
50
|
desc: 'manifest path for analyzing',
|
|
12
51
|
type: 'string',
|
|
13
52
|
normalize: true,
|
|
14
|
-
})
|
|
53
|
+
}).options({
|
|
54
|
+
workspaceDir: {
|
|
55
|
+
alias: 'w',
|
|
56
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
57
|
+
type: 'string',
|
|
58
|
+
normalize: true,
|
|
59
|
+
},
|
|
60
|
+
backendUrl: {
|
|
61
|
+
desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
|
|
62
|
+
type: 'string',
|
|
63
|
+
},
|
|
64
|
+
providers: {
|
|
65
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
66
|
+
type: 'string',
|
|
67
|
+
},
|
|
68
|
+
sources: {
|
|
69
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
70
|
+
type: 'string',
|
|
71
|
+
}
|
|
72
|
+
}).middleware(configMiddleware('/path/to/manifest')),
|
|
15
73
|
handler: async (args) => {
|
|
16
74
|
let manifestName = args['/path/to/manifest'];
|
|
17
|
-
|
|
75
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
76
|
+
if (args.backendUrl !== undefined) {
|
|
77
|
+
opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
|
|
78
|
+
}
|
|
79
|
+
if (args.providers !== undefined) {
|
|
80
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
81
|
+
}
|
|
82
|
+
if (args.sources !== undefined) {
|
|
83
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
84
|
+
}
|
|
85
|
+
let res = await client.componentAnalysis(manifestName, opts);
|
|
18
86
|
console.log(JSON.stringify(res, null, 2));
|
|
19
87
|
}
|
|
20
88
|
};
|
|
@@ -22,9 +90,8 @@ const validateToken = {
|
|
|
22
90
|
command: 'validate-token <token-provider> [--token-value thevalue]',
|
|
23
91
|
desc: 'Validates input token if authentic and authorized',
|
|
24
92
|
builder: yargs => yargs.positional('token-provider', {
|
|
25
|
-
desc: 'the token provider',
|
|
26
|
-
type: 'string'
|
|
27
|
-
choices: ['snyk', 'oss-index'],
|
|
93
|
+
desc: 'the token provider name',
|
|
94
|
+
type: 'string'
|
|
28
95
|
}).options({
|
|
29
96
|
tokenValue: {
|
|
30
97
|
alias: 'value',
|
|
@@ -37,7 +104,7 @@ const validateToken = {
|
|
|
37
104
|
let opts = {};
|
|
38
105
|
if (args['tokenValue'] !== undefined && args['tokenValue'].trim() !== "") {
|
|
39
106
|
let tokenValue = args['tokenValue'].trim();
|
|
40
|
-
opts[`
|
|
107
|
+
opts[`TRUSTIFY_DA_PROVIDER_${tokenProvider}_TOKEN`] = tokenValue;
|
|
41
108
|
}
|
|
42
109
|
let res = await client.validateToken(opts);
|
|
43
110
|
console.log(res);
|
|
@@ -63,8 +130,20 @@ const image = {
|
|
|
63
130
|
desc: 'For JSON report, get only the \'summary\'',
|
|
64
131
|
type: 'boolean',
|
|
65
132
|
conflicts: 'html'
|
|
133
|
+
},
|
|
134
|
+
backendUrl: {
|
|
135
|
+
desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
|
|
136
|
+
type: 'string',
|
|
137
|
+
},
|
|
138
|
+
providers: {
|
|
139
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
140
|
+
type: 'string',
|
|
141
|
+
},
|
|
142
|
+
sources: {
|
|
143
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
144
|
+
type: 'string',
|
|
66
145
|
}
|
|
67
|
-
}),
|
|
146
|
+
}).middleware(configMiddleware()),
|
|
68
147
|
handler: async (args) => {
|
|
69
148
|
let imageRefs = args['image-refs'];
|
|
70
149
|
if (!Array.isArray(imageRefs)) {
|
|
@@ -72,7 +151,17 @@ const image = {
|
|
|
72
151
|
}
|
|
73
152
|
let html = args['html'];
|
|
74
153
|
let summary = args['summary'];
|
|
75
|
-
|
|
154
|
+
const opts = {};
|
|
155
|
+
if (args.backendUrl !== undefined) {
|
|
156
|
+
opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
|
|
157
|
+
}
|
|
158
|
+
if (args.providers !== undefined) {
|
|
159
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
160
|
+
}
|
|
161
|
+
if (args.sources !== undefined) {
|
|
162
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
163
|
+
}
|
|
164
|
+
let res = await client.imageAnalysis(imageRefs, html, opts);
|
|
76
165
|
if (summary && !html) {
|
|
77
166
|
let summaries = {};
|
|
78
167
|
for (let [imageRef, report] of Object.entries(res)) {
|
|
@@ -117,15 +206,43 @@ const stack = {
|
|
|
117
206
|
desc: 'For JSON report, get only the \'summary\'',
|
|
118
207
|
type: 'boolean',
|
|
119
208
|
conflicts: 'html'
|
|
209
|
+
},
|
|
210
|
+
workspaceDir: {
|
|
211
|
+
alias: 'w',
|
|
212
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
213
|
+
type: 'string',
|
|
214
|
+
normalize: true,
|
|
215
|
+
},
|
|
216
|
+
backendUrl: {
|
|
217
|
+
desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
|
|
218
|
+
type: 'string',
|
|
219
|
+
},
|
|
220
|
+
providers: {
|
|
221
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
222
|
+
type: 'string',
|
|
223
|
+
},
|
|
224
|
+
sources: {
|
|
225
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
226
|
+
type: 'string',
|
|
120
227
|
}
|
|
121
|
-
}),
|
|
228
|
+
}).middleware(configMiddleware('/path/to/manifest')),
|
|
122
229
|
handler: async (args) => {
|
|
123
230
|
let manifest = args['/path/to/manifest'];
|
|
124
231
|
let html = args['html'];
|
|
125
232
|
let summary = args['summary'];
|
|
233
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
234
|
+
if (args.backendUrl !== undefined) {
|
|
235
|
+
opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
|
|
236
|
+
}
|
|
237
|
+
if (args.providers !== undefined) {
|
|
238
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
239
|
+
}
|
|
240
|
+
if (args.sources !== undefined) {
|
|
241
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
242
|
+
}
|
|
126
243
|
let theProvidersSummary = new Map();
|
|
127
244
|
let theProvidersObject = {};
|
|
128
|
-
let res = await client.stackAnalysis(manifest, html);
|
|
245
|
+
let res = await client.stackAnalysis(manifest, html, opts);
|
|
129
246
|
if (summary) {
|
|
130
247
|
for (let provider in res.providers) {
|
|
131
248
|
if (res.providers[provider].sources !== undefined) {
|
|
@@ -143,13 +260,311 @@ const stack = {
|
|
|
143
260
|
console.log(html ? res : JSON.stringify(!html && summary ? theProvidersObject : res, null, 2));
|
|
144
261
|
}
|
|
145
262
|
};
|
|
263
|
+
// command for batch stack analysis (workspace)
|
|
264
|
+
const stackBatch = {
|
|
265
|
+
command: 'stack-batch </path/to/workspace-root> [--html|--summary] [--concurrency <n>] [--ignore <pattern>...] [--metadata] [--fail-fast]',
|
|
266
|
+
desc: 'produce stack report for all packages/crates in a workspace (Cargo or JS/TS)',
|
|
267
|
+
builder: yargs => yargs.positional('/path/to/workspace-root', {
|
|
268
|
+
desc: 'workspace root directory (containing Cargo.toml+Cargo.lock or package.json+lock file)',
|
|
269
|
+
type: 'string',
|
|
270
|
+
normalize: true,
|
|
271
|
+
}).options({
|
|
272
|
+
html: {
|
|
273
|
+
alias: 'r',
|
|
274
|
+
desc: 'Get the report as HTML instead of JSON',
|
|
275
|
+
type: 'boolean',
|
|
276
|
+
conflicts: 'summary'
|
|
277
|
+
},
|
|
278
|
+
summary: {
|
|
279
|
+
alias: 's',
|
|
280
|
+
desc: 'For JSON report, get only the \'summary\' per package',
|
|
281
|
+
type: 'boolean',
|
|
282
|
+
conflicts: 'html'
|
|
283
|
+
},
|
|
284
|
+
concurrency: {
|
|
285
|
+
alias: 'c',
|
|
286
|
+
desc: 'Max parallel SBOM generations (default: 10, env: TRUSTIFY_DA_BATCH_CONCURRENCY)',
|
|
287
|
+
type: 'number',
|
|
288
|
+
},
|
|
289
|
+
ignore: {
|
|
290
|
+
alias: 'i',
|
|
291
|
+
desc: 'Extra glob patterns excluded from workspace discovery (merged with defaults). Repeat flag per pattern. Env: TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE (comma-separated)',
|
|
292
|
+
type: 'string',
|
|
293
|
+
array: true,
|
|
294
|
+
},
|
|
295
|
+
metadata: {
|
|
296
|
+
alias: 'm',
|
|
297
|
+
desc: 'Return { analysis, metadata } with per-manifest errors (env: TRUSTIFY_DA_BATCH_METADATA=true)',
|
|
298
|
+
type: 'boolean',
|
|
299
|
+
default: false,
|
|
300
|
+
},
|
|
301
|
+
failFast: {
|
|
302
|
+
desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
|
|
303
|
+
type: 'boolean',
|
|
304
|
+
default: false,
|
|
305
|
+
},
|
|
306
|
+
backendUrl: {
|
|
307
|
+
desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
|
|
308
|
+
type: 'string',
|
|
309
|
+
},
|
|
310
|
+
providers: {
|
|
311
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
312
|
+
type: 'string',
|
|
313
|
+
},
|
|
314
|
+
sources: {
|
|
315
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
316
|
+
type: 'string',
|
|
317
|
+
}
|
|
318
|
+
}).middleware(configMiddleware('/path/to/workspace-root')),
|
|
319
|
+
handler: async (args) => {
|
|
320
|
+
const workspaceRoot = args['/path/to/workspace-root'];
|
|
321
|
+
const html = args['html'];
|
|
322
|
+
const summary = args['summary'];
|
|
323
|
+
const opts = {};
|
|
324
|
+
if (args.backendUrl !== undefined) {
|
|
325
|
+
opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
|
|
326
|
+
}
|
|
327
|
+
if (args.concurrency != null) {
|
|
328
|
+
opts.batchConcurrency = args.concurrency;
|
|
329
|
+
}
|
|
330
|
+
const extraIgnores = Array.isArray(args.ignore) ? args.ignore.filter(p => p != null && String(p).trim()) : [];
|
|
331
|
+
if (extraIgnores.length > 0) {
|
|
332
|
+
opts.workspaceDiscoveryIgnore = extraIgnores;
|
|
333
|
+
}
|
|
334
|
+
if (args.metadata) {
|
|
335
|
+
opts.batchMetadata = true;
|
|
336
|
+
}
|
|
337
|
+
if (args.failFast) {
|
|
338
|
+
opts.continueOnError = false;
|
|
339
|
+
}
|
|
340
|
+
if (args.providers !== undefined) {
|
|
341
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
342
|
+
}
|
|
343
|
+
if (args.sources !== undefined) {
|
|
344
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
345
|
+
}
|
|
346
|
+
let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
|
|
347
|
+
const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
|
|
348
|
+
if (summary && !html && typeof batchAnalysis === 'object') {
|
|
349
|
+
const summaries = {};
|
|
350
|
+
for (const [purl, report] of Object.entries(batchAnalysis)) {
|
|
351
|
+
if (report?.providers) {
|
|
352
|
+
for (const provider of Object.keys(report.providers)) {
|
|
353
|
+
const sources = report.providers[provider]?.sources;
|
|
354
|
+
if (sources) {
|
|
355
|
+
for (const [source, data] of Object.entries(sources)) {
|
|
356
|
+
if (data?.summary) {
|
|
357
|
+
if (!summaries[purl]) {
|
|
358
|
+
summaries[purl] = {};
|
|
359
|
+
}
|
|
360
|
+
if (!summaries[purl][provider]) {
|
|
361
|
+
summaries[purl][provider] = {};
|
|
362
|
+
}
|
|
363
|
+
summaries[purl][provider][source] = data.summary;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (res && typeof res === 'object' && res != null && 'metadata' in res) {
|
|
371
|
+
res = { analysis: summaries, metadata: res.metadata };
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
res = summaries;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (html) {
|
|
378
|
+
const htmlContent = res && typeof res === 'object' && 'analysis' in res ? res.analysis : res;
|
|
379
|
+
console.log(htmlContent);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
console.log(JSON.stringify(res, null, 2));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
// command for license checking
|
|
387
|
+
const license = {
|
|
388
|
+
command: 'license </path/to/manifest>',
|
|
389
|
+
desc: 'Display project license information from manifest and LICENSE file in JSON format',
|
|
390
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
391
|
+
desc: 'manifest path for license analysis',
|
|
392
|
+
type: 'string',
|
|
393
|
+
normalize: true,
|
|
394
|
+
}),
|
|
395
|
+
handler: async (args) => {
|
|
396
|
+
let manifestPath = args['/path/to/manifest'];
|
|
397
|
+
const opts = {}; // CLI options can be extended in the future
|
|
398
|
+
try {
|
|
399
|
+
selectTrustifyDABackend(opts);
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
console.error(JSON.stringify({ error: err.message }, null, 2));
|
|
403
|
+
process.exit(1);
|
|
404
|
+
}
|
|
405
|
+
let localResult;
|
|
406
|
+
try {
|
|
407
|
+
localResult = getProjectLicense(manifestPath);
|
|
408
|
+
}
|
|
409
|
+
catch (err) {
|
|
410
|
+
console.error(JSON.stringify({ error: `Failed to read manifest: ${err.message}` }, null, 2));
|
|
411
|
+
process.exit(1);
|
|
412
|
+
}
|
|
413
|
+
const errors = [];
|
|
414
|
+
// Build LicenseInfo objects
|
|
415
|
+
const buildLicenseInfo = async (spdxId) => {
|
|
416
|
+
if (!spdxId) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
const licenseInfo = { spdxId };
|
|
420
|
+
try {
|
|
421
|
+
const details = await getLicenseDetails(spdxId, opts);
|
|
422
|
+
if (details) {
|
|
423
|
+
// Check if backend recognized the license as valid
|
|
424
|
+
if (details.category === 'UNKNOWN') {
|
|
425
|
+
errors.push(`"${spdxId}" is not a valid SPDX license identifier. Please use a valid SPDX expression (e.g., "Apache-2.0", "MIT"). See https://spdx.org/licenses/`);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
Object.assign(licenseInfo, details);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
errors.push(`No license details found for ${spdxId}`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
errors.push(`Failed to fetch details for ${spdxId}: ${err.message}`);
|
|
437
|
+
}
|
|
438
|
+
return licenseInfo;
|
|
439
|
+
};
|
|
440
|
+
const output = {
|
|
441
|
+
manifestLicense: await buildLicenseInfo(localResult.fromManifest),
|
|
442
|
+
fileLicense: await buildLicenseInfo(localResult.fromFile),
|
|
443
|
+
mismatch: localResult.mismatch
|
|
444
|
+
};
|
|
445
|
+
if (errors.length > 0) {
|
|
446
|
+
output.errors = errors;
|
|
447
|
+
}
|
|
448
|
+
console.log(JSON.stringify(output, null, 2));
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
const sbom = {
|
|
452
|
+
command: 'sbom </path/to/manifest> [--output]',
|
|
453
|
+
desc: 'generate a CycloneDX SBOM from a manifest file',
|
|
454
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
455
|
+
desc: 'manifest path for SBOM generation',
|
|
456
|
+
type: 'string',
|
|
457
|
+
normalize: true,
|
|
458
|
+
}).options({
|
|
459
|
+
output: {
|
|
460
|
+
alias: 'o',
|
|
461
|
+
desc: 'Write SBOM JSON to a file instead of stdout',
|
|
462
|
+
type: 'string',
|
|
463
|
+
normalize: true,
|
|
464
|
+
},
|
|
465
|
+
workspaceDir: {
|
|
466
|
+
alias: 'w',
|
|
467
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
468
|
+
type: 'string',
|
|
469
|
+
normalize: true,
|
|
470
|
+
}
|
|
471
|
+
}),
|
|
472
|
+
handler: async (args) => {
|
|
473
|
+
let manifest = args['/path/to/manifest'];
|
|
474
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
475
|
+
let result;
|
|
476
|
+
try {
|
|
477
|
+
result = await generateSbom(manifest, opts);
|
|
478
|
+
}
|
|
479
|
+
catch (err) {
|
|
480
|
+
console.error(JSON.stringify({ error: `Failed to generate SBOM: ${err.message}` }, null, 2));
|
|
481
|
+
process.exit(1);
|
|
482
|
+
}
|
|
483
|
+
const json = JSON.stringify(result, null, 2);
|
|
484
|
+
if (args.output) {
|
|
485
|
+
try {
|
|
486
|
+
fs.writeFileSync(args.output, json);
|
|
487
|
+
}
|
|
488
|
+
catch (err) {
|
|
489
|
+
console.error(JSON.stringify({ error: `Failed to write output file: ${err.message}` }, null, 2));
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
console.log(json);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const remediate = {
|
|
499
|
+
command: 'remediate <path>',
|
|
500
|
+
desc: 'Scan and apply vulnerability remediations to manifest files',
|
|
501
|
+
builder: yargs => yargs.positional('path', {
|
|
502
|
+
desc: 'Path to manifest file or directory',
|
|
503
|
+
type: 'string',
|
|
504
|
+
normalize: true,
|
|
505
|
+
}).options({
|
|
506
|
+
'dry-run': {
|
|
507
|
+
alias: 'd',
|
|
508
|
+
type: 'boolean',
|
|
509
|
+
desc: 'Preview changes without modifying files',
|
|
510
|
+
},
|
|
511
|
+
providers: {
|
|
512
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
513
|
+
type: 'string',
|
|
514
|
+
},
|
|
515
|
+
sources: {
|
|
516
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
517
|
+
type: 'string',
|
|
518
|
+
},
|
|
519
|
+
'group-by': {
|
|
520
|
+
type: 'string',
|
|
521
|
+
choices: ['dependency', 'bundle'],
|
|
522
|
+
desc: 'Report grouping strategy (default: dependency)',
|
|
523
|
+
},
|
|
524
|
+
backendUrl: {
|
|
525
|
+
desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
|
|
526
|
+
type: 'string',
|
|
527
|
+
},
|
|
528
|
+
}).middleware(configMiddleware('path', { groupBy: true })),
|
|
529
|
+
handler: async (args) => {
|
|
530
|
+
try {
|
|
531
|
+
const result = await runRemediation(args.path, {
|
|
532
|
+
dryRun: args['dry-run'],
|
|
533
|
+
providers: args.providers,
|
|
534
|
+
sources: args.sources,
|
|
535
|
+
backendUrl: args.backendUrl,
|
|
536
|
+
});
|
|
537
|
+
if (result.remediations.length === 0 && result.manifests.length === 0) {
|
|
538
|
+
console.log('No supported manifest files found.');
|
|
539
|
+
process.exit(result.exitCode);
|
|
540
|
+
}
|
|
541
|
+
if (!args['dry-run'] && result.appliedFiles.length > 0) {
|
|
542
|
+
console.log(`Updated ${result.appliedFiles.length} file(s):`);
|
|
543
|
+
for (const file of result.appliedFiles) {
|
|
544
|
+
console.log(` ${file}`);
|
|
545
|
+
}
|
|
546
|
+
console.log('');
|
|
547
|
+
}
|
|
548
|
+
console.log(generateReport(result.remediations, { groupBy: args['group-by'], dryRun: args['dry-run'] }));
|
|
549
|
+
process.exit(result.exitCode);
|
|
550
|
+
}
|
|
551
|
+
catch (err) {
|
|
552
|
+
console.error(err.message);
|
|
553
|
+
process.exit(1);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
};
|
|
146
557
|
// parse and invoke the command
|
|
147
558
|
yargs(hideBin(process.argv))
|
|
148
|
-
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|image|validate-token}`)
|
|
559
|
+
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|stack-batch|image|validate-token|license|sbom|remediate}`)
|
|
149
560
|
.command(stack)
|
|
561
|
+
.command(stackBatch)
|
|
150
562
|
.command(component)
|
|
151
563
|
.command(image)
|
|
152
564
|
.command(validateToken)
|
|
565
|
+
.command(license)
|
|
566
|
+
.command(sbom)
|
|
567
|
+
.command(remediate)
|
|
153
568
|
.scriptName('')
|
|
154
569
|
.version(false)
|
|
155
570
|
.demandCommand(1)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discovers and parses `.trustify-da.yml` by walking up from `startPath`.
|
|
3
|
+
* A missing config file is not an error — an empty object is returned so callers
|
|
4
|
+
* can fall back to defaults.
|
|
5
|
+
* @param {string} [startPath] - manifest file or directory to start the search from
|
|
6
|
+
* @returns {FileConfig} the parsed config object, or `{}` when no file is found
|
|
7
|
+
* @throws {Error} when the config file exists but contains malformed YAML
|
|
8
|
+
*/
|
|
9
|
+
export function loadConfig(startPath?: string): FileConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Merges config sources with precedence: CLI flag > environment variable
|
|
12
|
+
* (`TRUSTIFY_DA_*`) > config file > hardcoded default. Providers and sources are
|
|
13
|
+
* normalized to arrays regardless of whether the source used a YAML array or a
|
|
14
|
+
* comma-separated string.
|
|
15
|
+
* @param {FileConfig} [fileConfig={}] - values parsed from `.trustify-da.yml`
|
|
16
|
+
* @param {{ providers?: string, sources?: string, groupBy?: string, backendUrl?: string }} [cliFlags={}]
|
|
17
|
+
* @param {{ [key: string]: string | undefined }} [envVars={}] - typically `process.env`
|
|
18
|
+
* @returns {ResolvedConfig} the resolved, typed config object
|
|
19
|
+
*/
|
|
20
|
+
export function mergeConfig(fileConfig?: FileConfig, cliFlags?: {
|
|
21
|
+
providers?: string;
|
|
22
|
+
sources?: string;
|
|
23
|
+
groupBy?: string;
|
|
24
|
+
backendUrl?: string;
|
|
25
|
+
}, envVars?: {
|
|
26
|
+
[key: string]: string | undefined;
|
|
27
|
+
}): ResolvedConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Loads and merges the project configuration for a target path.
|
|
30
|
+
* @param {string} [startPath] - manifest file or directory to start discovery from
|
|
31
|
+
* @param {{ providers?: string, sources?: string, groupBy?: string, backendUrl?: string }} [cliFlags={}] - explicit options
|
|
32
|
+
* @param {{ [key: string]: string | undefined }} [envVars={}] - typically `process.env`
|
|
33
|
+
* @returns {ResolvedConfig} the resolved, typed config object
|
|
34
|
+
*/
|
|
35
|
+
export function resolveConfig(startPath?: string, cliFlags?: {
|
|
36
|
+
providers?: string;
|
|
37
|
+
sources?: string;
|
|
38
|
+
groupBy?: string;
|
|
39
|
+
backendUrl?: string;
|
|
40
|
+
}, envVars?: {
|
|
41
|
+
[key: string]: string | undefined;
|
|
42
|
+
}): ResolvedConfig;
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {{
|
|
45
|
+
* 'group-by'?: 'dependency' | 'bundle',
|
|
46
|
+
* exclude?: string[],
|
|
47
|
+
* labels?: string[],
|
|
48
|
+
* 'branch-prefix'?: string,
|
|
49
|
+
* [key: string]: unknown
|
|
50
|
+
* }} RemediationConfig
|
|
51
|
+
*/
|
|
52
|
+
/** @typedef {{ critical?: number, high?: number, 'license-conflicts'?: number, [key: string]: unknown }} FailOnConfig */
|
|
53
|
+
/** @typedef {{ 'fail-on'?: FailOnConfig, [key: string]: unknown }} CheckConfig */
|
|
54
|
+
/** @typedef {{ format?: string, targets?: string[], [key: string]: unknown }} SbomConfig */
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {{
|
|
57
|
+
* 'backend-url'?: string,
|
|
58
|
+
* providers?: string[] | string,
|
|
59
|
+
* sources?: string[] | string,
|
|
60
|
+
* remediation?: RemediationConfig,
|
|
61
|
+
* check?: CheckConfig,
|
|
62
|
+
* sbom?: SbomConfig,
|
|
63
|
+
* [key: string]: unknown
|
|
64
|
+
* }} FileConfig
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {{
|
|
68
|
+
* backendUrl: string | null,
|
|
69
|
+
* backendUrlSource: 'cli' | 'environment' | 'file' | 'default',
|
|
70
|
+
* providers: string[],
|
|
71
|
+
* sources: string[],
|
|
72
|
+
* groupBy: string,
|
|
73
|
+
* remediation: object,
|
|
74
|
+
* check: object,
|
|
75
|
+
* sbom: object
|
|
76
|
+
* }} ResolvedConfig
|
|
77
|
+
*/
|
|
78
|
+
/** Config file names discovered by walking up the directory tree, in precedence order. */
|
|
79
|
+
export const CONFIG_FILENAMES: string[];
|
|
80
|
+
export type RemediationConfig = {
|
|
81
|
+
"group-by"?: "dependency" | "bundle";
|
|
82
|
+
exclude?: string[];
|
|
83
|
+
labels?: string[];
|
|
84
|
+
"branch-prefix"?: string;
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
};
|
|
87
|
+
export type FailOnConfig = {
|
|
88
|
+
critical?: number;
|
|
89
|
+
high?: number;
|
|
90
|
+
"license-conflicts"?: number;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
};
|
|
93
|
+
export type CheckConfig = {
|
|
94
|
+
"fail-on"?: FailOnConfig;
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
};
|
|
97
|
+
export type SbomConfig = {
|
|
98
|
+
format?: string;
|
|
99
|
+
targets?: string[];
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
};
|
|
102
|
+
export type FileConfig = {
|
|
103
|
+
"backend-url"?: string;
|
|
104
|
+
providers?: string[] | string;
|
|
105
|
+
sources?: string[] | string;
|
|
106
|
+
remediation?: RemediationConfig;
|
|
107
|
+
check?: CheckConfig;
|
|
108
|
+
sbom?: SbomConfig;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
};
|
|
111
|
+
export type ResolvedConfig = {
|
|
112
|
+
backendUrl: string | null;
|
|
113
|
+
backendUrlSource: "cli" | "environment" | "file" | "default";
|
|
114
|
+
providers: string[];
|
|
115
|
+
sources: string[];
|
|
116
|
+
groupBy: string;
|
|
117
|
+
remediation: object;
|
|
118
|
+
check: object;
|
|
119
|
+
sbom: object;
|
|
120
|
+
};
|