@trustify-da/trustify-da-javascript-client 0.3.0-ea.c9a9877 → 0.3.0-ea.cb4ae28
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 +43 -1
- package/dist/package.json +16 -9
- package/dist/src/analysis.d.ts +5 -5
- package/dist/src/analysis.js +21 -76
- package/dist/src/cli.js +72 -6
- package/dist/src/cyclone_dx_sbom.d.ts +3 -2
- package/dist/src/cyclone_dx_sbom.js +16 -4
- package/dist/src/index.d.ts +65 -11
- package/dist/src/index.js +5 -3
- 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/images.d.ts +4 -5
- package/dist/src/oci_image/utils.d.ts +4 -4
- package/dist/src/provider.d.ts +12 -3
- package/dist/src/provider.js +16 -1
- package/dist/src/providers/base_java.d.ts +3 -5
- package/dist/src/providers/base_javascript.d.ts +10 -4
- package/dist/src/providers/base_javascript.js +30 -4
- package/dist/src/providers/golang_gomodules.d.ts +11 -4
- package/dist/src/providers/golang_gomodules.js +13 -4
- package/dist/src/providers/java_gradle.d.ts +9 -3
- package/dist/src/providers/java_gradle.js +12 -2
- 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 +12 -5
- package/dist/src/providers/java_maven.js +33 -5
- 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 +46 -53
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/sbom.d.ts +3 -1
- package/dist/src/sbom.js +3 -2
- package/dist/src/tools.d.ts +22 -6
- package/dist/src/tools.js +56 -1
- package/package.json +17 -10
package/dist/src/provider.js
CHANGED
|
@@ -8,7 +8,7 @@ import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
|
8
8
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
9
|
import pythonPipProvider from './providers/python_pip.js';
|
|
10
10
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
11
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided
|
|
11
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
12
12
|
/**
|
|
13
13
|
* MUST include all providers here.
|
|
14
14
|
* @type {[Provider]}
|
|
@@ -23,6 +23,21 @@ export const availableProviders = [
|
|
|
23
23
|
golangGomodulesProvider,
|
|
24
24
|
pythonPipProvider
|
|
25
25
|
];
|
|
26
|
+
/**
|
|
27
|
+
* Match a provider by manifest type only (no lock file check). Used for license reading.
|
|
28
|
+
* @param {string} manifestPath - path or name of the manifest
|
|
29
|
+
* @param {[Provider]} providers - list of providers to iterate over
|
|
30
|
+
* @returns {Provider}
|
|
31
|
+
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
32
|
+
*/
|
|
33
|
+
export function matchForLicense(manifestPath, providers) {
|
|
34
|
+
const base = path.parse(manifestPath).base;
|
|
35
|
+
const provider = providers.find(prov => prov.isSupported(base));
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw new Error(`${base} is not supported`);
|
|
38
|
+
}
|
|
39
|
+
return provider;
|
|
40
|
+
}
|
|
26
41
|
/**
|
|
27
42
|
* Match a provider from a list or providers based on file type.
|
|
28
43
|
* Each provider MUST export 'isSupported' taking a file name-type and returning true if supported.
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="packageurl-js/src/package-url.js" />
|
|
3
|
-
export type ecosystem_maven = import('../provider').Provider;
|
|
1
|
+
export type ecosystem_maven = import("../provider").Provider;
|
|
4
2
|
/** @typedef {import('../provider').Provider} */
|
|
5
3
|
/** @typedef {import('../provider').Provided} Provided */
|
|
6
4
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -51,7 +49,7 @@ export default class Base_Java {
|
|
|
51
49
|
* @param {import('child_process').ExecFileOptionsWithStringEncoding} [opts={}]
|
|
52
50
|
* @protected
|
|
53
51
|
*/
|
|
54
|
-
protected _invokeCommand(bin: any, args: any, opts?: import("child_process").ExecFileOptionsWithStringEncoding
|
|
52
|
+
protected _invokeCommand(bin: any, args: any, opts?: import("child_process").ExecFileOptionsWithStringEncoding): string;
|
|
55
53
|
/**
|
|
56
54
|
*
|
|
57
55
|
* @param {string} manifestPath
|
|
@@ -70,7 +68,7 @@ export default class Base_Java {
|
|
|
70
68
|
normalizePath(thePath: any): string;
|
|
71
69
|
#private;
|
|
72
70
|
}
|
|
73
|
-
export type Provided = import(
|
|
71
|
+
export type Provided = import("../provider").Provided;
|
|
74
72
|
export type Package = {
|
|
75
73
|
name: string;
|
|
76
74
|
version: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/** @typedef {import('../provider
|
|
1
|
+
export type purlType = import("../provider").Provider;
|
|
2
|
+
/** @typedef {import('../provider').Provider} */
|
|
3
|
+
/** @typedef {import('../provider').Provided} Provided */
|
|
3
4
|
/**
|
|
4
5
|
* The ecosystem identifier for JavaScript/npm packages
|
|
5
6
|
* @type {string}
|
|
@@ -85,6 +86,12 @@ export default class Base_javascript {
|
|
|
85
86
|
* @returns {Provided} The provided data for component analysis
|
|
86
87
|
*/
|
|
87
88
|
provideComponent(manifestPath: string, opts?: any): Provided;
|
|
89
|
+
/**
|
|
90
|
+
* Read license from manifest (package.json). Reused by npm, pnpm, yarn.
|
|
91
|
+
* @param {string} manifestPath - path to package.json
|
|
92
|
+
* @returns {string|null}
|
|
93
|
+
*/
|
|
94
|
+
readLicenseFromManifest(manifestPath: string): string | null;
|
|
88
95
|
/**
|
|
89
96
|
* Builds the dependency tree for the project
|
|
90
97
|
* @param {boolean} includeTransitive - Whether to include transitive dependencies
|
|
@@ -121,7 +128,6 @@ export default class Base_javascript {
|
|
|
121
128
|
protected _parseDepTreeOutput(output: string): string;
|
|
122
129
|
#private;
|
|
123
130
|
}
|
|
124
|
-
export type
|
|
125
|
-
export type Provided = import('../provider.js').Provided;
|
|
131
|
+
export type Provided = import("../provider").Provided;
|
|
126
132
|
import Manifest from './manifest.js';
|
|
127
133
|
import Sbom from '../sbom.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { getLicense } from '../license/license_utils.js';
|
|
4
5
|
import Sbom from '../sbom.js';
|
|
5
6
|
import { getCustom, getCustomPath, invokeCommand, toPurl, toPurlFromString } from "../tools.js";
|
|
6
7
|
import Manifest from './manifest.js';
|
|
7
|
-
/** @typedef {import('../provider
|
|
8
|
-
/** @typedef {import('../provider
|
|
8
|
+
/** @typedef {import('../provider').Provider} */
|
|
9
|
+
/** @typedef {import('../provider').Provided} Provided */
|
|
9
10
|
/**
|
|
10
11
|
* The ecosystem identifier for JavaScript/npm packages
|
|
11
12
|
* @type {string}
|
|
@@ -132,6 +133,29 @@ export default class Base_javascript {
|
|
|
132
133
|
contentType: 'application/vnd.cyclonedx+json'
|
|
133
134
|
};
|
|
134
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Read license from manifest (package.json). Reused by npm, pnpm, yarn.
|
|
138
|
+
* @param {string} manifestPath - path to package.json
|
|
139
|
+
* @returns {string|null}
|
|
140
|
+
*/
|
|
141
|
+
readLicenseFromManifest(manifestPath) {
|
|
142
|
+
let manifestLicense;
|
|
143
|
+
try {
|
|
144
|
+
const content = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
145
|
+
if (typeof content.license === 'string') {
|
|
146
|
+
manifestLicense = content.license.trim() || null;
|
|
147
|
+
}
|
|
148
|
+
else if (Array.isArray(content.licenses) && content.licenses.length > 0) {
|
|
149
|
+
const first = content.licenses[0];
|
|
150
|
+
const name = first.type || first.name;
|
|
151
|
+
manifestLicense = (typeof name === 'string' ? name.trim() : null);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
manifestLicense = null;
|
|
156
|
+
}
|
|
157
|
+
return getLicense(manifestLicense, manifestPath);
|
|
158
|
+
}
|
|
135
159
|
/**
|
|
136
160
|
* Builds the dependency tree for the project
|
|
137
161
|
* @param {boolean} includeTransitive - Whether to include transitive dependencies
|
|
@@ -155,8 +179,9 @@ export default class Base_javascript {
|
|
|
155
179
|
#getSBOM(opts = {}) {
|
|
156
180
|
const depsObject = this._buildDependencyTree(true);
|
|
157
181
|
let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
182
|
+
const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
|
|
158
183
|
let sbom = new Sbom();
|
|
159
|
-
sbom.addRoot(mainComponent);
|
|
184
|
+
sbom.addRoot(mainComponent, license);
|
|
160
185
|
this._addDependenciesToSbom(sbom, depsObject);
|
|
161
186
|
sbom.filterIgnoredDeps(this.#manifest.ignored);
|
|
162
187
|
return sbom.getAsJsonString(opts);
|
|
@@ -206,8 +231,9 @@ export default class Base_javascript {
|
|
|
206
231
|
#getDirectDependencySbom(opts = {}) {
|
|
207
232
|
const depTree = this._buildDependencyTree(false);
|
|
208
233
|
let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
234
|
+
const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
|
|
209
235
|
let sbom = new Sbom();
|
|
210
|
-
sbom.addRoot(mainComponent);
|
|
236
|
+
sbom.addRoot(mainComponent, license);
|
|
211
237
|
const rootDeps = this._getRootDependencies(depTree);
|
|
212
238
|
const sortedDepsKeys = Array
|
|
213
239
|
.from(rootDeps.keys())
|
|
@@ -3,9 +3,10 @@ declare namespace _default {
|
|
|
3
3
|
export { validateLockFile };
|
|
4
4
|
export { provideComponent };
|
|
5
5
|
export { provideStack };
|
|
6
|
+
export { readLicenseFromManifest };
|
|
6
7
|
}
|
|
7
8
|
export default _default;
|
|
8
|
-
export type Provided = import(
|
|
9
|
+
export type Provided = import("../provider").Provided;
|
|
9
10
|
export type Package = {
|
|
10
11
|
name: string;
|
|
11
12
|
version: string;
|
|
@@ -20,7 +21,7 @@ export type Dependency = {
|
|
|
20
21
|
/**
|
|
21
22
|
* @param {string} manifestName - the subject manifest name-type
|
|
22
23
|
* @returns {boolean} - return true if `pom.xml` is the manifest name-type
|
|
23
|
-
|
|
24
|
+
*/
|
|
24
25
|
declare function isSupported(manifestName: string): boolean;
|
|
25
26
|
/**
|
|
26
27
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
@@ -32,11 +33,17 @@ declare function validateLockFile(): boolean;
|
|
|
32
33
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
33
34
|
* @returns {Provided}
|
|
34
35
|
*/
|
|
35
|
-
declare function provideComponent(manifest: string, opts?: {}
|
|
36
|
+
declare function provideComponent(manifest: string, opts?: {}): Provided;
|
|
36
37
|
/**
|
|
37
38
|
* Provide content and content type for maven-maven stack analysis.
|
|
38
39
|
* @param {string} manifest - the manifest path or name
|
|
39
40
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
40
41
|
* @returns {Provided}
|
|
41
42
|
*/
|
|
42
|
-
declare function provideStack(manifest: string, opts?: {}
|
|
43
|
+
declare function provideStack(manifest: string, opts?: {}): Provided;
|
|
44
|
+
/**
|
|
45
|
+
* Go modules have no standard license field in go.mod
|
|
46
|
+
* @param {string} manifestPath - path to go.mod
|
|
47
|
+
* @returns {string|null}
|
|
48
|
+
*/
|
|
49
|
+
declare function readLicenseFromManifest(manifestPath: string): string | null;
|
|
@@ -2,9 +2,10 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { EOL } from "os";
|
|
4
4
|
import { PackageURL } from 'packageurl-js';
|
|
5
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
6
|
import Sbom from '../sbom.js';
|
|
6
7
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
|
-
export default { isSupported, validateLockFile, provideComponent, provideStack };
|
|
8
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
8
9
|
/** @typedef {import('../provider').Provider} */
|
|
9
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
10
11
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -12,16 +13,23 @@ export default { isSupported, validateLockFile, provideComponent, provideStack }
|
|
|
12
13
|
/**
|
|
13
14
|
* @type {string} ecosystem for npm-npm is 'maven'
|
|
14
15
|
* @private
|
|
15
|
-
|
|
16
|
+
*/
|
|
16
17
|
const ecosystem = 'golang';
|
|
17
18
|
const defaultMainModuleVersion = "v0.0.0";
|
|
18
19
|
/**
|
|
19
20
|
* @param {string} manifestName - the subject manifest name-type
|
|
20
21
|
* @returns {boolean} - return true if `pom.xml` is the manifest name-type
|
|
21
|
-
|
|
22
|
+
*/
|
|
22
23
|
function isSupported(manifestName) {
|
|
23
24
|
return 'go.mod' === manifestName;
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Go modules have no standard license field in go.mod
|
|
28
|
+
* @param {string} manifestPath - path to go.mod
|
|
29
|
+
* @returns {string|null}
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line no-unused-vars
|
|
32
|
+
function readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
25
33
|
/**
|
|
26
34
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
27
35
|
*/
|
|
@@ -250,7 +258,8 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
250
258
|
performManifestVersionsCheck(root, rows, manifest);
|
|
251
259
|
}
|
|
252
260
|
const mainModule = toPurl(root, "@");
|
|
253
|
-
|
|
261
|
+
const license = readLicenseFromManifest(manifest);
|
|
262
|
+
sbom.addRoot(mainModule, license);
|
|
254
263
|
const exhortGoMvsLogicEnabled = getCustom("TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED", "true", opts);
|
|
255
264
|
if (includeTransitive && exhortGoMvsLogicEnabled === "true") {
|
|
256
265
|
rows = getFinalPackagesVersionsForModule(rows, manifest, goBin);
|
|
@@ -15,21 +15,27 @@ export default class Java_gradle extends Base_java {
|
|
|
15
15
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
16
16
|
*/
|
|
17
17
|
validateLockFile(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Gradle manifests (build.gradle, build.gradle.kts) have no standard license field.
|
|
20
|
+
* @param {string} manifestPath - path to manifest
|
|
21
|
+
* @returns {null}
|
|
22
|
+
*/
|
|
23
|
+
readLicenseFromManifest(manifestPath: string): null;
|
|
18
24
|
/**
|
|
19
25
|
* Provide content and content type for stack analysis.
|
|
20
26
|
* @param {string} manifest - the manifest path or name
|
|
21
27
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
22
28
|
* @returns {Provided}
|
|
23
29
|
*/
|
|
24
|
-
provideStack(manifest: string, opts?: {}
|
|
30
|
+
provideStack(manifest: string, opts?: {}): Provided;
|
|
25
31
|
/**
|
|
26
32
|
* Provide content and content type for maven-maven component analysis.
|
|
27
33
|
* @param {string} manifest - path to pom.xml for component report
|
|
28
34
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
29
35
|
* @returns {Provided}
|
|
30
36
|
*/
|
|
31
|
-
provideComponent(manifest: string, opts?: {}
|
|
37
|
+
provideComponent(manifest: string, opts?: {}): Provided;
|
|
32
38
|
#private;
|
|
33
39
|
}
|
|
34
|
-
export type Provided = import(
|
|
40
|
+
export type Provided = import("../provider.js").Provided;
|
|
35
41
|
import Base_java from "./base_java.js";
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { EOL } from 'os';
|
|
4
4
|
import TOML from 'fast-toml';
|
|
5
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
6
|
import Sbom from '../sbom.js';
|
|
6
7
|
import Base_java, { ecosystem_gradle } from "./base_java.js";
|
|
7
8
|
/** @typedef {import('../provider.js').Provider} */
|
|
@@ -49,6 +50,13 @@ export default class Java_gradle extends Base_java {
|
|
|
49
50
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
50
51
|
*/
|
|
51
52
|
validateLockFile() { return true; }
|
|
53
|
+
/**
|
|
54
|
+
* Gradle manifests (build.gradle, build.gradle.kts) have no standard license field.
|
|
55
|
+
* @param {string} manifestPath - path to manifest
|
|
56
|
+
* @returns {null}
|
|
57
|
+
*/
|
|
58
|
+
// eslint-disable-next-line no-unused-vars
|
|
59
|
+
readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
52
60
|
/**
|
|
53
61
|
* Provide content and content type for stack analysis.
|
|
54
62
|
* @param {string} manifest - the manifest path or name
|
|
@@ -158,7 +166,8 @@ export default class Java_gradle extends Base_java {
|
|
|
158
166
|
let sbom = new Sbom();
|
|
159
167
|
let root = `${properties.group}:${properties[ROOT_PROJECT_KEY_NAME].match(/Root project '(.+)'/)[1]}:jar:${properties.version}`;
|
|
160
168
|
let rootPurl = this.parseDep(root);
|
|
161
|
-
|
|
169
|
+
const license = this.readLicenseFromManifest(manifestPath);
|
|
170
|
+
sbom.addRoot(rootPurl, license);
|
|
162
171
|
let ignoredDeps = this.#getIgnoredDeps(manifestPath);
|
|
163
172
|
const [runtimeConfig, compileConfig] = this.#extractConfigurations(content);
|
|
164
173
|
const processedDeps = new Set();
|
|
@@ -298,7 +307,8 @@ export default class Java_gradle extends Base_java {
|
|
|
298
307
|
let sbom = new Sbom();
|
|
299
308
|
let root = `${properties.group}:${properties[ROOT_PROJECT_KEY_NAME].match(/Root project '(.+)'/)[1]}:jar:${properties.version}`;
|
|
300
309
|
let rootPurl = this.parseDep(root);
|
|
301
|
-
|
|
310
|
+
const license = this.readLicenseFromManifest(manifestPath);
|
|
311
|
+
sbom.addRoot(rootPurl, license);
|
|
302
312
|
let ignoredDeps = this.#getIgnoredDeps(manifestPath);
|
|
303
313
|
const [runtimeConfig, compileConfig] = this.#extractConfigurations(content);
|
|
304
314
|
let directDependencies = new Map();
|
|
@@ -3,5 +3,5 @@ export default class Java_gradle_groovy extends Java_gradle {
|
|
|
3
3
|
_parseAliasForLibsNotation(alias: any): any;
|
|
4
4
|
_extractDepToBeIgnored(dep: any): any;
|
|
5
5
|
}
|
|
6
|
-
export type Provided = import(
|
|
6
|
+
export type Provided = import("../provider").Provided;
|
|
7
7
|
import Java_gradle from './java_gradle.js';
|
|
@@ -7,5 +7,5 @@ export default class Java_gradle_kotlin extends Java_gradle {
|
|
|
7
7
|
_parseAliasForLibsNotation(alias: any): any;
|
|
8
8
|
_extractDepToBeIgnored(dep: any): string | null;
|
|
9
9
|
}
|
|
10
|
-
export type Provided = import(
|
|
10
|
+
export type Provided = import("../provider").Provided;
|
|
11
11
|
import Java_gradle from './java_gradle.js';
|
|
@@ -19,25 +19,32 @@ export default class Java_maven extends Base_java {
|
|
|
19
19
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
20
20
|
* @returns {Provided}
|
|
21
21
|
*/
|
|
22
|
-
provideStack(manifest: string, opts?: {}
|
|
22
|
+
provideStack(manifest: string, opts?: {}): Provided;
|
|
23
23
|
/**
|
|
24
24
|
* Provide content and content type for maven-maven component analysis.
|
|
25
25
|
* @param {string} manifest - path to the manifest file
|
|
26
26
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
27
27
|
* @returns {Provided}
|
|
28
28
|
*/
|
|
29
|
-
provideComponent(manifest: string, opts?: {}
|
|
29
|
+
provideComponent(manifest: string, opts?: {}): Provided;
|
|
30
|
+
/**
|
|
31
|
+
* Read license from pom.xml manifest, with fallback to LICENSE file
|
|
32
|
+
* @param {string} manifestPath - path to pom.xml
|
|
33
|
+
* @returns {string|null}
|
|
34
|
+
*/
|
|
35
|
+
readLicenseFromManifest(manifestPath: string): string | null;
|
|
30
36
|
/**
|
|
31
37
|
*
|
|
32
38
|
* @param {String} textGraphList Text graph String of the manifest
|
|
33
39
|
* @param {[String]} ignoredDeps List of ignored dependencies to be omitted from sbom
|
|
40
|
+
* @param {String} manifestPath Path to the pom.xml manifest
|
|
34
41
|
* @return {String} formatted sbom Json String with all dependencies
|
|
35
42
|
*/
|
|
36
|
-
createSbomFileFromTextFormat(textGraphList: string, ignoredDeps: [string], opts: any): string;
|
|
43
|
+
createSbomFileFromTextFormat(textGraphList: string, ignoredDeps: [string], opts: any, manifestPath: string): string;
|
|
37
44
|
#private;
|
|
38
45
|
}
|
|
39
|
-
export type Java_maven = import(
|
|
40
|
-
export type Provided = import(
|
|
46
|
+
export type Java_maven = import("../provider").Provider;
|
|
47
|
+
export type Provided = import("../provider").Provided;
|
|
41
48
|
export type Package = {
|
|
42
49
|
name: string;
|
|
43
50
|
version: string;
|
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { EOL } from 'os';
|
|
5
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
6
|
+
import { getLicense } from '../license/license_utils.js';
|
|
6
7
|
import Sbom from '../sbom.js';
|
|
7
8
|
import { getCustom } from '../tools.js';
|
|
8
9
|
import Base_java, { ecosystem_maven } from "./base_java.js";
|
|
@@ -51,6 +52,30 @@ export default class Java_maven extends Base_java {
|
|
|
51
52
|
contentType: 'application/vnd.cyclonedx+json'
|
|
52
53
|
};
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Read license from pom.xml manifest, with fallback to LICENSE file
|
|
57
|
+
* @param {string} manifestPath - path to pom.xml
|
|
58
|
+
* @returns {string|null}
|
|
59
|
+
*/
|
|
60
|
+
readLicenseFromManifest(manifestPath) {
|
|
61
|
+
let fromPom = null;
|
|
62
|
+
try {
|
|
63
|
+
const xml = fs.readFileSync(manifestPath, 'utf-8');
|
|
64
|
+
const parser = new XMLParser({ ignoreAttributes: false });
|
|
65
|
+
const obj = parser.parse(xml);
|
|
66
|
+
const project = obj?.project;
|
|
67
|
+
if (project?.licenses?.license) {
|
|
68
|
+
const license = Array.isArray(project.licenses.license)
|
|
69
|
+
? project.licenses.license[0]
|
|
70
|
+
: project.licenses.license;
|
|
71
|
+
fromPom = (license?.name && license.name.trim()) || null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// leave fromPom as null
|
|
76
|
+
}
|
|
77
|
+
return getLicense(fromPom, manifestPath);
|
|
78
|
+
}
|
|
54
79
|
/**
|
|
55
80
|
* Create a Dot Graph dependency tree for a manifest path.
|
|
56
81
|
* @param {string} manifest - path for pom.xml
|
|
@@ -105,7 +130,7 @@ export default class Java_maven extends Base_java {
|
|
|
105
130
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
106
131
|
console.error("Dependency tree that will be used as input for creating the BOM =>" + EOL + EOL + content.toString());
|
|
107
132
|
}
|
|
108
|
-
let sbom = this.createSbomFileFromTextFormat(content.toString(), ignoredDeps, opts);
|
|
133
|
+
let sbom = this.createSbomFileFromTextFormat(content.toString(), ignoredDeps, opts, manifest);
|
|
109
134
|
// delete temp file and directory
|
|
110
135
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
111
136
|
// return dependency graph as string
|
|
@@ -115,15 +140,17 @@ export default class Java_maven extends Base_java {
|
|
|
115
140
|
*
|
|
116
141
|
* @param {String} textGraphList Text graph String of the manifest
|
|
117
142
|
* @param {[String]} ignoredDeps List of ignored dependencies to be omitted from sbom
|
|
143
|
+
* @param {String} manifestPath Path to the pom.xml manifest
|
|
118
144
|
* @return {String} formatted sbom Json String with all dependencies
|
|
119
145
|
*/
|
|
120
|
-
createSbomFileFromTextFormat(textGraphList, ignoredDeps, opts) {
|
|
146
|
+
createSbomFileFromTextFormat(textGraphList, ignoredDeps, opts, manifestPath) {
|
|
121
147
|
let lines = textGraphList.split(EOL);
|
|
122
148
|
// get root component
|
|
123
149
|
let root = lines[0];
|
|
124
150
|
let rootPurl = this.parseDep(root);
|
|
151
|
+
const license = this.readLicenseFromManifest(manifestPath);
|
|
125
152
|
let sbom = new Sbom();
|
|
126
|
-
sbom.addRoot(rootPurl);
|
|
153
|
+
sbom.addRoot(rootPurl, license);
|
|
127
154
|
this.parseDependencyTree(root, 0, lines.slice(1), sbom);
|
|
128
155
|
return sbom.filterIgnoredDeps(ignoredDeps).getAsJsonString(opts);
|
|
129
156
|
}
|
|
@@ -156,7 +183,8 @@ export default class Java_maven extends Base_java {
|
|
|
156
183
|
let sbom = new Sbom();
|
|
157
184
|
let rootDependency = this.#getRootFromPom(tmpEffectivePom, manifestPath);
|
|
158
185
|
let purlRoot = this.toPurl(rootDependency.groupId, rootDependency.artifactId, rootDependency.version);
|
|
159
|
-
|
|
186
|
+
const license = this.readLicenseFromManifest(manifestPath);
|
|
187
|
+
sbom.addRoot(purlRoot, license);
|
|
160
188
|
dependencies.forEach(dep => {
|
|
161
189
|
let currentPurl = this.toPurl(dep.groupId, dep.artifactId, dep.version);
|
|
162
190
|
sbom.addDependency(purlRoot, currentPurl);
|
|
@@ -209,7 +237,7 @@ export default class Java_maven extends Base_java {
|
|
|
209
237
|
let ignored = [];
|
|
210
238
|
// build xml parser with options
|
|
211
239
|
let parser = new XMLParser({
|
|
212
|
-
commentPropName: '#comment',
|
|
240
|
+
commentPropName: '#comment', // mark comments with #comment
|
|
213
241
|
isArray: (_, jpath) => 'project.dependencies.dependency' === jpath,
|
|
214
242
|
parseTagValue: false
|
|
215
243
|
});
|
|
@@ -15,13 +15,16 @@ export default class Python_controller {
|
|
|
15
15
|
realEnvironment: boolean;
|
|
16
16
|
pathToRequirements: string;
|
|
17
17
|
options: {};
|
|
18
|
+
parser: Promise<import("web-tree-sitter").Parser>;
|
|
19
|
+
requirementsQuery: Promise<import("web-tree-sitter").Query>;
|
|
20
|
+
pinnedVersionQuery: Promise<import("web-tree-sitter").Query>;
|
|
18
21
|
prepareEnvironment(): void;
|
|
19
22
|
/**
|
|
20
23
|
*
|
|
21
24
|
* @param {boolean} includeTransitive - whether to return include in returned object transitive dependencies or not
|
|
22
|
-
* @return {[DependencyEntry]}
|
|
25
|
+
* @return {Promise<[DependencyEntry]>}
|
|
23
26
|
*/
|
|
24
|
-
getDependencies(includeTransitive: boolean): [DependencyEntry]
|
|
27
|
+
getDependencies(includeTransitive: boolean): Promise<[DependencyEntry]>;
|
|
25
28
|
#private;
|
|
26
29
|
}
|
|
27
30
|
export type DependencyEntry = {
|