@trustify-da/trustify-da-javascript-client 0.3.0-ea.a8c3942 → 0.3.0-ea.aaf5191
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 +177 -3
- package/dist/package.json +30 -22
- package/dist/src/analysis.d.ts +14 -7
- package/dist/src/analysis.js +29 -13
- package/dist/src/cli.js +106 -2
- package/dist/src/cyclone_dx_sbom.d.ts +13 -0
- package/dist/src/cyclone_dx_sbom.js +50 -4
- package/dist/src/index.d.ts +14 -10
- package/dist/src/index.js +17 -27
- package/dist/src/license/index.d.ts +3 -3
- package/dist/src/license/index.js +4 -1
- package/dist/src/license/license_utils.js +4 -1
- package/dist/src/license/licenses_api.d.ts +2 -2
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +4 -3
- package/dist/src/provider.js +6 -2
- package/dist/src/providers/base_java.d.ts +67 -3
- package/dist/src/providers/base_java.js +80 -23
- package/dist/src/providers/base_javascript.d.ts +74 -9
- package/dist/src/providers/base_javascript.js +115 -6
- package/dist/src/providers/base_pyproject.d.ts +10 -5
- package/dist/src/providers/base_pyproject.js +7 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +2 -1
- package/dist/src/providers/golang_gomodules.js +50 -8
- package/dist/src/providers/java_gradle.d.ts +48 -0
- package/dist/src/providers/java_gradle.js +196 -18
- 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 +29 -9
- package/dist/src/providers/java_maven.js +176 -10
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -1
- package/dist/src/providers/javascript_npm.js +40 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +47 -1
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.js +6 -3
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +3 -2
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.js +61 -4
- package/dist/src/providers/python_pip.d.ts +1 -0
- package/dist/src/providers/python_pip.js +1 -1
- package/dist/src/providers/python_poetry.d.ts +31 -8
- package/dist/src/providers/python_poetry.js +62 -14
- package/dist/src/providers/python_uv.d.ts +5 -14
- package/dist/src/providers/python_uv.js +44 -2
- package/dist/src/providers/requirements_parser.js +1 -1
- package/dist/src/providers/rust_cargo.d.ts +6 -2
- package/dist/src/providers/rust_cargo.js +101 -33
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +11 -0
- package/dist/src/sbom.js +10 -0
- package/dist/src/tools.d.ts +2 -2
- package/dist/src/tools.js +24 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/package.json +31 -23
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export default class Python_poetry extends Base_pyproject {
|
|
2
|
+
_verifyPoetryAccessible(poetryBin: any): void;
|
|
2
3
|
/**
|
|
3
4
|
* @param {string} manifestDir
|
|
4
5
|
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
@@ -6,7 +7,7 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
6
7
|
* @param {Object} opts
|
|
7
8
|
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
8
9
|
*/
|
|
9
|
-
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts:
|
|
10
|
+
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts: Object): Promise<{
|
|
10
11
|
directDeps: string[];
|
|
11
12
|
graph: Map<string, {
|
|
12
13
|
name: string;
|
|
@@ -18,17 +19,17 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
18
19
|
* Get poetry show --tree output.
|
|
19
20
|
* @param {string} manifestDir
|
|
20
21
|
* @param {boolean} hasDevGroup
|
|
21
|
-
* @param {
|
|
22
|
+
* @param {string} poetryBin
|
|
22
23
|
* @returns {string}
|
|
23
24
|
*/
|
|
24
|
-
_getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean,
|
|
25
|
+
_getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, poetryBin: string): string;
|
|
25
26
|
/**
|
|
26
27
|
* Get poetry show --all output (flat list with resolved versions).
|
|
27
28
|
* @param {string} manifestDir
|
|
28
|
-
* @param {
|
|
29
|
+
* @param {string} poetryBin
|
|
29
30
|
* @returns {string}
|
|
30
31
|
*/
|
|
31
|
-
_getPoetryShowAllOutput(manifestDir: string,
|
|
32
|
+
_getPoetryShowAllOutput(manifestDir: string, poetryBin: string): string;
|
|
32
33
|
/**
|
|
33
34
|
* Parse poetry show --all output into a version map.
|
|
34
35
|
* Lines look like: "name (!) 1.2.3 Description text..."
|
|
@@ -46,29 +47,51 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
46
47
|
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
47
48
|
* @param {string|null} lockDir
|
|
48
49
|
* @param {object} parsed - parsed pyproject.toml
|
|
49
|
-
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
|
|
50
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}}
|
|
50
51
|
*/
|
|
51
52
|
_extractMarkerData(lockDir: string | null, parsed: object): {
|
|
52
53
|
directMarkers: Map<string, string>;
|
|
53
54
|
transitiveMarkers: Map<string, Map<string, string>>;
|
|
55
|
+
hashMap: Map<string, Array<{
|
|
56
|
+
alg: string;
|
|
57
|
+
content: string;
|
|
58
|
+
}>>;
|
|
54
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Extract a SHA-256 hex digest from poetry.lock files array.
|
|
62
|
+
* Prefers the sdist (.tar.gz) hash; falls back to the first wheel hash.
|
|
63
|
+
* @param {Array<{file: string, hash: string}>} [files]
|
|
64
|
+
* @returns {string|null}
|
|
65
|
+
*/
|
|
66
|
+
_extractSha256FromFiles(files?: Array<{
|
|
67
|
+
file: string;
|
|
68
|
+
hash: string;
|
|
69
|
+
}>): string | null;
|
|
55
70
|
/**
|
|
56
71
|
* Parse poetry show --tree output into a dependency graph structure.
|
|
57
72
|
*
|
|
58
73
|
* @param {string} treeOutput
|
|
59
74
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
60
|
-
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
|
|
61
|
-
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
75
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}} markerData
|
|
76
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}>}}
|
|
62
77
|
*/
|
|
63
78
|
_parsePoetryTree(treeOutput: string, versionMap: Map<string, string>, markerData: {
|
|
64
79
|
directMarkers: Map<string, string>;
|
|
65
80
|
transitiveMarkers: Map<string, Map<string, string>>;
|
|
81
|
+
hashMap: Map<string, Array<{
|
|
82
|
+
alg: string;
|
|
83
|
+
content: string;
|
|
84
|
+
}>>;
|
|
66
85
|
}): {
|
|
67
86
|
directDeps: string[];
|
|
68
87
|
graph: Map<string, {
|
|
69
88
|
name: string;
|
|
70
89
|
version: string;
|
|
71
90
|
children: string[];
|
|
91
|
+
hashes?: Array<{
|
|
92
|
+
alg: string;
|
|
93
|
+
content: string;
|
|
94
|
+
}>;
|
|
72
95
|
}>;
|
|
73
96
|
};
|
|
74
97
|
}
|
|
@@ -32,6 +32,17 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
32
32
|
_cmdName() {
|
|
33
33
|
return 'poetry';
|
|
34
34
|
}
|
|
35
|
+
_verifyPoetryAccessible(poetryBin) {
|
|
36
|
+
try {
|
|
37
|
+
invokeCommand(poetryBin, ['--version']);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code === 'ENOENT') {
|
|
41
|
+
throw new Error(`poetry is not accessible at "${poetryBin}"`, { cause: error });
|
|
42
|
+
}
|
|
43
|
+
throw new Error('failed to check for poetry binary', { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
35
46
|
/**
|
|
36
47
|
* @param {string} manifestDir
|
|
37
48
|
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
@@ -41,9 +52,15 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
41
52
|
*/
|
|
42
53
|
// eslint-disable-next-line no-unused-vars
|
|
43
54
|
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
55
|
+
let poetryBin = getCustomPath('poetry', opts);
|
|
56
|
+
let envBypass = environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')
|
|
57
|
+
&& environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL');
|
|
58
|
+
if (!envBypass) {
|
|
59
|
+
this._verifyPoetryAccessible(poetryBin);
|
|
60
|
+
}
|
|
44
61
|
let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
|
|
45
|
-
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup,
|
|
46
|
-
let showAllOutput = this._getPoetryShowAllOutput(manifestDir,
|
|
62
|
+
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, poetryBin);
|
|
63
|
+
let showAllOutput = this._getPoetryShowAllOutput(manifestDir, poetryBin);
|
|
47
64
|
let versionMap = this._parsePoetryShowAll(showAllOutput);
|
|
48
65
|
let lockDir = this._findLockFileDir(manifestDir, opts);
|
|
49
66
|
let markerData = this._extractMarkerData(lockDir, parsed);
|
|
@@ -53,14 +70,13 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
53
70
|
* Get poetry show --tree output.
|
|
54
71
|
* @param {string} manifestDir
|
|
55
72
|
* @param {boolean} hasDevGroup
|
|
56
|
-
* @param {
|
|
73
|
+
* @param {string} poetryBin
|
|
57
74
|
* @returns {string}
|
|
58
75
|
*/
|
|
59
|
-
_getPoetryShowTreeOutput(manifestDir, hasDevGroup,
|
|
76
|
+
_getPoetryShowTreeOutput(manifestDir, hasDevGroup, poetryBin) {
|
|
60
77
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
|
|
61
78
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
|
|
62
79
|
}
|
|
63
|
-
let poetryBin = getCustomPath('poetry', opts);
|
|
64
80
|
let args = ['show', '--tree', '--no-ansi'];
|
|
65
81
|
if (hasDevGroup) {
|
|
66
82
|
args.push('--without', 'dev');
|
|
@@ -70,14 +86,13 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
70
86
|
/**
|
|
71
87
|
* Get poetry show --all output (flat list with resolved versions).
|
|
72
88
|
* @param {string} manifestDir
|
|
73
|
-
* @param {
|
|
89
|
+
* @param {string} poetryBin
|
|
74
90
|
* @returns {string}
|
|
75
91
|
*/
|
|
76
|
-
_getPoetryShowAllOutput(manifestDir,
|
|
92
|
+
_getPoetryShowAllOutput(manifestDir, poetryBin) {
|
|
77
93
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
|
|
78
94
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
|
|
79
95
|
}
|
|
80
|
-
let poetryBin = getCustomPath('poetry', opts);
|
|
81
96
|
return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
|
|
82
97
|
}
|
|
83
98
|
/**
|
|
@@ -111,11 +126,12 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
111
126
|
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
112
127
|
* @param {string|null} lockDir
|
|
113
128
|
* @param {object} parsed - parsed pyproject.toml
|
|
114
|
-
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
|
|
129
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}}
|
|
115
130
|
*/
|
|
116
131
|
_extractMarkerData(lockDir, parsed) {
|
|
117
132
|
let directMarkers = new Map();
|
|
118
133
|
let transitiveMarkers = new Map();
|
|
134
|
+
let hashMap = new Map();
|
|
119
135
|
// Extract markers from PEP 621 dependency strings: "name[extras]>=ver ; marker"
|
|
120
136
|
let deps = parsed.project?.dependencies || [];
|
|
121
137
|
for (let dep of deps) {
|
|
@@ -142,18 +158,40 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
142
158
|
transitiveMarkers.get(pkgKey).set(this._canonicalize(depName), markers);
|
|
143
159
|
}
|
|
144
160
|
}
|
|
161
|
+
let sha256Hex = this._extractSha256FromFiles(pkg.files);
|
|
162
|
+
if (sha256Hex) {
|
|
163
|
+
hashMap.set(pkgKey, [{ alg: "SHA-256", content: sha256Hex }]);
|
|
164
|
+
}
|
|
145
165
|
}
|
|
146
166
|
}
|
|
147
167
|
}
|
|
148
|
-
return { directMarkers, transitiveMarkers };
|
|
168
|
+
return { directMarkers, transitiveMarkers, hashMap };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Extract a SHA-256 hex digest from poetry.lock files array.
|
|
172
|
+
* Prefers the sdist (.tar.gz) hash; falls back to the first wheel hash.
|
|
173
|
+
* @param {Array<{file: string, hash: string}>} [files]
|
|
174
|
+
* @returns {string|null}
|
|
175
|
+
*/
|
|
176
|
+
_extractSha256FromFiles(files) {
|
|
177
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
let sdist = files.find(f => f.file.endsWith('.tar.gz'));
|
|
181
|
+
let entry = sdist || files[0];
|
|
182
|
+
let hash = entry.hash;
|
|
183
|
+
if (hash && hash.startsWith('sha256:')) {
|
|
184
|
+
return hash.slice(7);
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
149
187
|
}
|
|
150
188
|
/**
|
|
151
189
|
* Parse poetry show --tree output into a dependency graph structure.
|
|
152
190
|
*
|
|
153
191
|
* @param {string} treeOutput
|
|
154
192
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
155
|
-
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
|
|
156
|
-
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
193
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}} markerData
|
|
194
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}>}}
|
|
157
195
|
*/
|
|
158
196
|
_parsePoetryTree(treeOutput, versionMap, markerData) {
|
|
159
197
|
let lines = treeOutput.split(/\r?\n/);
|
|
@@ -179,7 +217,12 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
179
217
|
}
|
|
180
218
|
directDeps.push(key);
|
|
181
219
|
if (!graph.has(key)) {
|
|
182
|
-
|
|
220
|
+
let entry = { name, version, children: [] };
|
|
221
|
+
let hashes = markerData.hashMap.get(key);
|
|
222
|
+
if (hashes) {
|
|
223
|
+
entry.hashes = hashes;
|
|
224
|
+
}
|
|
225
|
+
graph.set(key, entry);
|
|
183
226
|
}
|
|
184
227
|
currentDirectDep = key;
|
|
185
228
|
stack = [{ key, depth: -1 }];
|
|
@@ -223,7 +266,12 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
223
266
|
throw new Error(`poetry: package '${depName}' has no resolved version`);
|
|
224
267
|
}
|
|
225
268
|
if (!graph.has(depKey)) {
|
|
226
|
-
|
|
269
|
+
let entry = { name: depName, version, children: [] };
|
|
270
|
+
let hashes = markerData.hashMap.get(depKey);
|
|
271
|
+
if (hashes) {
|
|
272
|
+
entry.hashes = hashes;
|
|
273
|
+
}
|
|
274
|
+
graph.set(depKey, entry);
|
|
227
275
|
}
|
|
228
276
|
if (parentKey) {
|
|
229
277
|
let parentEntry = graph.get(parentKey);
|
|
@@ -13,27 +13,18 @@ export function discoverUvWorkspaceMembers(workspaceRoot: string, opts?: {
|
|
|
13
13
|
}): Promise<string[]>;
|
|
14
14
|
export default class Python_uv extends Base_pyproject {
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {string}
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {Object} opts
|
|
20
|
-
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
16
|
+
* Parse uv.lock and attach SHA-256 hashes to graph entries.
|
|
17
|
+
* @param {string} lockFilePath - path to uv.lock
|
|
18
|
+
* @param {Map<string, import('./base_pyproject.js').GraphEntry>} graph
|
|
21
19
|
*/
|
|
22
|
-
|
|
23
|
-
directDeps: string[];
|
|
24
|
-
graph: Map<string, {
|
|
25
|
-
name: string;
|
|
26
|
-
version: string;
|
|
27
|
-
children: string[];
|
|
28
|
-
}>;
|
|
29
|
-
}>;
|
|
20
|
+
_attachHashesFromLockFile(lockFilePath: string, graph: Map<string, import("./base_pyproject.js").GraphEntry>): Promise<void>;
|
|
30
21
|
/**
|
|
31
22
|
* Get the uv export output, either from env var or by running the command.
|
|
32
23
|
* @param {string} manifestDir
|
|
33
24
|
* @param {Object} opts
|
|
34
25
|
* @returns {string}
|
|
35
26
|
*/
|
|
36
|
-
_getUvExportOutput(manifestDir: string, opts:
|
|
27
|
+
_getUvExportOutput(manifestDir: string, opts: Object): string;
|
|
37
28
|
/**
|
|
38
29
|
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
39
30
|
* for package/version extraction and string parsing for "# via" comments.
|
|
@@ -21,12 +21,54 @@ export default class Python_uv extends Base_pyproject {
|
|
|
21
21
|
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
22
22
|
* @param {object} parsed - parsed pyproject.toml
|
|
23
23
|
* @param {Object} opts
|
|
24
|
-
* @returns {Promise<{directDeps: string[], graph: Map<string,
|
|
24
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, import('./base_pyproject.js').GraphEntry>}>}
|
|
25
25
|
*/
|
|
26
26
|
async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
|
|
27
27
|
let projectName = this._getProjectName(parsed);
|
|
28
28
|
let uvOutput = this._getUvExportOutput(manifestDir, opts);
|
|
29
|
-
|
|
29
|
+
let { directDeps, graph } = await this._parseUvExport(uvOutput, projectName, workspaceDir);
|
|
30
|
+
await this._attachHashesFromLockFile(path.join(workspaceDir, 'uv.lock'), graph);
|
|
31
|
+
return { directDeps, graph };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse uv.lock and attach SHA-256 hashes to graph entries.
|
|
35
|
+
* @param {string} lockFilePath - path to uv.lock
|
|
36
|
+
* @param {Map<string, import('./base_pyproject.js').GraphEntry>} graph
|
|
37
|
+
*/
|
|
38
|
+
async _attachHashesFromLockFile(lockFilePath, graph) {
|
|
39
|
+
let lockContent;
|
|
40
|
+
try {
|
|
41
|
+
lockContent = await fs.promises.readFile(lockFilePath, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = parseToml(lockContent);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let packages = parsed.package;
|
|
54
|
+
if (!Array.isArray(packages)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (let pkg of packages) {
|
|
58
|
+
if (!pkg.name) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let hashStr = pkg.sdist?.hash || pkg.wheels?.[0]?.hash;
|
|
62
|
+
if (!hashStr || !hashStr.startsWith('sha256:')) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let key = this._canonicalize(pkg.name);
|
|
66
|
+
let entry = graph.get(key);
|
|
67
|
+
if (!entry || entry.hashes) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
entry.hashes = [{ alg: "SHA-256", content: hashStr.slice(7) }];
|
|
71
|
+
}
|
|
30
72
|
}
|
|
31
73
|
/**
|
|
32
74
|
* Get the uv export output, either from env var or by running the command.
|
|
@@ -16,7 +16,7 @@ export async function getRequirementQuery() {
|
|
|
16
16
|
}
|
|
17
17
|
export async function getIgnoreQuery() {
|
|
18
18
|
const language = await init();
|
|
19
|
-
return new Query(language, '((requirement (package) @name) @req . (comment) @comment (#match? @comment "^#[\\t ]*exhortignore"))');
|
|
19
|
+
return new Query(language, '((requirement (package) @name) @req . (comment) @comment (#match? @comment "^#[\\t ]*(exhortignore|trustify-da-ignore)(?![\\w-])"))');
|
|
20
20
|
}
|
|
21
21
|
export async function getPinnedVersionQuery() {
|
|
22
22
|
const language = await init();
|
|
@@ -4,9 +4,10 @@ declare namespace _default {
|
|
|
4
4
|
export { provideComponent };
|
|
5
5
|
export { provideStack };
|
|
6
6
|
export { readLicenseFromManifest };
|
|
7
|
+
export function packageManagerName(): string;
|
|
7
8
|
}
|
|
8
9
|
export default _default;
|
|
9
|
-
export type Provided =
|
|
10
|
+
export type Provided = any;
|
|
10
11
|
/**
|
|
11
12
|
* @param {string} manifestName - the subject manifest name-type
|
|
12
13
|
* @returns {boolean} - return true if `Cargo.toml` is the manifest name-type
|
|
@@ -46,7 +47,10 @@ declare function provideStack(manifest: string, opts?: {}): Provided;
|
|
|
46
47
|
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
47
48
|
* Supports the `license` field under `[package]` (single crate / workspace
|
|
48
49
|
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
50
|
+
* When a member crate uses `license = { workspace = true }`, the actual
|
|
51
|
+
* license is resolved from the workspace root Cargo.toml.
|
|
49
52
|
* @param {string} manifestPath - path to Cargo.toml
|
|
53
|
+
* @param {object} [metadata] - cargo metadata output (needed for workspace license resolution)
|
|
50
54
|
* @returns {string|null} SPDX identifier or null
|
|
51
55
|
*/
|
|
52
|
-
declare function readLicenseFromManifest(manifestPath: string): string | null;
|
|
56
|
+
declare function readLicenseFromManifest(manifestPath: string, metadata?: object): string | null;
|
|
@@ -5,7 +5,7 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
5
5
|
import { getLicense } from '../license/license_utils.js';
|
|
6
6
|
import Sbom from '../sbom.js';
|
|
7
7
|
import { getCustom, getCustomPath, invokeCommand } from '../tools.js';
|
|
8
|
-
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
8
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest, packageManagerName() { return 'cargo'; } };
|
|
9
9
|
/** @typedef {import('../provider').Provider} */
|
|
10
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
11
11
|
/**
|
|
@@ -71,15 +71,22 @@ function isSupported(manifestName) {
|
|
|
71
71
|
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
72
72
|
* Supports the `license` field under `[package]` (single crate / workspace
|
|
73
73
|
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
74
|
+
* When a member crate uses `license = { workspace = true }`, the actual
|
|
75
|
+
* license is resolved from the workspace root Cargo.toml.
|
|
74
76
|
* @param {string} manifestPath - path to Cargo.toml
|
|
77
|
+
* @param {object} [metadata] - cargo metadata output (needed for workspace license resolution)
|
|
75
78
|
* @returns {string|null} SPDX identifier or null
|
|
76
79
|
*/
|
|
77
|
-
function readLicenseFromManifest(manifestPath) {
|
|
80
|
+
function readLicenseFromManifest(manifestPath, metadata) {
|
|
78
81
|
let fromManifest = null;
|
|
79
82
|
try {
|
|
80
83
|
let content = fs.readFileSync(manifestPath, 'utf-8');
|
|
81
84
|
let parsed = parseToml(content);
|
|
82
|
-
|
|
85
|
+
let packageLicense = parsed.package?.license;
|
|
86
|
+
if (typeof packageLicense === 'object' && packageLicense?.workspace === true) {
|
|
87
|
+
packageLicense = resolveWorkspaceLicense(parsed, metadata);
|
|
88
|
+
}
|
|
89
|
+
fromManifest = packageLicense
|
|
83
90
|
|| parsed.workspace?.package?.license
|
|
84
91
|
|| null;
|
|
85
92
|
}
|
|
@@ -89,30 +96,45 @@ function readLicenseFromManifest(manifestPath) {
|
|
|
89
96
|
return getLicense(fromManifest, manifestPath);
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
* Resolve a workspace-inherited license from the workspace root Cargo.toml.
|
|
100
|
+
* @param {object} parsed - the parsed member crate Cargo.toml
|
|
101
|
+
* @param {object} [metadata] - cargo metadata output with workspace_root
|
|
102
|
+
* @returns {string|null} resolved license string or null
|
|
103
|
+
*/
|
|
104
|
+
function resolveWorkspaceLicense(parsed, metadata) {
|
|
105
|
+
if (metadata?.workspace_root) {
|
|
106
|
+
let cargoTomlPath = path.join(metadata.workspace_root, 'Cargo.toml');
|
|
107
|
+
try {
|
|
108
|
+
let content = fs.readFileSync(cargoTomlPath, 'utf-8');
|
|
109
|
+
let workspaceParsed = parseToml(content);
|
|
110
|
+
return workspaceParsed.workspace?.package?.license || null;
|
|
111
|
+
}
|
|
112
|
+
catch (_) {
|
|
113
|
+
// fall through
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return parsed.workspace?.package?.license || null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Finds the directory containing Cargo.lock, honoring TRUSTIFY_DA_WORKSPACE_DIR.
|
|
120
|
+
* Walks up from manifestDir looking for Cargo.lock, stopping at workspace root or filesystem root.
|
|
100
121
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
101
122
|
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
102
|
-
* @returns {
|
|
123
|
+
* @returns {string|null} the directory path containing Cargo.lock, or null if not found
|
|
124
|
+
* @private
|
|
103
125
|
*/
|
|
104
|
-
function
|
|
126
|
+
function _findCargoLockDir(manifestDir, opts = {}) {
|
|
105
127
|
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
106
128
|
if (workspaceDir) {
|
|
107
129
|
const dir = path.resolve(workspaceDir);
|
|
108
|
-
return fs.existsSync(path.join(dir, 'Cargo.lock'));
|
|
130
|
+
return fs.existsSync(path.join(dir, 'Cargo.lock')) ? dir : null;
|
|
109
131
|
}
|
|
110
132
|
let dir = path.resolve(manifestDir);
|
|
111
133
|
let parent = dir;
|
|
112
134
|
do {
|
|
113
135
|
dir = parent;
|
|
114
136
|
if (fs.existsSync(path.join(dir, 'Cargo.lock'))) {
|
|
115
|
-
return
|
|
137
|
+
return dir;
|
|
116
138
|
}
|
|
117
139
|
// If this directory has a Cargo.toml with [workspace], the lock file
|
|
118
140
|
// should have been here — stop searching.
|
|
@@ -121,7 +143,7 @@ function validateLockFile(manifestDir, opts = {}) {
|
|
|
121
143
|
try {
|
|
122
144
|
let content = fs.readFileSync(cargoToml, 'utf-8');
|
|
123
145
|
if (/\[workspace\]/.test(content)) {
|
|
124
|
-
return
|
|
146
|
+
return null;
|
|
125
147
|
}
|
|
126
148
|
}
|
|
127
149
|
catch (_) {
|
|
@@ -130,7 +152,23 @@ function validateLockFile(manifestDir, opts = {}) {
|
|
|
130
152
|
}
|
|
131
153
|
parent = path.dirname(dir);
|
|
132
154
|
} while (parent !== dir);
|
|
133
|
-
return
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validates that Cargo.lock exists in the manifest directory or in a parent
|
|
159
|
+
* workspace root directory. In Cargo workspaces the lock file always lives at
|
|
160
|
+
* the workspace root, so when a member crate's Cargo.toml is provided we walk
|
|
161
|
+
* up the directory tree looking for Cargo.lock (stopping when we find a
|
|
162
|
+
* Cargo.toml that contains a [workspace] section, or when we reach the
|
|
163
|
+
* filesystem root).
|
|
164
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
|
|
165
|
+
* checks only that directory for Cargo.lock — no walk-up.
|
|
166
|
+
* @param {string} manifestDir - the directory where the manifest lies
|
|
167
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
168
|
+
* @returns {boolean} true if Cargo.lock is found
|
|
169
|
+
*/
|
|
170
|
+
function validateLockFile(manifestDir, opts = {}) {
|
|
171
|
+
return _findCargoLockDir(manifestDir, opts) !== null;
|
|
134
172
|
}
|
|
135
173
|
/**
|
|
136
174
|
* Provide content and content type for Cargo stack analysis.
|
|
@@ -173,13 +211,14 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
173
211
|
let metadata = executeCargoMetadata(cargoBin, manifestDir);
|
|
174
212
|
let ignoredDeps = getIgnoredDeps(manifest, metadata);
|
|
175
213
|
let crateType = detectCrateType(metadata);
|
|
176
|
-
let license = readLicenseFromManifest(manifest);
|
|
214
|
+
let license = readLicenseFromManifest(manifest, metadata);
|
|
215
|
+
let hashMap = parseCargoLockHashes(manifestDir, opts);
|
|
177
216
|
let sbom;
|
|
178
217
|
if (crateType === CrateType.WORKSPACE_VIRTUAL) {
|
|
179
|
-
sbom = handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransitive, opts, license);
|
|
218
|
+
sbom = handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransitive, opts, license, hashMap);
|
|
180
219
|
}
|
|
181
220
|
else {
|
|
182
|
-
sbom = handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, license);
|
|
221
|
+
sbom = handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, license, hashMap);
|
|
183
222
|
}
|
|
184
223
|
return sbom;
|
|
185
224
|
}
|
|
@@ -217,6 +256,34 @@ function executeCargoMetadata(cargoBin, manifestDir) {
|
|
|
217
256
|
throw new Error('failed to execute cargo metadata', { cause: error });
|
|
218
257
|
}
|
|
219
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Parses Cargo.lock to extract SHA-256 checksums for each package.
|
|
261
|
+
* @param {string} manifestDir - directory containing Cargo.toml (Cargo.lock is searched upward)
|
|
262
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
263
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} map of "name@version" to CycloneDX hashes
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
function parseCargoLockHashes(manifestDir, opts = {}) {
|
|
267
|
+
let hashMap = new Map();
|
|
268
|
+
let lockDir = _findCargoLockDir(manifestDir, opts);
|
|
269
|
+
if (!lockDir) {
|
|
270
|
+
return hashMap;
|
|
271
|
+
}
|
|
272
|
+
let lockPath = path.join(lockDir, 'Cargo.lock');
|
|
273
|
+
try {
|
|
274
|
+
let content = fs.readFileSync(lockPath, 'utf-8');
|
|
275
|
+
let parsed = parseToml(content);
|
|
276
|
+
for (let pkg of (parsed.package || [])) {
|
|
277
|
+
if (pkg.name && pkg.version && pkg.checksum) {
|
|
278
|
+
hashMap.set(`${pkg.name}@${pkg.version}`, [{ alg: 'SHA-256', content: pkg.checksum }]);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
console.warn('Failed to parse Cargo.lock for hashes, SBOM will be generated without hashes');
|
|
284
|
+
}
|
|
285
|
+
return hashMap;
|
|
286
|
+
}
|
|
220
287
|
/**
|
|
221
288
|
* Detects the type of Cargo project from metadata.
|
|
222
289
|
* @param {object} metadata - parsed cargo metadata
|
|
@@ -248,7 +315,7 @@ function detectCrateType(metadata) {
|
|
|
248
315
|
* @returns {string} SBOM json string
|
|
249
316
|
* @private
|
|
250
317
|
*/
|
|
251
|
-
function handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, license) {
|
|
318
|
+
function handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, license, hashMap) {
|
|
252
319
|
let rootPackageId = metadata.resolve.root;
|
|
253
320
|
let rootPackage = findPackageById(metadata, rootPackageId);
|
|
254
321
|
let rootPurl = toPurl(rootPackage.name, rootPackage.version);
|
|
@@ -259,10 +326,10 @@ function handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, licen
|
|
|
259
326
|
return sbom.getAsJsonString(opts);
|
|
260
327
|
}
|
|
261
328
|
if (includeTransitive) {
|
|
262
|
-
addTransitiveDeps(sbom, metadata, rootPackageId, ignoredDeps, new Set(), rootPurl);
|
|
329
|
+
addTransitiveDeps(sbom, metadata, rootPackageId, ignoredDeps, new Set(), hashMap, rootPurl);
|
|
263
330
|
}
|
|
264
331
|
else {
|
|
265
|
-
addDirectDeps(sbom, metadata, rootPackageId, rootPurl, ignoredDeps);
|
|
332
|
+
addDirectDeps(sbom, metadata, rootPackageId, rootPurl, ignoredDeps, hashMap);
|
|
266
333
|
}
|
|
267
334
|
return sbom.getAsJsonString(opts);
|
|
268
335
|
}
|
|
@@ -288,7 +355,7 @@ function handleSingleCrate(metadata, ignoredDeps, includeTransitive, opts, licen
|
|
|
288
355
|
* @returns {string} SBOM json string
|
|
289
356
|
* @private
|
|
290
357
|
*/
|
|
291
|
-
function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransitive, opts, license) {
|
|
358
|
+
function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransitive, opts, license, hashMap) {
|
|
292
359
|
let workspaceRoot = metadata.workspace_root;
|
|
293
360
|
let rootName = path.basename(workspaceRoot);
|
|
294
361
|
let workspaceVersion = getWorkspaceVersion(metadata);
|
|
@@ -296,7 +363,6 @@ function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransiti
|
|
|
296
363
|
let sbom = new Sbom();
|
|
297
364
|
sbom.addRoot(rootPurl, license);
|
|
298
365
|
if (includeTransitive) {
|
|
299
|
-
// Stack analysis: walk all members and their full dependency trees
|
|
300
366
|
let workspaceMembers = metadata.workspace_members || [];
|
|
301
367
|
for (let memberId of workspaceMembers) {
|
|
302
368
|
let memberPackage = findPackageById(metadata, memberId);
|
|
@@ -307,11 +373,10 @@ function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransiti
|
|
|
307
373
|
? toPathDepPurl(memberPackage.name, memberPackage.version)
|
|
308
374
|
: toPurl(memberPackage.name, memberPackage.version);
|
|
309
375
|
sbom.addDependency(rootPurl, memberPurl);
|
|
310
|
-
addTransitiveDeps(sbom, metadata, memberId, ignoredDeps, new Set(), memberPurl);
|
|
376
|
+
addTransitiveDeps(sbom, metadata, memberId, ignoredDeps, new Set(), hashMap, memberPurl);
|
|
311
377
|
}
|
|
312
378
|
}
|
|
313
379
|
else {
|
|
314
|
-
// Component analysis: only [workspace.dependencies] from root Cargo.toml
|
|
315
380
|
let workspaceDeps = getWorkspaceDepsFromManifest(manifest);
|
|
316
381
|
for (let depName of workspaceDeps) {
|
|
317
382
|
if (isDepIgnored(depName, ignoredDeps)) {
|
|
@@ -328,7 +393,8 @@ function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransiti
|
|
|
328
393
|
let depPurl = pkg.source == null
|
|
329
394
|
? toPathDepPurl(pkg.name, pkg.version)
|
|
330
395
|
: toPurl(pkg.name, pkg.version);
|
|
331
|
-
|
|
396
|
+
let hashes = hashMap.get(`${pkg.name}@${pkg.version}`);
|
|
397
|
+
sbom.addDependency(rootPurl, depPurl, undefined, hashes);
|
|
332
398
|
}
|
|
333
399
|
}
|
|
334
400
|
return sbom.getAsJsonString(opts);
|
|
@@ -347,7 +413,7 @@ function handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransiti
|
|
|
347
413
|
* so callers can ensure it matches the purl already added to the SBOM
|
|
348
414
|
* @private
|
|
349
415
|
*/
|
|
350
|
-
function addTransitiveDeps(sbom, metadata, packageId, ignoredDeps, visited, startingPurl) {
|
|
416
|
+
function addTransitiveDeps(sbom, metadata, packageId, ignoredDeps, visited, hashMap, startingPurl) {
|
|
351
417
|
if (visited.has(packageId)) {
|
|
352
418
|
return;
|
|
353
419
|
}
|
|
@@ -375,8 +441,9 @@ function addTransitiveDeps(sbom, metadata, packageId, ignoredDeps, visited, star
|
|
|
375
441
|
let depPurl = depPackage.source == null
|
|
376
442
|
? toPathDepPurl(depPackage.name, depPackage.version)
|
|
377
443
|
: toPurl(depPackage.name, depPackage.version);
|
|
378
|
-
|
|
379
|
-
|
|
444
|
+
let hashes = hashMap ? hashMap.get(`${depPackage.name}@${depPackage.version}`) : undefined;
|
|
445
|
+
sbom.addDependency(sourcePurl, depPurl, undefined, hashes);
|
|
446
|
+
addTransitiveDeps(sbom, metadata, depId, ignoredDeps, visited, hashMap);
|
|
380
447
|
}
|
|
381
448
|
}
|
|
382
449
|
/**
|
|
@@ -389,7 +456,7 @@ function addTransitiveDeps(sbom, metadata, packageId, ignoredDeps, visited, star
|
|
|
389
456
|
* @param {Set<string>} ignoredDeps - set of ignored dependency names
|
|
390
457
|
* @private
|
|
391
458
|
*/
|
|
392
|
-
function addDirectDeps(sbom, metadata, packageId, parentPurl, ignoredDeps) {
|
|
459
|
+
function addDirectDeps(sbom, metadata, packageId, parentPurl, ignoredDeps, hashMap) {
|
|
393
460
|
let resolveNode = findResolveNode(metadata, packageId);
|
|
394
461
|
if (!resolveNode) {
|
|
395
462
|
return;
|
|
@@ -406,7 +473,8 @@ function addDirectDeps(sbom, metadata, packageId, parentPurl, ignoredDeps) {
|
|
|
406
473
|
let depPurl = depPackage.source == null
|
|
407
474
|
? toPathDepPurl(depPackage.name, depPackage.version)
|
|
408
475
|
: toPurl(depPackage.name, depPackage.version);
|
|
409
|
-
|
|
476
|
+
let hashes = hashMap ? hashMap.get(`${depPackage.name}@${depPackage.version}`) : undefined;
|
|
477
|
+
sbom.addDependency(parentPurl, depPurl, undefined, hashes);
|
|
410
478
|
}
|
|
411
479
|
}
|
|
412
480
|
/**
|
|
Binary file
|