@trustify-da/trustify-da-javascript-client 0.3.0-ea.7ed8d8c → 0.3.0-ea.848421d
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 +191 -11
- package/dist/package.json +13 -4
- package/dist/src/analysis.d.ts +16 -6
- package/dist/src/analysis.js +72 -68
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +241 -8
- package/dist/src/cyclone_dx_sbom.d.ts +17 -2
- package/dist/src/cyclone_dx_sbom.js +48 -8
- package/dist/src/index.d.ts +134 -1
- package/dist/src/index.js +342 -4
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +100 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +134 -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/utils.js +11 -2
- package/dist/src/provider.d.ts +15 -3
- package/dist/src/provider.js +29 -5
- package/dist/src/providers/base_java.d.ts +0 -9
- package/dist/src/providers/base_java.js +2 -38
- package/dist/src/providers/base_javascript.d.ts +29 -7
- package/dist/src/providers/base_javascript.js +129 -22
- package/dist/src/providers/base_pyproject.d.ts +153 -0
- package/dist/src/providers/base_pyproject.js +315 -0
- package/dist/src/providers/golang_gomodules.d.ts +28 -12
- package/dist/src/providers/golang_gomodules.js +161 -114
- 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 +25 -0
- package/dist/src/providers/java_gradle.js +126 -2
- package/dist/src/providers/java_maven.d.ts +16 -1
- package/dist/src/providers/java_maven.js +125 -5
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +8 -4
- package/dist/src/providers/python_pip.d.ts +11 -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 +144 -0
- package/dist/src/providers/python_poetry.d.ts +58 -0
- package/dist/src/providers/python_poetry.js +175 -0
- package/dist/src/providers/python_uv.d.ts +42 -0
- package/dist/src/providers/python_uv.js +149 -0
- package/dist/src/providers/requirements_parser.js +5 -8
- package/dist/src/providers/rust_cargo.d.ts +52 -0
- package/dist/src/providers/rust_cargo.js +614 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/sbom.d.ts +17 -2
- package/dist/src/sbom.js +16 -4
- package/dist/src/tools.d.ts +44 -0
- package/dist/src/tools.js +113 -0
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +14 -5
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether to skip failed manifests and continue (default), or fail on first SBOM/validation error.
|
|
3
|
+
* `opts.continueOnError` overrides; env `TRUSTIFY_DA_CONTINUE_ON_ERROR=false` disables continuation.
|
|
4
|
+
*
|
|
5
|
+
* @param {{ continueOnError?: boolean, TRUSTIFY_DA_CONTINUE_ON_ERROR?: string, [key: string]: unknown }} [opts={}]
|
|
6
|
+
* @returns {boolean} true = collect errors (default), false = fail-fast
|
|
7
|
+
*/
|
|
8
|
+
export function resolveContinueOnError(opts?: {
|
|
9
|
+
continueOnError?: boolean;
|
|
10
|
+
TRUSTIFY_DA_CONTINUE_ON_ERROR?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* When true, `stackAnalysisBatch` returns `{ analysis, metadata }` instead of the backend response only.
|
|
15
|
+
* `opts.batchMetadata` overrides; env `TRUSTIFY_DA_BATCH_METADATA=true` enables.
|
|
16
|
+
*
|
|
17
|
+
* @param {{ batchMetadata?: boolean, TRUSTIFY_DA_BATCH_METADATA?: string, [key: string]: unknown }} [opts={}]
|
|
18
|
+
* @returns {boolean}
|
|
19
|
+
*/
|
|
20
|
+
export function resolveBatchMetadata(opts?: {
|
|
21
|
+
batchMetadata?: boolean;
|
|
22
|
+
TRUSTIFY_DA_BATCH_METADATA?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getCustom } from './tools.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether to skip failed manifests and continue (default), or fail on first SBOM/validation error.
|
|
4
|
+
* `opts.continueOnError` overrides; env `TRUSTIFY_DA_CONTINUE_ON_ERROR=false` disables continuation.
|
|
5
|
+
*
|
|
6
|
+
* @param {{ continueOnError?: boolean, TRUSTIFY_DA_CONTINUE_ON_ERROR?: string, [key: string]: unknown }} [opts={}]
|
|
7
|
+
* @returns {boolean} true = collect errors (default), false = fail-fast
|
|
8
|
+
*/
|
|
9
|
+
export function resolveContinueOnError(opts = {}) {
|
|
10
|
+
if (typeof opts.continueOnError === 'boolean') {
|
|
11
|
+
return opts.continueOnError;
|
|
12
|
+
}
|
|
13
|
+
const v = getCustom('TRUSTIFY_DA_CONTINUE_ON_ERROR', null, opts);
|
|
14
|
+
if (v != null && String(v).trim() !== '') {
|
|
15
|
+
return String(v).toLowerCase() !== 'false';
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* When true, `stackAnalysisBatch` returns `{ analysis, metadata }` instead of the backend response only.
|
|
21
|
+
* `opts.batchMetadata` overrides; env `TRUSTIFY_DA_BATCH_METADATA=true` enables.
|
|
22
|
+
*
|
|
23
|
+
* @param {{ batchMetadata?: boolean, TRUSTIFY_DA_BATCH_METADATA?: string, [key: string]: unknown }} [opts={}]
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export function resolveBatchMetadata(opts = {}) {
|
|
27
|
+
if (typeof opts.batchMetadata === 'boolean') {
|
|
28
|
+
return opts.batchMetadata;
|
|
29
|
+
}
|
|
30
|
+
const v = getCustom('TRUSTIFY_DA_BATCH_METADATA', null, opts);
|
|
31
|
+
if (v != null && String(v).trim() !== '') {
|
|
32
|
+
return String(v).toLowerCase() === 'true';
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
package/dist/src/cli.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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 { getProjectLicense, getLicenseDetails } from './license/index.js';
|
|
7
|
+
import client, { selectTrustifyDABackend, generateSbom } from './index.js';
|
|
6
8
|
// command for component analysis take manifest type and content
|
|
7
9
|
const component = {
|
|
8
10
|
command: 'component </path/to/manifest>',
|
|
@@ -11,10 +13,18 @@ const component = {
|
|
|
11
13
|
desc: 'manifest path for analyzing',
|
|
12
14
|
type: 'string',
|
|
13
15
|
normalize: true,
|
|
16
|
+
}).options({
|
|
17
|
+
workspaceDir: {
|
|
18
|
+
alias: 'w',
|
|
19
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
20
|
+
type: 'string',
|
|
21
|
+
normalize: true,
|
|
22
|
+
}
|
|
14
23
|
}),
|
|
15
24
|
handler: async (args) => {
|
|
16
25
|
let manifestName = args['/path/to/manifest'];
|
|
17
|
-
|
|
26
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
27
|
+
let res = await client.componentAnalysis(manifestName, opts);
|
|
18
28
|
console.log(JSON.stringify(res, null, 2));
|
|
19
29
|
}
|
|
20
30
|
};
|
|
@@ -22,9 +32,8 @@ const validateToken = {
|
|
|
22
32
|
command: 'validate-token <token-provider> [--token-value thevalue]',
|
|
23
33
|
desc: 'Validates input token if authentic and authorized',
|
|
24
34
|
builder: yargs => yargs.positional('token-provider', {
|
|
25
|
-
desc: 'the token provider',
|
|
26
|
-
type: 'string'
|
|
27
|
-
choices: ['snyk', 'oss-index'],
|
|
35
|
+
desc: 'the token provider name',
|
|
36
|
+
type: 'string'
|
|
28
37
|
}).options({
|
|
29
38
|
tokenValue: {
|
|
30
39
|
alias: 'value',
|
|
@@ -37,7 +46,7 @@ const validateToken = {
|
|
|
37
46
|
let opts = {};
|
|
38
47
|
if (args['tokenValue'] !== undefined && args['tokenValue'].trim() !== "") {
|
|
39
48
|
let tokenValue = args['tokenValue'].trim();
|
|
40
|
-
opts[`
|
|
49
|
+
opts[`TRUSTIFY_DA_PROVIDER_${tokenProvider}_TOKEN`] = tokenValue;
|
|
41
50
|
}
|
|
42
51
|
let res = await client.validateToken(opts);
|
|
43
52
|
console.log(res);
|
|
@@ -117,15 +126,22 @@ const stack = {
|
|
|
117
126
|
desc: 'For JSON report, get only the \'summary\'',
|
|
118
127
|
type: 'boolean',
|
|
119
128
|
conflicts: 'html'
|
|
129
|
+
},
|
|
130
|
+
workspaceDir: {
|
|
131
|
+
alias: 'w',
|
|
132
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
133
|
+
type: 'string',
|
|
134
|
+
normalize: true,
|
|
120
135
|
}
|
|
121
136
|
}),
|
|
122
137
|
handler: async (args) => {
|
|
123
138
|
let manifest = args['/path/to/manifest'];
|
|
124
139
|
let html = args['html'];
|
|
125
140
|
let summary = args['summary'];
|
|
141
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
126
142
|
let theProvidersSummary = new Map();
|
|
127
143
|
let theProvidersObject = {};
|
|
128
|
-
let res = await client.stackAnalysis(manifest, html);
|
|
144
|
+
let res = await client.stackAnalysis(manifest, html, opts);
|
|
129
145
|
if (summary) {
|
|
130
146
|
for (let provider in res.providers) {
|
|
131
147
|
if (res.providers[provider].sources !== undefined) {
|
|
@@ -143,13 +159,230 @@ const stack = {
|
|
|
143
159
|
console.log(html ? res : JSON.stringify(!html && summary ? theProvidersObject : res, null, 2));
|
|
144
160
|
}
|
|
145
161
|
};
|
|
162
|
+
// command for batch stack analysis (workspace)
|
|
163
|
+
const stackBatch = {
|
|
164
|
+
command: 'stack-batch </path/to/workspace-root> [--html|--summary] [--concurrency <n>] [--ignore <pattern>...] [--metadata] [--fail-fast]',
|
|
165
|
+
desc: 'produce stack report for all packages/crates in a workspace (Cargo or JS/TS)',
|
|
166
|
+
builder: yargs => yargs.positional('/path/to/workspace-root', {
|
|
167
|
+
desc: 'workspace root directory (containing Cargo.toml+Cargo.lock or package.json+lock file)',
|
|
168
|
+
type: 'string',
|
|
169
|
+
normalize: true,
|
|
170
|
+
}).options({
|
|
171
|
+
html: {
|
|
172
|
+
alias: 'r',
|
|
173
|
+
desc: 'Get the report as HTML instead of JSON',
|
|
174
|
+
type: 'boolean',
|
|
175
|
+
conflicts: 'summary'
|
|
176
|
+
},
|
|
177
|
+
summary: {
|
|
178
|
+
alias: 's',
|
|
179
|
+
desc: 'For JSON report, get only the \'summary\' per package',
|
|
180
|
+
type: 'boolean',
|
|
181
|
+
conflicts: 'html'
|
|
182
|
+
},
|
|
183
|
+
concurrency: {
|
|
184
|
+
alias: 'c',
|
|
185
|
+
desc: 'Max parallel SBOM generations (default: 10, env: TRUSTIFY_DA_BATCH_CONCURRENCY)',
|
|
186
|
+
type: 'number',
|
|
187
|
+
},
|
|
188
|
+
ignore: {
|
|
189
|
+
alias: 'i',
|
|
190
|
+
desc: 'Extra glob patterns excluded from workspace discovery (merged with defaults). Repeat flag per pattern. Env: TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE (comma-separated)',
|
|
191
|
+
type: 'string',
|
|
192
|
+
array: true,
|
|
193
|
+
},
|
|
194
|
+
metadata: {
|
|
195
|
+
alias: 'm',
|
|
196
|
+
desc: 'Return { analysis, metadata } with per-manifest errors (env: TRUSTIFY_DA_BATCH_METADATA=true)',
|
|
197
|
+
type: 'boolean',
|
|
198
|
+
default: false,
|
|
199
|
+
},
|
|
200
|
+
failFast: {
|
|
201
|
+
desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
|
|
202
|
+
type: 'boolean',
|
|
203
|
+
default: false,
|
|
204
|
+
}
|
|
205
|
+
}),
|
|
206
|
+
handler: async (args) => {
|
|
207
|
+
const workspaceRoot = args['/path/to/workspace-root'];
|
|
208
|
+
const html = args['html'];
|
|
209
|
+
const summary = args['summary'];
|
|
210
|
+
const opts = {};
|
|
211
|
+
if (args.concurrency != null) {
|
|
212
|
+
opts.batchConcurrency = args.concurrency;
|
|
213
|
+
}
|
|
214
|
+
const extraIgnores = Array.isArray(args.ignore) ? args.ignore.filter(p => p != null && String(p).trim()) : [];
|
|
215
|
+
if (extraIgnores.length > 0) {
|
|
216
|
+
opts.workspaceDiscoveryIgnore = extraIgnores;
|
|
217
|
+
}
|
|
218
|
+
if (args.metadata) {
|
|
219
|
+
opts.batchMetadata = true;
|
|
220
|
+
}
|
|
221
|
+
if (args.failFast) {
|
|
222
|
+
opts.continueOnError = false;
|
|
223
|
+
}
|
|
224
|
+
let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
|
|
225
|
+
const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
|
|
226
|
+
if (summary && !html && typeof batchAnalysis === 'object') {
|
|
227
|
+
const summaries = {};
|
|
228
|
+
for (const [purl, report] of Object.entries(batchAnalysis)) {
|
|
229
|
+
if (report?.providers) {
|
|
230
|
+
for (const provider of Object.keys(report.providers)) {
|
|
231
|
+
const sources = report.providers[provider]?.sources;
|
|
232
|
+
if (sources) {
|
|
233
|
+
for (const [source, data] of Object.entries(sources)) {
|
|
234
|
+
if (data?.summary) {
|
|
235
|
+
if (!summaries[purl]) {
|
|
236
|
+
summaries[purl] = {};
|
|
237
|
+
}
|
|
238
|
+
if (!summaries[purl][provider]) {
|
|
239
|
+
summaries[purl][provider] = {};
|
|
240
|
+
}
|
|
241
|
+
summaries[purl][provider][source] = data.summary;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (res && typeof res === 'object' && res != null && 'metadata' in res) {
|
|
249
|
+
res = { analysis: summaries, metadata: res.metadata };
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
res = summaries;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (html) {
|
|
256
|
+
const htmlContent = res && typeof res === 'object' && 'analysis' in res ? res.analysis : res;
|
|
257
|
+
console.log(htmlContent);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.log(JSON.stringify(res, null, 2));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
// command for license checking
|
|
265
|
+
const license = {
|
|
266
|
+
command: 'license </path/to/manifest>',
|
|
267
|
+
desc: 'Display project license information from manifest and LICENSE file in JSON format',
|
|
268
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
269
|
+
desc: 'manifest path for license analysis',
|
|
270
|
+
type: 'string',
|
|
271
|
+
normalize: true,
|
|
272
|
+
}),
|
|
273
|
+
handler: async (args) => {
|
|
274
|
+
let manifestPath = args['/path/to/manifest'];
|
|
275
|
+
const opts = {}; // CLI options can be extended in the future
|
|
276
|
+
try {
|
|
277
|
+
selectTrustifyDABackend(opts);
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
console.error(JSON.stringify({ error: err.message }, null, 2));
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
let localResult;
|
|
284
|
+
try {
|
|
285
|
+
localResult = getProjectLicense(manifestPath);
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
console.error(JSON.stringify({ error: `Failed to read manifest: ${err.message}` }, null, 2));
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
const errors = [];
|
|
292
|
+
// Build LicenseInfo objects
|
|
293
|
+
const buildLicenseInfo = async (spdxId) => {
|
|
294
|
+
if (!spdxId) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const licenseInfo = { spdxId };
|
|
298
|
+
try {
|
|
299
|
+
const details = await getLicenseDetails(spdxId, opts);
|
|
300
|
+
if (details) {
|
|
301
|
+
// Check if backend recognized the license as valid
|
|
302
|
+
if (details.category === 'UNKNOWN') {
|
|
303
|
+
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/`);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
Object.assign(licenseInfo, details);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
errors.push(`No license details found for ${spdxId}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
errors.push(`Failed to fetch details for ${spdxId}: ${err.message}`);
|
|
315
|
+
}
|
|
316
|
+
return licenseInfo;
|
|
317
|
+
};
|
|
318
|
+
const output = {
|
|
319
|
+
manifestLicense: await buildLicenseInfo(localResult.fromManifest),
|
|
320
|
+
fileLicense: await buildLicenseInfo(localResult.fromFile),
|
|
321
|
+
mismatch: localResult.mismatch
|
|
322
|
+
};
|
|
323
|
+
if (errors.length > 0) {
|
|
324
|
+
output.errors = errors;
|
|
325
|
+
}
|
|
326
|
+
console.log(JSON.stringify(output, null, 2));
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const sbom = {
|
|
330
|
+
command: 'sbom </path/to/manifest> [--output]',
|
|
331
|
+
desc: 'generate a CycloneDX SBOM from a manifest file',
|
|
332
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
333
|
+
desc: 'manifest path for SBOM generation',
|
|
334
|
+
type: 'string',
|
|
335
|
+
normalize: true,
|
|
336
|
+
}).options({
|
|
337
|
+
output: {
|
|
338
|
+
alias: 'o',
|
|
339
|
+
desc: 'Write SBOM JSON to a file instead of stdout',
|
|
340
|
+
type: 'string',
|
|
341
|
+
normalize: true,
|
|
342
|
+
},
|
|
343
|
+
workspaceDir: {
|
|
344
|
+
alias: 'w',
|
|
345
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
346
|
+
type: 'string',
|
|
347
|
+
normalize: true,
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
handler: async (args) => {
|
|
351
|
+
let manifest = args['/path/to/manifest'];
|
|
352
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
353
|
+
let result;
|
|
354
|
+
try {
|
|
355
|
+
result = await generateSbom(manifest, opts);
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
console.error(JSON.stringify({ error: `Failed to generate SBOM: ${err.message}` }, null, 2));
|
|
359
|
+
process.exit(1);
|
|
360
|
+
}
|
|
361
|
+
const json = JSON.stringify(result, null, 2);
|
|
362
|
+
if (args.output) {
|
|
363
|
+
try {
|
|
364
|
+
fs.writeFileSync(args.output, json);
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
console.error(JSON.stringify({ error: `Failed to write output file: ${err.message}` }, null, 2));
|
|
368
|
+
process.exit(1);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
console.log(json);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
146
376
|
// parse and invoke the command
|
|
147
377
|
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}`)
|
|
378
|
+
.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}`)
|
|
149
379
|
.command(stack)
|
|
380
|
+
.command(stackBatch)
|
|
150
381
|
.command(component)
|
|
151
382
|
.command(image)
|
|
152
383
|
.command(validateToken)
|
|
384
|
+
.command(license)
|
|
385
|
+
.command(sbom)
|
|
153
386
|
.scriptName('')
|
|
154
387
|
.version(false)
|
|
155
388
|
.demandCommand(1)
|
|
@@ -6,9 +6,10 @@ export default class CycloneDxSbom {
|
|
|
6
6
|
sourceManifestForAuditTrail: any;
|
|
7
7
|
/**
|
|
8
8
|
* @param {PackageURL} root - add main/root component for sbom
|
|
9
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
9
10
|
* @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
|
|
10
11
|
*/
|
|
11
|
-
addRoot(root: PackageURL): CycloneDxSbom;
|
|
12
|
+
addRoot(root: PackageURL, licenses?: string | any[]): CycloneDxSbom;
|
|
12
13
|
/**
|
|
13
14
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
|
14
15
|
*/
|
|
@@ -17,9 +18,14 @@ export default class CycloneDxSbom {
|
|
|
17
18
|
* Adds a dependency relationship between two components in the SBOM
|
|
18
19
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
19
20
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
21
|
+
* @param {string} [scope] - Scope of the dependency
|
|
22
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
20
23
|
* @return {CycloneDxSbom} The updated SBOM
|
|
21
24
|
*/
|
|
22
|
-
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope
|
|
25
|
+
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
26
|
+
alg: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}>): CycloneDxSbom;
|
|
23
29
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
24
30
|
* @return String CycloneDx Sbom json object in a string format
|
|
25
31
|
*/
|
|
@@ -48,6 +54,8 @@ export default class CycloneDxSbom {
|
|
|
48
54
|
type: any;
|
|
49
55
|
version: any;
|
|
50
56
|
scope: any;
|
|
57
|
+
licenses?: any;
|
|
58
|
+
hashes?: any;
|
|
51
59
|
};
|
|
52
60
|
/**
|
|
53
61
|
* This method gets an array of dependencies to be ignored, and remove all of them from CycloneDx Sbom
|
|
@@ -68,6 +76,13 @@ export default class CycloneDxSbom {
|
|
|
68
76
|
* @return {boolean}
|
|
69
77
|
*/
|
|
70
78
|
checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
81
|
+
* @param {PackageURL} sourceRef - The source component
|
|
82
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
|
|
71
86
|
/** Removes the root component from the sbom
|
|
72
87
|
*/
|
|
73
88
|
removeRootComponent(): void;
|
|
@@ -5,10 +5,12 @@ import { PackageURL } from "packageurl-js";
|
|
|
5
5
|
* @param component {PackageURL}
|
|
6
6
|
* @param type type of package - application or library
|
|
7
7
|
* @param scope scope of the component - runtime or compile
|
|
8
|
-
* @
|
|
8
|
+
* @param licenses optional license string or array of licenses for the component
|
|
9
|
+
* @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
|
|
10
|
+
* @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
|
|
9
11
|
* @private
|
|
10
12
|
*/
|
|
11
|
-
function getComponent(component, type, scope) {
|
|
13
|
+
function getComponent(component, type, scope, licenses, hashes) {
|
|
12
14
|
let componentObject;
|
|
13
15
|
if (component instanceof PackageURL) {
|
|
14
16
|
if (component.namespace) {
|
|
@@ -36,6 +38,20 @@ function getComponent(component, type, scope) {
|
|
|
36
38
|
else {
|
|
37
39
|
componentObject = component;
|
|
38
40
|
}
|
|
41
|
+
// Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
|
|
42
|
+
if (licenses) {
|
|
43
|
+
const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
|
|
44
|
+
componentObject.licenses = licenseArray.map(lic => {
|
|
45
|
+
if (typeof lic === 'string') {
|
|
46
|
+
return { license: { id: lic } };
|
|
47
|
+
}
|
|
48
|
+
return lic;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Add hashes if provided (CycloneDX 1.4 format).
|
|
52
|
+
if (hashes && hashes.length > 0) {
|
|
53
|
+
componentObject.hashes = hashes;
|
|
54
|
+
}
|
|
39
55
|
return componentObject;
|
|
40
56
|
}
|
|
41
57
|
function createDependency(dependency) {
|
|
@@ -56,11 +72,12 @@ export default class CycloneDxSbom {
|
|
|
56
72
|
}
|
|
57
73
|
/**
|
|
58
74
|
* @param {PackageURL} root - add main/root component for sbom
|
|
75
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
59
76
|
* @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
|
|
60
77
|
*/
|
|
61
|
-
addRoot(root) {
|
|
78
|
+
addRoot(root, licenses) {
|
|
62
79
|
this.rootComponent =
|
|
63
|
-
getComponent(root, "application");
|
|
80
|
+
getComponent(root, "application", undefined, licenses);
|
|
64
81
|
this.components.push(this.rootComponent);
|
|
65
82
|
return this;
|
|
66
83
|
}
|
|
@@ -74,16 +91,24 @@ export default class CycloneDxSbom {
|
|
|
74
91
|
* Adds a dependency relationship between two components in the SBOM
|
|
75
92
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
76
93
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
94
|
+
* @param {string} [scope] - Scope of the dependency
|
|
95
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
77
96
|
* @return {CycloneDxSbom} The updated SBOM
|
|
78
97
|
*/
|
|
79
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
98
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
80
99
|
const sourcePurl = sourceRef.toString();
|
|
81
100
|
const targetPurl = targetRef.toString();
|
|
82
101
|
// Ensure both components exist in the components list
|
|
83
102
|
[sourceRef, targetRef].forEach((ref, index) => {
|
|
84
103
|
const purl = index === 0 ? sourcePurl : targetPurl;
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
const existingIndex = this.getComponentIndex(purl);
|
|
105
|
+
if (existingIndex < 0) {
|
|
106
|
+
const hashes = index === 1 ? targetHashes : undefined;
|
|
107
|
+
this.components.push(getComponent(ref, "library", scope, undefined, hashes));
|
|
108
|
+
}
|
|
109
|
+
else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
|
|
110
|
+
// Update hashes if the component was first seen without them (e.g. as a source)
|
|
111
|
+
this.components[existingIndex].hashes = targetHashes;
|
|
87
112
|
}
|
|
88
113
|
});
|
|
89
114
|
// Ensure source dependency exists
|
|
@@ -108,6 +133,7 @@ export default class CycloneDxSbom {
|
|
|
108
133
|
getAsJsonString(opts) {
|
|
109
134
|
let manifestType = opts["manifest-type"];
|
|
110
135
|
this.setSourceManifest(opts["source-manifest"]);
|
|
136
|
+
const rootPurl = this.rootComponent?.purl;
|
|
111
137
|
this.sbomObject = {
|
|
112
138
|
"bomFormat": "CycloneDX",
|
|
113
139
|
"specVersion": "1.4",
|
|
@@ -117,7 +143,7 @@ export default class CycloneDxSbom {
|
|
|
117
143
|
"component": this.rootComponent,
|
|
118
144
|
"properties": new Array()
|
|
119
145
|
},
|
|
120
|
-
"components": this.components,
|
|
146
|
+
"components": this.components.filter(c => c.purl !== rootPurl),
|
|
121
147
|
"dependencies": this.dependencies
|
|
122
148
|
};
|
|
123
149
|
if (this.rootComponent === undefined) {
|
|
@@ -229,6 +255,20 @@ export default class CycloneDxSbom {
|
|
|
229
255
|
return false;
|
|
230
256
|
}
|
|
231
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
260
|
+
* @param {PackageURL} sourceRef - The source component
|
|
261
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
262
|
+
* @return {boolean}
|
|
263
|
+
*/
|
|
264
|
+
checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
|
|
265
|
+
const sourcePurl = sourceRef.toString();
|
|
266
|
+
const depIndex = this.getDependencyIndex(sourcePurl);
|
|
267
|
+
if (depIndex < 0) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return this.dependencies[depIndex].dependsOn.some(dep => dep.startsWith(purlPrefix));
|
|
271
|
+
}
|
|
232
272
|
/** Removes the root component from the sbom
|
|
233
273
|
*/
|
|
234
274
|
removeRootComponent() {
|