mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-08 08:30:47 -09:00
utils/generate-cyclonedx: generate vcs externalReferences for source repos
Some packages do not have a http/https download URL for a source tarball, but are acquired over a version control system like git. If so, add externalReferences of type "vcs" for such URLs. As most git repositories use a https:// transport that may not indicated the repository type, add a "comment" due to the lack of a better mechanism in CycloneDX. While the hashes are calculated over a tarball created locally, it still may be useful, so add them for "vcs" externalReferences as well. Signed-off-by: Martin Willi <martin@strongswan.org> Acked-By: Thomas Perale <thomas.perale@mind.be> Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
committed by
Arnout Vandecappelle
parent
1791b79422
commit
e8c54ffb3d
@@ -147,6 +147,8 @@ class TestGenerateCycloneDX(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"source": "foo-1.2.tar.gz",
|
"source": "foo-1.2.tar.gz",
|
||||||
"uris": [
|
"uris": [
|
||||||
|
"git+git://git.example.org/foo",
|
||||||
|
"svn+https://svn.example.org/foo",
|
||||||
"https+https://sources.buildroot.net/foo",
|
"https+https://sources.buildroot.net/foo",
|
||||||
"http|https+https://mirror.example.org/foo",
|
"http|https+https://mirror.example.org/foo",
|
||||||
],
|
],
|
||||||
@@ -160,10 +162,20 @@ class TestGenerateCycloneDX(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
foo["externalReferences"],
|
foo["externalReferences"],
|
||||||
[
|
[
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "git://git.example.org/foo",
|
||||||
|
"comment": "git repository",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://svn.example.org/foo",
|
||||||
|
"comment": "svn repository",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "source-distribution",
|
"type": "source-distribution",
|
||||||
"url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
|
"url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -183,6 +195,7 @@ class TestGenerateCycloneDX(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"source": "foo-1.2.tar.gz",
|
"source": "foo-1.2.tar.gz",
|
||||||
"uris": [
|
"uris": [
|
||||||
|
"git+git://git.example.org/foo",
|
||||||
"http|https+https://mirror.example.org/foo",
|
"http|https+https://mirror.example.org/foo",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -194,6 +207,21 @@ class TestGenerateCycloneDX(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
foo["externalReferences"],
|
foo["externalReferences"],
|
||||||
[
|
[
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "git://git.example.org/foo",
|
||||||
|
"comment": "git repository",
|
||||||
|
"hashes": [
|
||||||
|
{
|
||||||
|
"alg": "SHA-256",
|
||||||
|
"content": "1111111111111111111111111111111111111111111111111111111111111111",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alg": "SHA-1",
|
||||||
|
"content": "2222222222222222222222222222222222222222",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "source-distribution",
|
"type": "source-distribution",
|
||||||
"url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
|
"url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
|
||||||
|
|||||||
@@ -325,6 +325,7 @@ def cyclonedx_external_refs(comp):
|
|||||||
dict: External reference information in CycloneDX format, or empty dict
|
dict: External reference information in CycloneDX format, or empty dict
|
||||||
"""
|
"""
|
||||||
SOURCE_DIST_SCHEMES = {"http", "https"}
|
SOURCE_DIST_SCHEMES = {"http", "https"}
|
||||||
|
VCS_SCHEMES = {"git", "svn", "cvs", "hg", "bzr"}
|
||||||
|
|
||||||
refs = []
|
refs = []
|
||||||
for download in comp.get("downloads", []):
|
for download in comp.get("downloads", []):
|
||||||
@@ -336,6 +337,13 @@ def cyclonedx_external_refs(comp):
|
|||||||
"url": f"{uri}/{source}",
|
"url": f"{uri}/{source}",
|
||||||
**cyclonedx_source_hashes(comp, source),
|
**cyclonedx_source_hashes(comp, source),
|
||||||
})
|
})
|
||||||
|
elif set(schemes) & VCS_SCHEMES:
|
||||||
|
refs.append({
|
||||||
|
"type": "vcs",
|
||||||
|
"url": uri,
|
||||||
|
"comment": f"{schemes[0]} repository",
|
||||||
|
**cyclonedx_source_hashes(comp, source),
|
||||||
|
})
|
||||||
if refs:
|
if refs:
|
||||||
return {"externalReferences": refs}
|
return {"externalReferences": refs}
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Reference in New Issue
Block a user