@trustify-da/trustify-da-javascript-client 0.3.0-ea.d349baa → 0.3.0-ea.d71f957
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 +136 -10
- package/dist/package.json +18 -5
- package/dist/src/analysis.d.ts +16 -0
- package/dist/src/analysis.js +71 -78
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +192 -8
- package/dist/src/cyclone_dx_sbom.d.ts +10 -1
- package/dist/src/cyclone_dx_sbom.js +32 -5
- package/dist/src/index.d.ts +67 -4
- package/dist/src/index.js +270 -7
- 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/provider.d.ts +17 -5
- package/dist/src/provider.js +23 -5
- package/dist/src/providers/base_javascript.d.ts +29 -7
- package/dist/src/providers/base_javascript.js +129 -22
- package/dist/src/providers/golang_gomodules.d.ts +19 -12
- package/dist/src/providers/golang_gomodules.js +112 -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 +6 -0
- package/dist/src/providers/java_gradle.js +12 -2
- package/dist/src/providers/java_maven.d.ts +8 -1
- package/dist/src/providers/java_maven.js +32 -4
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +2 -2
- 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 +82 -3
- package/dist/src/providers/python_controller.d.ts +5 -2
- package/dist/src/providers/python_controller.js +56 -58
- package/dist/src/providers/python_pip.d.ts +11 -4
- package/dist/src/providers/python_pip.js +47 -54
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- 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 +10 -1
- package/dist/src/sbom.js +12 -2
- package/dist/src/tools.d.ts +18 -0
- package/dist/src/tools.js +56 -1
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +19 -6
package/README.md
CHANGED
|
@@ -32,6 +32,11 @@ let stackAnalysis = await client.stackAnalysis('/path/to/pom.xml')
|
|
|
32
32
|
let stackAnalysisHtml = await client.stackAnalysis('/path/to/pom.xml', true)
|
|
33
33
|
// Get component analysis in JSON format
|
|
34
34
|
let componentAnalysis = await client.componentAnalysis('/path/to/pom.xml')
|
|
35
|
+
// For monorepos, pass workspace root so the client finds the lock file
|
|
36
|
+
let monorepoOpts = { workspaceDir: '/path/to/workspace-root' }
|
|
37
|
+
let stackAnalysisMonorepo = await client.stackAnalysis('/path/to/package.json', false, monorepoOpts)
|
|
38
|
+
// Batch analysis for entire workspace (Cargo or JS/TS); optional parallel SBOM generation
|
|
39
|
+
let batchReport = await client.stackAnalysisBatch('/path/to/workspace-root', false, { batchConcurrency: 10 })
|
|
35
40
|
// Get image analysis in JSON format
|
|
36
41
|
let imageAnalysis = await client.imageAnalysis(['docker.io/library/node:18'])
|
|
37
42
|
// Get image analysis in HTML format (string)
|
|
@@ -43,6 +48,21 @@ let imageAnalysisWithArch = await client.imageAnalysis(['httpd:2.4.49^^amd64'])
|
|
|
43
48
|
```
|
|
44
49
|
</li>
|
|
45
50
|
</ul>
|
|
51
|
+
|
|
52
|
+
<h3>License Detection</h3>
|
|
53
|
+
<p>
|
|
54
|
+
The client automatically detects your project's license with intelligent fallback:
|
|
55
|
+
</p>
|
|
56
|
+
<ul>
|
|
57
|
+
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript, Rust Cargo), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>, <code>Cargo.toml</code>)</li>
|
|
58
|
+
<li><strong>LICENSE file fallback:</strong> If no license in manifest, or for ecosystems without license support (Gradle, Go, Python), automatically reads from <code>LICENSE</code>, <code>LICENSE.md</code>, or <code>LICENSE.txt</code></li>
|
|
59
|
+
<li><strong>SBOM integration:</strong> Detected licenses are included in generated SBOMs for all ecosystems</li>
|
|
60
|
+
<li><strong>SPDX support:</strong> Automatically detects common licenses (Apache-2.0, MIT, GPL, BSD) from LICENSE file content</li>
|
|
61
|
+
</ul>
|
|
62
|
+
<p>
|
|
63
|
+
See <a href="./docs/license-resolution-and-compliance.md">License Resolution and Compliance</a> for detailed documentation.
|
|
64
|
+
</p>
|
|
65
|
+
|
|
46
66
|
<ul>
|
|
47
67
|
<li>
|
|
48
68
|
Use as ESM Module from Common-JS module
|
|
@@ -83,12 +103,14 @@ Use as CLI Script
|
|
|
83
103
|
```shell
|
|
84
104
|
$ npx @trustify-da/trustify-da-javascript-client help
|
|
85
105
|
|
|
86
|
-
Usage: trustify-da-javascript-client {component|stack|image|validate-token}
|
|
106
|
+
Usage: trustify-da-javascript-client {component|stack|image|validate-token|license}
|
|
87
107
|
|
|
88
108
|
Commands:
|
|
89
|
-
trustify-da-javascript-client stack </path/to/manifest> [--html|--summary] produce stack report for manifest path
|
|
90
|
-
trustify-da-javascript-client
|
|
109
|
+
trustify-da-javascript-client stack </path/to/manifest> [--workspace-dir <path>] [--html|--summary] produce stack report for manifest path
|
|
110
|
+
trustify-da-javascript-client stack-batch </path/to/workspace-root> [--html|--summary] produce stack report for all packages/crates in workspace
|
|
111
|
+
trustify-da-javascript-client component <path/to/manifest> [--workspace-dir <path>] produce component report for a manifest type and content
|
|
91
112
|
trustify-da-javascript-client image <image-refs..> [--html|--summary] produce image analysis report for OCI image references
|
|
113
|
+
trustify-da-javascript-client license </path/to/manifest> display project license information from manifest and LICENSE file in JSON format
|
|
92
114
|
|
|
93
115
|
Options:
|
|
94
116
|
--help Show help [boolean]
|
|
@@ -105,9 +127,21 @@ $ npx @trustify-da/trustify-da-javascript-client stack /path/to/pom.xml --summar
|
|
|
105
127
|
# get stack analysis in html format format
|
|
106
128
|
$ npx @trustify-da/trustify-da-javascript-client stack /path/to/pom.xml --html
|
|
107
129
|
|
|
130
|
+
# get stack analysis for monorepo (lock file at workspace root)
|
|
131
|
+
$ npx @trustify-da/trustify-da-javascript-client stack /path/to/package.json --workspace-dir /path/to/workspace-root
|
|
132
|
+
|
|
108
133
|
# get component analysis
|
|
109
134
|
$ npx @trustify-da/trustify-da-javascript-client component /path/to/pom.xml
|
|
110
135
|
|
|
136
|
+
# get component analysis for monorepo
|
|
137
|
+
$ npx @trustify-da/trustify-da-javascript-client component /path/to/package.json -w /path/to/workspace-root
|
|
138
|
+
|
|
139
|
+
# batch stack analysis for entire workspace (Cargo or JS/TS)
|
|
140
|
+
$ npx @trustify-da/trustify-da-javascript-client stack-batch /path/to/workspace-root
|
|
141
|
+
|
|
142
|
+
# optional: extra discovery excludes (merged with defaults); repeat --ignore or use TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE
|
|
143
|
+
$ npx @trustify-da/trustify-da-javascript-client stack-batch /path/to/workspace-root --ignore '**/fixtures/**'
|
|
144
|
+
|
|
111
145
|
# get image analysis in json format
|
|
112
146
|
$ npx @trustify-da/trustify-da-javascript-client image docker.io/library/node:18
|
|
113
147
|
|
|
@@ -123,6 +157,9 @@ $ npx @trustify-da/trustify-da-javascript-client image docker.io/library/node:18
|
|
|
123
157
|
|
|
124
158
|
# specify architecture using ^^ notation (e.g., httpd:2.4.49^^amd64)
|
|
125
159
|
$ npx @trustify-da/trustify-da-javascript-client image httpd:2.4.49^^amd64
|
|
160
|
+
|
|
161
|
+
# get project license information
|
|
162
|
+
$ npx @trustify-da/trustify-da-javascript-client license /path/to/package.json
|
|
126
163
|
```
|
|
127
164
|
</li>
|
|
128
165
|
|
|
@@ -143,9 +180,21 @@ $ trustify-da-javascript-client stack /path/to/pom.xml --summary
|
|
|
143
180
|
# get stack analysis in html format format
|
|
144
181
|
$ trustify-da-javascript-client stack /path/to/pom.xml --html
|
|
145
182
|
|
|
183
|
+
# get stack analysis for monorepo (lock file at workspace root)
|
|
184
|
+
$ trustify-da-javascript-client stack /path/to/package.json --workspace-dir /path/to/workspace-root
|
|
185
|
+
|
|
146
186
|
# get component analysis
|
|
147
187
|
$ trustify-da-javascript-client component /path/to/pom.xml
|
|
148
188
|
|
|
189
|
+
# get component analysis for monorepo
|
|
190
|
+
$ trustify-da-javascript-client component /path/to/package.json -w /path/to/workspace-root
|
|
191
|
+
|
|
192
|
+
# batch stack analysis for entire workspace
|
|
193
|
+
$ trustify-da-javascript-client stack-batch /path/to/workspace-root
|
|
194
|
+
|
|
195
|
+
# with extra discovery excludes
|
|
196
|
+
$ trustify-da-javascript-client stack-batch /path/to/workspace-root -i '**/vendor/**'
|
|
197
|
+
|
|
149
198
|
# get image analysis in json format
|
|
150
199
|
$ trustify-da-javascript-client image docker.io/library/node:18
|
|
151
200
|
|
|
@@ -161,6 +210,9 @@ $ trustify-da-javascript-client image docker.io/library/node:18 docker.io/librar
|
|
|
161
210
|
|
|
162
211
|
# specify architecture using ^^ notation (e.g., httpd:2.4.49^^amd64)
|
|
163
212
|
$ trustify-da-javascript-client image httpd:2.4.49^^amd64
|
|
213
|
+
|
|
214
|
+
# get project license information
|
|
215
|
+
$ trustify-da-javascript-client license /path/to/package.json
|
|
164
216
|
```
|
|
165
217
|
</li>
|
|
166
218
|
</ul>
|
|
@@ -174,8 +226,24 @@ $ trustify-da-javascript-client image httpd:2.4.49^^amd64
|
|
|
174
226
|
<li><a href="https://go.dev/">Golang</a> - <a href="https://go.dev/blog/using-go-modules/">Go Modules</a></li>
|
|
175
227
|
<li><a href="https://www.python.org/">Python</a> - <a href="https://pypi.org/project/pip/">pip Installer</a></li>
|
|
176
228
|
<li><a href="https://gradle.org/">Gradle (Groovy and Kotlin DSL)</a> - <a href="https://gradle.org/install/">Gradle Installation</a></li>
|
|
229
|
+
<li><a href="https://www.rust-lang.org/">Rust</a> - <a href="https://doc.rust-lang.org/cargo/">Cargo</a></li>
|
|
177
230
|
</ul>
|
|
178
231
|
|
|
232
|
+
<h3>License Detection</h3>
|
|
233
|
+
<p>
|
|
234
|
+
The client automatically detects your project's license with intelligent fallback:
|
|
235
|
+
</p>
|
|
236
|
+
<ul>
|
|
237
|
+
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript, Rust Cargo), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>, <code>Cargo.toml</code>)</li>
|
|
238
|
+
<li><strong>LICENSE file fallback:</strong> If no license in manifest, or for ecosystems without license support (Gradle, Go, Python), automatically reads from <code>LICENSE</code>, <code>LICENSE.md</code>, or <code>LICENSE.txt</code></li>
|
|
239
|
+
<li><strong>SBOM integration:</strong> Detected licenses are included in generated SBOMs for all ecosystems</li>
|
|
240
|
+
<li><strong>SPDX support:</strong> Automatically detects common licenses (Apache-2.0, MIT, GPL, BSD) from LICENSE file content</li>
|
|
241
|
+
</ul>
|
|
242
|
+
<p>
|
|
243
|
+
See <a href="./docs/license-resolution-and-compliance.md">License Resolution and Compliance</a> for detailed documentation.
|
|
244
|
+
</p>
|
|
245
|
+
|
|
246
|
+
|
|
179
247
|
<h3>Excluding Packages</h3>
|
|
180
248
|
<p>
|
|
181
249
|
Excluding a package from any analysis can be achieved by marking the package for exclusion.
|
|
@@ -219,8 +287,11 @@ Excluding a package from any analysis can be achieved by marking the package for
|
|
|
219
287
|
]
|
|
220
288
|
}
|
|
221
289
|
```
|
|
290
|
+
</li>
|
|
291
|
+
|
|
292
|
+
<li>
|
|
293
|
+
<em>Golang</em> users can add in go.mod a comment with <code>// exhortignore</code> next to the package to be ignored, or to "piggyback" on existing comment ( e.g - <code>// indirect</code>), for example:
|
|
222
294
|
|
|
223
|
-
<em>Golang</em> users can add in go.mod a comment with //exhortignore next to the package to be ignored, or to "piggyback" on existing comment ( e.g - //indirect) , for example:
|
|
224
295
|
```go
|
|
225
296
|
module github.com/trustify-da/SaaSi/deployer
|
|
226
297
|
|
|
@@ -229,7 +300,7 @@ go 1.19
|
|
|
229
300
|
require (
|
|
230
301
|
github.com/gin-gonic/gin v1.9.1
|
|
231
302
|
github.com/google/uuid v1.1.2
|
|
232
|
-
github.com/jessevdk/go-flags v1.5.0 //exhortignore
|
|
303
|
+
github.com/jessevdk/go-flags v1.5.0 // exhortignore
|
|
233
304
|
github.com/kr/pretty v0.3.1
|
|
234
305
|
gopkg.in/yaml.v2 v2.4.0
|
|
235
306
|
k8s.io/apimachinery v0.26.1
|
|
@@ -237,14 +308,20 @@ require (
|
|
|
237
308
|
)
|
|
238
309
|
|
|
239
310
|
require (
|
|
240
|
-
github.com/davecgh/go-spew v1.1.1 // indirect exhortignore
|
|
311
|
+
github.com/davecgh/go-spew v1.1.1 // indirect; exhortignore
|
|
241
312
|
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
|
242
|
-
github.com/go-logr/logr v1.2.3 // indirect
|
|
313
|
+
github.com/go-logr/logr v1.2.3 // indirect; exhortignore
|
|
243
314
|
|
|
244
315
|
)
|
|
245
316
|
```
|
|
246
317
|
|
|
318
|
+
<b>NOTE</b>: It is important to format <code>exhortignore</code> markers on indirect dependencies as shown above, otherwise the Go tooling (as well as this library) may incorrectly parse dependencies marked as indirect as being direct dependencies instead.
|
|
319
|
+
</li>
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
<li>
|
|
247
323
|
<em>Python pip</em> users can add in requirements.txt a comment with #exhortignore(or # exhortignore) to the right of the same artifact to be ignored, for example:
|
|
324
|
+
|
|
248
325
|
```properties
|
|
249
326
|
anyio==3.6.2
|
|
250
327
|
asgiref==3.4.1
|
|
@@ -275,11 +352,14 @@ Werkzeug==2.0.3
|
|
|
275
352
|
zipp==3.6.0
|
|
276
353
|
|
|
277
354
|
```
|
|
355
|
+
</li>
|
|
278
356
|
|
|
357
|
+
<li>
|
|
279
358
|
<em>Gradle</em> users can add in build.gradle a comment with //exhortignore next to the package to be ignored:
|
|
359
|
+
|
|
280
360
|
```build.gradle
|
|
281
361
|
plugins {
|
|
282
|
-
id 'java'
|
|
362
|
+
id 'java'
|
|
283
363
|
}
|
|
284
364
|
|
|
285
365
|
group = 'groupName'
|
|
@@ -297,9 +377,22 @@ test {
|
|
|
297
377
|
}
|
|
298
378
|
```
|
|
299
379
|
|
|
300
|
-
|
|
301
|
-
</li>
|
|
380
|
+
<em>Rust Cargo</em> users can add a comment with <code># trustify-da-ignore</code> (or <code># exhortignore</code>) in <em>Cargo.toml</em> next to the dependency to be ignored. This works for inline declarations, table-based declarations, and workspace-level dependency sections:
|
|
302
381
|
|
|
382
|
+
```toml
|
|
383
|
+
[dependencies]
|
|
384
|
+
serde = "1.0" # trustify-da-ignore
|
|
385
|
+
tokio = { version = "1.35", features = ["full"] }
|
|
386
|
+
|
|
387
|
+
[dependencies.regex] # trustify-da-ignore
|
|
388
|
+
version = "1.10"
|
|
389
|
+
|
|
390
|
+
[workspace.dependencies]
|
|
391
|
+
log = "0.4" # trustify-da-ignore
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
All of the 6 above examples are valid for marking a package to be ignored
|
|
395
|
+
</li>
|
|
303
396
|
</ul>
|
|
304
397
|
|
|
305
398
|
<h3>Customization</h3>
|
|
@@ -329,6 +422,9 @@ let options = {
|
|
|
329
422
|
'TRUSTIFY_DA_PYTHON_PATH' : '/path/to/python',
|
|
330
423
|
'TRUSTIFY_DA_PIP_PATH' : '/path/to/pip',
|
|
331
424
|
'TRUSTIFY_DA_GRADLE_PATH' : '/path/to/gradle',
|
|
425
|
+
'TRUSTIFY_DA_CARGO_PATH' : '/path/to/cargo',
|
|
426
|
+
// Workspace root for monorepos (Cargo, npm/pnpm/yarn); lock file expected here
|
|
427
|
+
'workspaceDir': '/path/to/workspace-root',
|
|
332
428
|
// Configure proxy for all requests
|
|
333
429
|
'TRUSTIFY_DA_PROXY_URL': 'http://proxy.example.com:8080'
|
|
334
430
|
}
|
|
@@ -351,6 +447,21 @@ let imageAnalysisWithArch = await client.imageAnalysis(['httpd:2.4.49^^amd64'],
|
|
|
351
447
|
**_Environment variables takes precedence._**
|
|
352
448
|
</p>
|
|
353
449
|
|
|
450
|
+
<h4>Monorepo / Workspace Support</h4>
|
|
451
|
+
<p>
|
|
452
|
+
For monorepos (Cargo workspaces, npm/pnpm/yarn workspaces) where the lock file lives at the workspace root rather than next to the manifest, pass the workspace root via <code>workspaceDir</code> or <code>TRUSTIFY_DA_WORKSPACE_DIR</code>:
|
|
453
|
+
</p>
|
|
454
|
+
<ul>
|
|
455
|
+
<li><strong>Cargo:</strong> When set, the client checks only the given directory for <code>Cargo.lock</code> instead of walking up from the manifest.</li>
|
|
456
|
+
<li><strong>JavaScript (npm, pnpm, yarn):</strong> When set, the client looks for the lock file (<code>package-lock.json</code>, <code>pnpm-lock.yaml</code>, <code>yarn.lock</code>) at the workspace root.</li>
|
|
457
|
+
</ul>
|
|
458
|
+
<p>
|
|
459
|
+
Use <code>stackAnalysisBatch(workspaceRoot, html, opts)</code> to analyze all packages/crates in a workspace in one request. Supports Cargo workspaces and JS/TS workspaces (pnpm, npm, yarn). Optional <code>batchConcurrency</code> (or <code>TRUSTIFY_DA_BATCH_CONCURRENCY</code>) limits parallel SBOM generation (default 10). For JS/TS, each <code>package.json</code> must have non-empty <code>name</code> and <code>version</code>; invalid manifests are skipped (warnings). Per-manifest SBOM failures are skipped if at least one SBOM succeeds (unless <code>continueOnError: false</code>). Set <code>batchMetadata: true</code> (or <code>TRUSTIFY_DA_BATCH_METADATA</code>) to receive <code>{ analysis, metadata }</code> with <code>errors[]</code>. CLI: <code>stack-batch --metadata</code>, <code>--fail-fast</code>. See <a href="./docs/monorepo-implementation-plan.md">monorepo implementation plan</a> §2.3 and §3.5.
|
|
460
|
+
</p>
|
|
461
|
+
<p>
|
|
462
|
+
See <a href="./docs/vscode-extension-integration-requirements.md">VS Code Extension Integration Requirements</a> for integration details.
|
|
463
|
+
</p>
|
|
464
|
+
|
|
354
465
|
<h4>Proxy Configuration</h4>
|
|
355
466
|
<p>
|
|
356
467
|
You can configure a proxy for all HTTP/HTTPS requests made by the API. This is useful when your environment requires going through a proxy to access external services.
|
|
@@ -372,6 +483,11 @@ const options = {
|
|
|
372
483
|
The proxy URL should be in the format: `http://host:port` or `https://host:port`. The API will automatically use the appropriate protocol (HTTP or HTTPS) based on the proxy URL provided.
|
|
373
484
|
</p>
|
|
374
485
|
|
|
486
|
+
<h4>License resolution and dependency license compliance</h4>
|
|
487
|
+
<p>
|
|
488
|
+
The client can resolve the <strong>project license</strong> from the manifest (e.g. <code>package.json</code> <code>license</code>, <code>pom.xml</code> <code><licenses></code>, <code>Cargo.toml</code> <code>license</code>) and from a <code>LICENSE</code> or <code>LICENSE.md</code> file in the project, and report when they differ. For <strong>component analysis</strong>, you can optionally run a license check: the client fetches dependency licenses from the backend (by purl) and reports dependencies whose licenses are incompatible with the project license. See <a href="docs/license-resolution-and-compliance.md">License resolution and compliance</a> for design and behavior. To disable the check on component analysis, set <code>TRUSTIFY_DA_LICENSE_CHECK=false</code> or pass <code>licenseCheck: false</code> in the options.
|
|
489
|
+
</p>
|
|
490
|
+
|
|
375
491
|
<h4>Customizing Executables</h4>
|
|
376
492
|
<p>
|
|
377
493
|
This project uses each ecosystem's executable for creating dependency trees. These executables are expected to be
|
|
@@ -445,6 +561,16 @@ following keys for setting custom paths for the said executables.
|
|
|
445
561
|
<td><em>gradle</em></td>
|
|
446
562
|
<td>TRUSTIFY_DA_PREFER_GRADLEW</td>
|
|
447
563
|
</tr>
|
|
564
|
+
<tr>
|
|
565
|
+
<td><a href="https://www.rust-lang.org/">Rust Cargo</a></td>
|
|
566
|
+
<td><em>cargo</em></td>
|
|
567
|
+
<td>TRUSTIFY_DA_CARGO_PATH</td>
|
|
568
|
+
</tr>
|
|
569
|
+
<tr>
|
|
570
|
+
<td>Workspace root (monorepos)</td>
|
|
571
|
+
<td>—</td>
|
|
572
|
+
<td>workspaceDir / TRUSTIFY_DA_WORKSPACE_DIR</td>
|
|
573
|
+
</tr>
|
|
448
574
|
</table>
|
|
449
575
|
|
|
450
576
|
#### Match Manifest Versions Feature
|
package/dist/package.json
CHANGED
|
@@ -40,29 +40,42 @@
|
|
|
40
40
|
"test": "c8 npm run tests",
|
|
41
41
|
"tests": "mocha --config .mocharc.json --grep \".*analysis module.*\" --invert",
|
|
42
42
|
"tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
|
|
43
|
+
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
|
|
43
44
|
"precompile": "rm -rf dist",
|
|
44
|
-
"compile": "tsc -p tsconfig.json"
|
|
45
|
+
"compile": "tsc -p tsconfig.json",
|
|
46
|
+
"compile:dev": "tsc -p tsconfig.dev.json",
|
|
47
|
+
"postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"@babel/core": "^7.23.2",
|
|
48
51
|
"@cyclonedx/cyclonedx-library": "^6.13.0",
|
|
52
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
53
|
+
"fast-glob": "^3.3.3",
|
|
49
54
|
"fast-toml": "^0.5.4",
|
|
50
55
|
"fast-xml-parser": "^5.3.4",
|
|
51
56
|
"help": "^3.0.2",
|
|
52
57
|
"https-proxy-agent": "^7.0.6",
|
|
53
|
-
"
|
|
58
|
+
"js-yaml": "^4.1.1",
|
|
59
|
+
"micromatch": "^4.0.8",
|
|
60
|
+
"node-fetch": "^3.3.2",
|
|
61
|
+
"p-limit": "^4.0.0",
|
|
54
62
|
"packageurl-js": "~1.0.2",
|
|
55
|
-
"
|
|
63
|
+
"smol-toml": "^1.6.0",
|
|
64
|
+
"tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
|
|
65
|
+
"tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
|
|
66
|
+
"web-tree-sitter": "^0.26.7",
|
|
67
|
+
"yargs": "^18.0.0"
|
|
56
68
|
},
|
|
57
69
|
"devDependencies": {
|
|
58
70
|
"@babel/core": "^7.23.2",
|
|
59
|
-
"@trustify-da/trustify-da-api-model": "^2.0.
|
|
71
|
+
"@trustify-da/trustify-da-api-model": "^2.0.7",
|
|
60
72
|
"@types/node": "^20.17.30",
|
|
61
73
|
"@types/which": "^3.0.4",
|
|
62
74
|
"babel-plugin-rewire": "^1.2.0",
|
|
63
|
-
"c8": "^
|
|
75
|
+
"c8": "^11.0.0",
|
|
64
76
|
"chai": "^4.3.7",
|
|
65
77
|
"eslint": "^8.42.0",
|
|
78
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
66
79
|
"eslint-plugin-editorconfig": "^4.0.3",
|
|
67
80
|
"eslint-plugin-import": "^2.29.1",
|
|
68
81
|
"esmock": "^2.6.2",
|
package/dist/src/analysis.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/** Media type for CycloneDX JSON batch payloads (batch-analysis API). */
|
|
2
|
+
export const CYCLONEDX_JSON_MEDIA_TYPE: "application/vnd.cyclonedx+json";
|
|
1
3
|
declare namespace _default {
|
|
2
4
|
export { requestComponent };
|
|
3
5
|
export { requestStack };
|
|
6
|
+
export { requestStackBatch };
|
|
4
7
|
export { requestImages };
|
|
5
8
|
export { validateToken };
|
|
6
9
|
}
|
|
@@ -24,6 +27,19 @@ declare function requestComponent(provider: import("./provider").Provider, manif
|
|
|
24
27
|
* @returns {Promise<string|import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
|
|
25
28
|
*/
|
|
26
29
|
declare function requestStack(provider: import("./provider").Provider, manifest: string, url: string, html?: boolean, opts?: import("index.js").Options): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
|
|
30
|
+
/**
|
|
31
|
+
* Send a batch stack analysis request for multiple manifests (SBOMs keyed by purl).
|
|
32
|
+
* @param {Object.<string, object>} sbomByPurl - Map of root purl to CycloneDX SBOM object
|
|
33
|
+
* @param {string} url - the backend url
|
|
34
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON
|
|
35
|
+
* @param {import("index.js").Options} [opts={}]
|
|
36
|
+
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
37
|
+
*/
|
|
38
|
+
declare function requestStackBatch(sbomByPurl: {
|
|
39
|
+
[x: string]: any;
|
|
40
|
+
}, url: string, html?: boolean, opts?: import("index.js").Options): Promise<string | {
|
|
41
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
42
|
+
}>;
|
|
27
43
|
/**
|
|
28
44
|
*
|
|
29
45
|
* @param {Array<string>} imageRefs
|
package/dist/src/analysis.js
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { EOL } from "os";
|
|
4
|
-
import {
|
|
4
|
+
import { runLicenseCheck } from "./license/index.js";
|
|
5
5
|
import { generateImageSBOM, parseImageRef } from "./oci_image/utils.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const rhdaSourceHeader = "rhda-source";
|
|
11
|
-
const rhdaOperationTypeHeader = "rhda-operation-type";
|
|
12
|
-
const rhdaPackageManagerHeader = "rhda-pkg-manager";
|
|
13
|
-
/**
|
|
14
|
-
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
15
|
-
* @param {RequestInit} options - The base fetch options
|
|
16
|
-
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
17
|
-
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
18
|
-
*/
|
|
19
|
-
function addProxyAgent(options, opts) {
|
|
20
|
-
const proxyUrl = getCustom('TRUSTIFY_DA_PROXY_URL', null, opts);
|
|
21
|
-
if (proxyUrl) {
|
|
22
|
-
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
23
|
-
}
|
|
24
|
-
return options;
|
|
25
|
-
}
|
|
6
|
+
import { addProxyAgent, getCustom, getTokenHeaders, TRUSTIFY_DA_OPERATION_TYPE_HEADER, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER } from "./tools.js";
|
|
7
|
+
/** Media type for CycloneDX JSON batch payloads (batch-analysis API). */
|
|
8
|
+
export const CYCLONEDX_JSON_MEDIA_TYPE = 'application/vnd.cyclonedx+json';
|
|
9
|
+
export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken };
|
|
26
10
|
/**
|
|
27
11
|
* Send a stack analysis request and get the report as 'text/html' or 'application/json'.
|
|
28
12
|
* @param {import('./provider').Provider} provider - the provided data for constructing the request
|
|
@@ -35,15 +19,15 @@ function addProxyAgent(options, opts) {
|
|
|
35
19
|
async function requestStack(provider, manifest, url, html = false, opts = {}) {
|
|
36
20
|
opts["source-manifest"] = Buffer.from(fs.readFileSync(manifest).toString()).toString('base64');
|
|
37
21
|
opts["manifest-type"] = path.parse(manifest).base;
|
|
38
|
-
let provided = provider.provideStack(manifest, opts); // throws error if content providing failed
|
|
22
|
+
let provided = await provider.provideStack(manifest, opts); // throws error if content providing failed
|
|
39
23
|
opts["source-manifest"] = "";
|
|
40
|
-
opts[
|
|
24
|
+
opts[TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_")] = "stack-analysis";
|
|
41
25
|
let startTime = new Date();
|
|
42
26
|
let endTime;
|
|
43
27
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
44
28
|
console.log("Starting time of sending stack analysis request to the dependency analytics server= " + startTime);
|
|
45
29
|
}
|
|
46
|
-
opts[
|
|
30
|
+
opts[TRUSTIFY_DA_PACKAGE_MANAGER_HEADER.toUpperCase().replaceAll("-", "_")] = provided.ecosystem;
|
|
47
31
|
const fetchOptions = addProxyAgent({
|
|
48
32
|
method: 'POST',
|
|
49
33
|
headers: {
|
|
@@ -53,7 +37,7 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
|
|
|
53
37
|
},
|
|
54
38
|
body: provided.content
|
|
55
39
|
}, opts);
|
|
56
|
-
const finalUrl = new URL(`${url}/api/
|
|
40
|
+
const finalUrl = new URL(`${url}/api/v5/analysis`);
|
|
57
41
|
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
58
42
|
finalUrl.searchParams.append('recommend', 'false');
|
|
59
43
|
}
|
|
@@ -94,13 +78,13 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
|
|
|
94
78
|
*/
|
|
95
79
|
async function requestComponent(provider, manifest, url, opts = {}) {
|
|
96
80
|
opts["source-manifest"] = Buffer.from(fs.readFileSync(manifest).toString()).toString('base64');
|
|
97
|
-
let provided = provider.provideComponent(manifest, opts); // throws error if content providing failed
|
|
81
|
+
let provided = await provider.provideComponent(manifest, opts); // throws error if content providing failed
|
|
98
82
|
opts["source-manifest"] = "";
|
|
99
|
-
opts[
|
|
83
|
+
opts[TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_")] = "component-analysis";
|
|
100
84
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
101
85
|
console.log("Starting time of sending component analysis request to Trustify DA backend server= " + new Date());
|
|
102
86
|
}
|
|
103
|
-
opts[
|
|
87
|
+
opts[TRUSTIFY_DA_PACKAGE_MANAGER_HEADER.toUpperCase().replaceAll("-", "_")] = provided.ecosystem;
|
|
104
88
|
const fetchOptions = addProxyAgent({
|
|
105
89
|
method: 'POST',
|
|
106
90
|
headers: {
|
|
@@ -110,7 +94,7 @@ async function requestComponent(provider, manifest, url, opts = {}) {
|
|
|
110
94
|
},
|
|
111
95
|
body: provided.content
|
|
112
96
|
}, opts);
|
|
113
|
-
const finalUrl = new URL(`${url}/api/
|
|
97
|
+
const finalUrl = new URL(`${url}/api/v5/analysis`);
|
|
114
98
|
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
115
99
|
finalUrl.searchParams.append('recommend', 'false');
|
|
116
100
|
}
|
|
@@ -127,12 +111,67 @@ async function requestComponent(provider, manifest, url, opts = {}) {
|
|
|
127
111
|
console.log(JSON.stringify(result, null, 4));
|
|
128
112
|
console.log("Ending time of sending component analysis request to Trustify DA backend server= " + new Date());
|
|
129
113
|
}
|
|
114
|
+
const licenseCheckEnabled = getCustom('TRUSTIFY_DA_LICENSE_CHECK', 'true', opts) !== 'false' && opts.licenseCheck !== false;
|
|
115
|
+
if (licenseCheckEnabled) {
|
|
116
|
+
try {
|
|
117
|
+
result.licenseSummary = await runLicenseCheck(provided.content, manifest, url, opts, result);
|
|
118
|
+
}
|
|
119
|
+
catch (licenseErr) {
|
|
120
|
+
result.licenseSummary = { error: licenseErr.message };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
130
123
|
}
|
|
131
124
|
else {
|
|
132
125
|
throw new Error(`Got error response from Trustify DA backend - http return code : ${resp.status}, ex-request-id: ${resp.headers.get("ex-request-id")} error message => ${await resp.text()}`);
|
|
133
126
|
}
|
|
134
127
|
return Promise.resolve(result);
|
|
135
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Send a batch stack analysis request for multiple manifests (SBOMs keyed by purl).
|
|
131
|
+
* @param {Object.<string, object>} sbomByPurl - Map of root purl to CycloneDX SBOM object
|
|
132
|
+
* @param {string} url - the backend url
|
|
133
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON
|
|
134
|
+
* @param {import("index.js").Options} [opts={}]
|
|
135
|
+
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
136
|
+
*/
|
|
137
|
+
async function requestStackBatch(sbomByPurl, url, html = false, opts = {}) {
|
|
138
|
+
const finalUrl = new URL(`${url}/api/v5/batch-analysis`);
|
|
139
|
+
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
140
|
+
finalUrl.searchParams.append('recommend', 'false');
|
|
141
|
+
}
|
|
142
|
+
const fetchOptions = addProxyAgent({
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: {
|
|
145
|
+
'Accept': html ? 'text/html' : 'application/json',
|
|
146
|
+
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
|
|
147
|
+
...getTokenHeaders(opts)
|
|
148
|
+
},
|
|
149
|
+
body: JSON.stringify(sbomByPurl)
|
|
150
|
+
}, opts);
|
|
151
|
+
const resp = await fetch(finalUrl, fetchOptions);
|
|
152
|
+
if (resp.status === 200) {
|
|
153
|
+
let result;
|
|
154
|
+
if (!html) {
|
|
155
|
+
result = await resp.json();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
result = await resp.text();
|
|
159
|
+
}
|
|
160
|
+
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
161
|
+
const exRequestId = resp.headers.get("ex-request-id");
|
|
162
|
+
if (exRequestId) {
|
|
163
|
+
console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId);
|
|
164
|
+
}
|
|
165
|
+
console.log("Response body received from Trustify DA backend server : " + EOL + EOL);
|
|
166
|
+
console.log(JSON.stringify(result, null, 4));
|
|
167
|
+
console.log("Ending time of sending batch stack analysis request to Trustify DA backend server= " + new Date());
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new Error(`Got error response from Trustify DA backend - http return code : ${resp.status}, ex-request-id: ${resp.headers.get("ex-request-id")} error message => ${await resp.text()}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
136
175
|
/**
|
|
137
176
|
*
|
|
138
177
|
* @param {Array<string>} imageRefs
|
|
@@ -146,7 +185,7 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
|
|
|
146
185
|
const parsedImageRef = parseImageRef(image, opts);
|
|
147
186
|
imageSboms[parsedImageRef.getPackageURL().toString()] = generateImageSBOM(parsedImageRef, opts);
|
|
148
187
|
}
|
|
149
|
-
const finalUrl = new URL(`${url}/api/
|
|
188
|
+
const finalUrl = new URL(`${url}/api/v5/batch-analysis`);
|
|
150
189
|
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
151
190
|
finalUrl.searchParams.append('recommend', 'false');
|
|
152
191
|
}
|
|
@@ -154,7 +193,7 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
|
|
|
154
193
|
method: 'POST',
|
|
155
194
|
headers: {
|
|
156
195
|
'Accept': html ? 'text/html' : 'application/json',
|
|
157
|
-
'Content-Type':
|
|
196
|
+
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
|
|
158
197
|
...getTokenHeaders(opts)
|
|
159
198
|
},
|
|
160
199
|
body: JSON.stringify(imageSboms),
|
|
@@ -195,7 +234,7 @@ async function validateToken(url, opts = {}) {
|
|
|
195
234
|
...getTokenHeaders(opts),
|
|
196
235
|
}
|
|
197
236
|
}, opts);
|
|
198
|
-
let resp = await fetch(`${url}/api/
|
|
237
|
+
let resp = await fetch(`${url}/api/v5/token`, fetchOptions);
|
|
199
238
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
200
239
|
let exRequestId = resp.headers.get("ex-request-id");
|
|
201
240
|
if (exRequestId) {
|
|
@@ -204,49 +243,3 @@ async function validateToken(url, opts = {}) {
|
|
|
204
243
|
}
|
|
205
244
|
return resp.status;
|
|
206
245
|
}
|
|
207
|
-
/**
|
|
208
|
-
*
|
|
209
|
-
* @param {string} headerName - the header name to populate in request
|
|
210
|
-
* @param headers
|
|
211
|
-
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
212
|
-
* @private
|
|
213
|
-
*/
|
|
214
|
-
function setRhdaHeader(headerName, headers, opts) {
|
|
215
|
-
let rhdaHeaderValue = getCustom(headerName.toUpperCase().replaceAll("-", "_"), null, opts);
|
|
216
|
-
if (rhdaHeaderValue) {
|
|
217
|
-
headers[headerName] = rhdaHeaderValue;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Utility function for fetching vendor tokens
|
|
222
|
-
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
223
|
-
* @returns {{}}
|
|
224
|
-
*/
|
|
225
|
-
function getTokenHeaders(opts = {}) {
|
|
226
|
-
let supportedTokens = ['snyk', 'oss-index'];
|
|
227
|
-
let headers = {};
|
|
228
|
-
supportedTokens.forEach(vendor => {
|
|
229
|
-
let token = getCustom(`TRUSTIFY_DA_${vendor.replace("-", "_").toUpperCase()}_TOKEN`, null, opts);
|
|
230
|
-
if (token) {
|
|
231
|
-
headers[`ex-${vendor}-token`] = token;
|
|
232
|
-
}
|
|
233
|
-
let user = getCustom(`TRUSTIFY_DA_${vendor.replace("-", "_").toUpperCase()}_USER`, null, opts);
|
|
234
|
-
if (user) {
|
|
235
|
-
headers[`ex-${vendor}-user`] = user;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
setRhdaHeader(rhdaTokenHeader, headers, opts);
|
|
239
|
-
setRhdaHeader(rhdaSourceHeader, headers, opts);
|
|
240
|
-
setRhdaHeader(rhdaOperationTypeHeader, headers, opts);
|
|
241
|
-
setRhdaHeader(rhdaPackageManagerHeader, headers, opts);
|
|
242
|
-
setRhdaHeader(rhdaTelemetryId, headers, opts);
|
|
243
|
-
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
244
|
-
console.log("Headers Values to be sent to Trustify DA backend:" + EOL);
|
|
245
|
-
for (const headerKey in headers) {
|
|
246
|
-
if (!headerKey.match(RegexNotToBeLogged)) {
|
|
247
|
-
console.log(`${headerKey}: ${headers[headerKey]}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return headers;
|
|
252
|
-
}
|
|
@@ -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
|
+
}
|