@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e5bb86c
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 +23 -10
- package/dist/src/analysis.d.ts +21 -5
- package/dist/src/analysis.js +74 -80
- 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 -2
- package/dist/src/cyclone_dx_sbom.js +32 -5
- package/dist/src/index.d.ts +128 -11
- package/dist/src/index.js +272 -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/oci_image/images.d.ts +4 -5
- package/dist/src/oci_image/utils.d.ts +4 -4
- package/dist/src/provider.d.ts +17 -5
- package/dist/src/provider.js +27 -5
- package/dist/src/providers/base_java.d.ts +3 -5
- 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 +147 -0
- package/dist/src/providers/base_pyproject.js +279 -0
- package/dist/src/providers/golang_gomodules.d.ts +20 -13
- 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 +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/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/python_poetry.d.ts +42 -0
- package/dist/src/providers/python_poetry.js +146 -0
- package/dist/src/providers/python_uv.d.ts +26 -0
- package/dist/src/providers/python_uv.js +118 -0
- 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 +22 -6
- 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 +24 -11
|
@@ -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;
|
|
@@ -18,25 +19,31 @@ export type Dependency = {
|
|
|
18
19
|
ignore: boolean;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
|
-
* @param {string} manifestName
|
|
22
|
-
* @returns {boolean}
|
|
23
|
-
|
|
22
|
+
* @param {string} manifestName the subject manifest name-type
|
|
23
|
+
* @returns {boolean} return true if `pom.xml` is the manifest name-type
|
|
24
|
+
*/
|
|
24
25
|
declare function isSupported(manifestName: string): boolean;
|
|
25
26
|
/**
|
|
26
|
-
* @param {string} manifestDir
|
|
27
|
+
* @param {string} manifestDir the directory where the manifest lies
|
|
27
28
|
*/
|
|
28
29
|
declare function validateLockFile(): boolean;
|
|
29
30
|
/**
|
|
30
31
|
* Provide content and content type for maven-maven component analysis.
|
|
31
|
-
* @param {string} manifest
|
|
32
|
-
* @param {{}} [opts={}]
|
|
33
|
-
* @returns {Provided}
|
|
32
|
+
* @param {string} manifest path to go.mod for component report
|
|
33
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
34
|
+
* @returns {Promise<Provided>}
|
|
34
35
|
*/
|
|
35
|
-
declare function provideComponent(manifest: string, opts?: {}
|
|
36
|
+
declare function provideComponent(manifest: string, opts?: {}): Promise<Provided>;
|
|
36
37
|
/**
|
|
37
38
|
* Provide content and content type for maven-maven stack analysis.
|
|
38
|
-
* @param {string} manifest
|
|
39
|
-
* @param {{}} [opts={}]
|
|
40
|
-
* @returns {Provided}
|
|
39
|
+
* @param {string} manifest the manifest path or name
|
|
40
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
41
|
+
* @returns {Promise<Provided>}
|
|
41
42
|
*/
|
|
42
|
-
declare function provideStack(manifest: string, opts?: {}
|
|
43
|
+
declare function provideStack(manifest: string, opts?: {}): Promise<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;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { EOL } from "os";
|
|
4
3
|
import { PackageURL } from 'packageurl-js';
|
|
4
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
5
|
import Sbom from '../sbom.js';
|
|
6
6
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
|
-
|
|
7
|
+
import { getParser, getRequireQuery } from './gomod_parser.js';
|
|
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,43 +13,50 @@ 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
|
-
* @param {string} manifestName
|
|
20
|
-
* @returns {boolean}
|
|
21
|
-
|
|
20
|
+
* @param {string} manifestName the subject manifest name-type
|
|
21
|
+
* @returns {boolean} return true if `pom.xml` is the manifest name-type
|
|
22
|
+
*/
|
|
22
23
|
function isSupported(manifestName) {
|
|
23
24
|
return 'go.mod' === manifestName;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
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); }
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} manifestDir the directory where the manifest lies
|
|
27
35
|
*/
|
|
28
36
|
function validateLockFile() { return true; }
|
|
29
37
|
/**
|
|
30
38
|
* Provide content and content type for maven-maven stack analysis.
|
|
31
|
-
* @param {string} manifest
|
|
32
|
-
* @param {{}} [opts={}]
|
|
33
|
-
* @returns {Provided}
|
|
39
|
+
* @param {string} manifest the manifest path or name
|
|
40
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
41
|
+
* @returns {Promise<Provided>}
|
|
34
42
|
*/
|
|
35
|
-
function provideStack(manifest, opts = {}) {
|
|
43
|
+
async function provideStack(manifest, opts = {}) {
|
|
36
44
|
return {
|
|
37
45
|
ecosystem,
|
|
38
|
-
content: getSBOM(manifest, opts, true),
|
|
46
|
+
content: await getSBOM(manifest, opts, true),
|
|
39
47
|
contentType: 'application/vnd.cyclonedx+json'
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
43
51
|
* Provide content and content type for maven-maven component analysis.
|
|
44
|
-
* @param {string} manifest
|
|
45
|
-
* @param {{}} [opts={}]
|
|
46
|
-
* @returns {Provided}
|
|
52
|
+
* @param {string} manifest path to go.mod for component report
|
|
53
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
54
|
+
* @returns {Promise<Provided>}
|
|
47
55
|
*/
|
|
48
|
-
function provideComponent(manifest, opts = {}) {
|
|
56
|
+
async function provideComponent(manifest, opts = {}) {
|
|
49
57
|
return {
|
|
50
58
|
ecosystem,
|
|
51
|
-
content: getSBOM(manifest, opts, false),
|
|
59
|
+
content: await getSBOM(manifest, opts, false),
|
|
52
60
|
contentType: 'application/vnd.cyclonedx+json'
|
|
53
61
|
};
|
|
54
62
|
}
|
|
@@ -69,50 +77,52 @@ function getChildVertexFromEdge(edge) {
|
|
|
69
77
|
return edge.split(" ")[1];
|
|
70
78
|
}
|
|
71
79
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
80
|
+
* Check whether a require_spec has a valid exhortignore marker.
|
|
81
|
+
* For direct dependencies: `//exhortignore` or `// exhortignore`
|
|
82
|
+
* For indirect dependencies: `// indirect; exhortignore` (semicolon-separated)
|
|
83
|
+
* @param {import('web-tree-sitter').SyntaxNode} specNode
|
|
84
|
+
* @return {boolean}
|
|
75
85
|
*/
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
function hasExhortIgnore(specNode) {
|
|
87
|
+
// Ideally this would be the following tree-sitter query instead, but for some
|
|
88
|
+
// reason it throws an error here but not in the playground.
|
|
89
|
+
// (require_spec) ((module_path) @path (version) (comment) @comment (#match? @comment "^//.*exhortignore"))
|
|
90
|
+
// QueryError: Bad pattern structure at offset 53: '(comment) @comment (#match? @comment "^//.*exhortignore")) @spec'...
|
|
91
|
+
let comments = specNode.children.filter(c => c.type === 'comment');
|
|
92
|
+
for (let comment of comments) {
|
|
93
|
+
let text = comment.text;
|
|
94
|
+
if (/^\/\/\s*indirect;\s*exhortignore/.test(text)) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (/^\/\/\s*exhortignore/.test(text)) {
|
|
98
|
+
return true;
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* extract package name from go.mod line that contains exhortignore comment.
|
|
94
|
-
* @param line a row contains exhortignore as part of a comment
|
|
95
|
-
* @return {string} the full package name + group/namespace + version
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
|
-
function extractPackageName(line) {
|
|
99
|
-
let trimmedRow = line.trim();
|
|
100
|
-
let firstRemarkNotationOccurrence = trimmedRow.indexOf("//");
|
|
101
|
-
return trimmedRow.substring(0, firstRemarkNotationOccurrence).trim();
|
|
101
|
+
return false;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
*
|
|
105
|
-
* @param {string
|
|
106
|
-
* @
|
|
105
|
+
* @param {string} manifestContent go.mod file contents
|
|
106
|
+
* @param {import('web-tree-sitter').Parser} parser
|
|
107
|
+
* @param {import('web-tree-sitter').Query} requireQuery
|
|
108
|
+
* @return {PackageURL[]} list of ignored dependencies
|
|
107
109
|
*/
|
|
108
|
-
function getIgnoredDeps(
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
function getIgnoredDeps(manifestContent, parser, requireQuery) {
|
|
111
|
+
let tree = parser.parse(manifestContent);
|
|
112
|
+
return requireQuery.matches(tree.rootNode)
|
|
113
|
+
.filter(match => {
|
|
114
|
+
let specNode = match.captures.find(c => c.name === 'spec').node;
|
|
115
|
+
return hasExhortIgnore(specNode);
|
|
116
|
+
})
|
|
117
|
+
.map(match => {
|
|
118
|
+
let name = match.captures.find(c => c.name === 'name').node.text;
|
|
119
|
+
let version = match.captures.find(c => c.name === 'version').node.text;
|
|
120
|
+
return toPurl(`${name} ${version}`, /[ ]{1,3}/);
|
|
121
|
+
});
|
|
112
122
|
}
|
|
113
123
|
/**
|
|
114
124
|
*
|
|
115
|
-
* @param {[
|
|
125
|
+
* @param {PackageURL[]} allIgnoredDeps list of purls of all dependencies that should be ignored
|
|
116
126
|
* @param {PackageURL} purl object to be checked if needed to be ignored
|
|
117
127
|
* @return {boolean}
|
|
118
128
|
*/
|
|
@@ -131,59 +141,29 @@ function enforceRemovingIgnoredDepsInCaseOfAutomaticVersionUpdate(ignoredDeps, s
|
|
|
131
141
|
}
|
|
132
142
|
/**
|
|
133
143
|
*
|
|
134
|
-
* @param {
|
|
135
|
-
* @param {
|
|
136
|
-
* @
|
|
144
|
+
* @param {string} manifestContent go.mod file contents
|
|
145
|
+
* @param {import('web-tree-sitter').Parser} parser
|
|
146
|
+
* @param {import('web-tree-sitter').Query} requireQuery
|
|
147
|
+
* @return {string[]} all dependencies from go.mod file as "name version" strings
|
|
137
148
|
*/
|
|
138
|
-
function collectAllDepsFromManifest(
|
|
139
|
-
let
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
while (requirePositionObject.index > -1) {
|
|
146
|
-
let depsInsideRequirementsBlock = currentSegmentOfGoMod.substring(requirePositionObject.index + requirePositionObject.startingOffeset).trim();
|
|
147
|
-
let endOfBlockIndex = depsInsideRequirementsBlock.indexOf(")");
|
|
148
|
-
let currentIndex = 0;
|
|
149
|
-
while (currentIndex < endOfBlockIndex) {
|
|
150
|
-
let endOfLinePosition = depsInsideRequirementsBlock.indexOf(EOL, currentIndex);
|
|
151
|
-
let dependency = depsInsideRequirementsBlock.substring(currentIndex, endOfLinePosition);
|
|
152
|
-
result.push(dependency.trim());
|
|
153
|
-
currentIndex = endOfLinePosition + 1;
|
|
154
|
-
}
|
|
155
|
-
currentSegmentOfGoMod = currentSegmentOfGoMod.substring(endOfBlockIndex + 1).trim();
|
|
156
|
-
requirePositionObject = decideRequireBlockIndex(currentSegmentOfGoMod);
|
|
157
|
-
}
|
|
158
|
-
function decideRequireBlockIndex(goMod) {
|
|
159
|
-
let object = {};
|
|
160
|
-
let index = goMod.indexOf("require(");
|
|
161
|
-
object.startingOffeset = "require(".length;
|
|
162
|
-
if (index === -1) {
|
|
163
|
-
index = goMod.indexOf("require (");
|
|
164
|
-
object.startingOffeset = "require (".length;
|
|
165
|
-
if (index === -1) {
|
|
166
|
-
index = goMod.indexOf("require (");
|
|
167
|
-
object.startingOffeset = "require (".length;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
object.index = index;
|
|
171
|
-
return object;
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
149
|
+
function collectAllDepsFromManifest(manifestContent, parser, requireQuery) {
|
|
150
|
+
let tree = parser.parse(manifestContent);
|
|
151
|
+
return requireQuery.matches(tree.rootNode).map(match => {
|
|
152
|
+
let name = match.captures.find(c => c.name === 'name').node.text;
|
|
153
|
+
let version = match.captures.find(c => c.name === 'version').node.text;
|
|
154
|
+
return `${name} ${version}`;
|
|
155
|
+
});
|
|
174
156
|
}
|
|
175
157
|
/**
|
|
176
158
|
*
|
|
177
159
|
* @param {string} rootElementName the rootElementName element of go mod graph, to compare only direct deps from go mod graph against go.mod manifest
|
|
178
|
-
* @param{[
|
|
179
|
-
* @param {string
|
|
160
|
+
* @param {string[]} goModGraphOutputRows the goModGraphOutputRows from go mod graph' output
|
|
161
|
+
* @param {string} manifestContent go.mod file contents
|
|
180
162
|
* @private
|
|
181
163
|
*/
|
|
182
|
-
function performManifestVersionsCheck(rootElementName, goModGraphOutputRows,
|
|
183
|
-
let goMod = fs.readFileSync(manifest).toString().trim();
|
|
184
|
-
let lines = goMod.split(getLineSeparatorGolang());
|
|
164
|
+
function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, manifestContent, parser, requireQuery) {
|
|
185
165
|
let comparisonLines = goModGraphOutputRows.filter((line) => line.startsWith(rootElementName)).map((line) => getChildVertexFromEdge(line));
|
|
186
|
-
let manifestDeps = collectAllDepsFromManifest(
|
|
166
|
+
let manifestDeps = collectAllDepsFromManifest(manifestContent, parser, requireQuery);
|
|
187
167
|
try {
|
|
188
168
|
comparisonLines.forEach((dependency) => {
|
|
189
169
|
let parts = dependency.split("@");
|
|
@@ -195,7 +175,7 @@ function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, man
|
|
|
195
175
|
let currentVersion = components[1];
|
|
196
176
|
if (currentDepName === depName) {
|
|
197
177
|
if (currentVersion !== version) {
|
|
198
|
-
throw new Error(`
|
|
178
|
+
throw new Error(`version mismatch for dependency "${depName}", manifest version=${currentVersion}, installed version=${version}, if you want to allow version mismatch for analysis between installed and requested packages, set environment variable/setting MATCH_MANIFEST_VERSIONS=false`);
|
|
199
179
|
}
|
|
200
180
|
}
|
|
201
181
|
});
|
|
@@ -211,10 +191,10 @@ function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, man
|
|
|
211
191
|
* @param {string} manifest - path for go.mod
|
|
212
192
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
213
193
|
* @param {boolean} includeTransitive - whether the sbom should contain transitive dependencies of the main module or not.
|
|
214
|
-
* @returns {string} the SBOM json content
|
|
194
|
+
* @returns {Promise<string>} the SBOM json content
|
|
215
195
|
* @private
|
|
216
196
|
*/
|
|
217
|
-
function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
197
|
+
async function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
218
198
|
// get custom goBin path
|
|
219
199
|
let goBin = getCustomPath('go', opts);
|
|
220
200
|
// verify goBin is accessible
|
|
@@ -240,17 +220,29 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
240
220
|
catch (error) {
|
|
241
221
|
throw new Error('failed to determine root module name', { cause: error });
|
|
242
222
|
}
|
|
243
|
-
let
|
|
223
|
+
let manifestContent = fs.readFileSync(manifest).toString();
|
|
224
|
+
let [parser, requireQuery] = await Promise.all([getParser(), getRequireQuery()]);
|
|
225
|
+
let ignoredDeps = getIgnoredDeps(manifestContent, parser, requireQuery);
|
|
244
226
|
let allIgnoredDeps = ignoredDeps.map((dep) => dep.toString());
|
|
245
227
|
let sbom = new Sbom();
|
|
246
228
|
let rows = goGraphOutput.split(getLineSeparatorGolang()).filter(line => !line.includes(' go@'));
|
|
247
|
-
let root =
|
|
229
|
+
let root = goModEditOutput['Module']['Path'];
|
|
230
|
+
// Build set of direct dependency paths from go mod edit -json
|
|
231
|
+
let directDepPaths = new Set();
|
|
232
|
+
if (goModEditOutput['Require']) {
|
|
233
|
+
goModEditOutput['Require'].forEach(req => {
|
|
234
|
+
if (!req['Indirect']) {
|
|
235
|
+
directDepPaths.add(req['Path']);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
248
239
|
let matchManifestVersions = getCustom("MATCH_MANIFEST_VERSIONS", "false", opts);
|
|
249
240
|
if (matchManifestVersions === "true") {
|
|
250
|
-
performManifestVersionsCheck(root, rows,
|
|
241
|
+
performManifestVersionsCheck(root, rows, manifestContent, parser, requireQuery);
|
|
251
242
|
}
|
|
252
243
|
const mainModule = toPurl(root, "@");
|
|
253
|
-
|
|
244
|
+
const license = readLicenseFromManifest(manifest);
|
|
245
|
+
sbom.addRoot(mainModule, license);
|
|
254
246
|
const exhortGoMvsLogicEnabled = getCustom("TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED", "true", opts);
|
|
255
247
|
if (includeTransitive && exhortGoMvsLogicEnabled === "true") {
|
|
256
248
|
rows = getFinalPackagesVersionsForModule(rows, manifest, goBin);
|
|
@@ -264,7 +256,11 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
264
256
|
currentParent = getParentVertexFromEdge(row);
|
|
265
257
|
source = toPurl(currentParent, "@");
|
|
266
258
|
}
|
|
267
|
-
let
|
|
259
|
+
let child = getChildVertexFromEdge(row);
|
|
260
|
+
let target = toPurl(child, "@");
|
|
261
|
+
if (getParentVertexFromEdge(row) === root && !directDepPaths.has(getPackageName(child))) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
268
264
|
sbom.addDependency(source, target);
|
|
269
265
|
});
|
|
270
266
|
// at the end, filter out all ignored dependencies including versions.
|
|
@@ -274,10 +270,12 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
274
270
|
else {
|
|
275
271
|
let directDependencies = rows.filter(row => row.startsWith(root));
|
|
276
272
|
directDependencies.forEach(pair => {
|
|
277
|
-
let
|
|
278
|
-
let
|
|
279
|
-
if (dependencyNotIgnored(ignoredDeps,
|
|
280
|
-
|
|
273
|
+
let child = getChildVertexFromEdge(pair);
|
|
274
|
+
let target = toPurl(child, "@");
|
|
275
|
+
if (dependencyNotIgnored(ignoredDeps, target)) {
|
|
276
|
+
if (directDepPaths.has(getPackageName(child))) {
|
|
277
|
+
sbom.addDependency(mainModule, target);
|
|
278
|
+
}
|
|
281
279
|
}
|
|
282
280
|
});
|
|
283
281
|
enforceRemovingIgnoredDepsInCaseOfAutomaticVersionUpdate(ignoredDeps, sbom);
|
|
@@ -287,7 +285,7 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
287
285
|
/**
|
|
288
286
|
* Utility function for creating Purl String
|
|
289
287
|
|
|
290
|
-
* @param {string
|
|
288
|
+
* @param {string} dependency the name of the artifact, can include a namespace(group) or not - namespace/artifactName.
|
|
291
289
|
* @param {RegExp} delimiter delimiter between name of dependency and version
|
|
292
290
|
* @private
|
|
293
291
|
* @returns {PackageURL|null} PackageUrl Object ready to be used in SBOM
|
|
@@ -312,12 +310,12 @@ function toPurl(dependency, delimiter) {
|
|
|
312
310
|
}
|
|
313
311
|
return pkg;
|
|
314
312
|
}
|
|
315
|
-
/** This function gets rows from go mod graph
|
|
313
|
+
/** This function gets rows from go mod graph, and go.mod graph, and selecting for all
|
|
316
314
|
* packages the has more than one minor the final versions as selected by golang MVS algorithm.
|
|
317
|
-
* @param {[
|
|
315
|
+
* @param {string[]} rows all the rows from go modules dependency tree
|
|
318
316
|
* @param {string} manifestPath the path of the go.mod file
|
|
319
317
|
* @param {string} path to go binary
|
|
320
|
-
* @return {[
|
|
318
|
+
* @return {string[]} rows that contains final versions.
|
|
321
319
|
*/
|
|
322
320
|
function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
323
321
|
let manifestDir = path.dirname(manifestPath);
|
|
@@ -372,7 +370,7 @@ function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
|
372
370
|
/**
|
|
373
371
|
*
|
|
374
372
|
* @param {string} fullPackage - full package with its name and version
|
|
375
|
-
* @return
|
|
373
|
+
* @return {string} package name only
|
|
376
374
|
* @private
|
|
377
375
|
*/
|
|
378
376
|
function getPackageName(fullPackage) {
|
|
@@ -390,7 +388,7 @@ function isSpecialGoModule(moduleName) {
|
|
|
390
388
|
/**
|
|
391
389
|
*
|
|
392
390
|
* @param {string} fullPackage - full package with its name and version
|
|
393
|
-
* @return
|
|
391
|
+
* @return {string|undefined} package version only
|
|
394
392
|
* @private
|
|
395
393
|
*/
|
|
396
394
|
function getVersionOfPackage(fullPackage) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
+
const wasmUrl = new URL('./tree-sitter-gomod.wasm', import.meta.url);
|
|
4
|
+
async function init() {
|
|
5
|
+
await Parser.init();
|
|
6
|
+
const wasmBytes = new Uint8Array(await readFile(wasmUrl));
|
|
7
|
+
return await Language.load(wasmBytes);
|
|
8
|
+
}
|
|
9
|
+
export async function getParser() {
|
|
10
|
+
const language = await init();
|
|
11
|
+
return new Parser().setLanguage(language);
|
|
12
|
+
}
|
|
13
|
+
export async function getRequireQuery() {
|
|
14
|
+
const language = await init();
|
|
15
|
+
return new Query(language, '(require_spec (module_path) @name (version) @version) @spec');
|
|
16
|
+
}
|
|
@@ -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;
|