Skip to content

Commit 73e7c1a

Browse files
authored
feat: add support for properties in external references (#907)
part of #903 --------- Signed-off-by: Johannes Feichtner <[email protected]>
1 parent 70adb7c commit 73e7c1a

16 files changed

+104
-5
lines changed

cyclonedx/model/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,13 @@ def __init__(
835835
url: XsUri,
836836
comment: Optional[str] = None,
837837
hashes: Optional[Iterable[HashType]] = None,
838+
properties: Optional[Iterable['Property']] = None,
838839
) -> None:
839840
self.url = url
840841
self.comment = comment
841842
self.type = type
842843
self.hashes = hashes or []
844+
self.properties = properties or []
843845

844846
@property
845847
@serializable.xml_sequence(1)
@@ -909,10 +911,27 @@ def hashes(self) -> 'SortedSet[HashType]':
909911
def hashes(self, hashes: Iterable[HashType]) -> None:
910912
self._hashes = SortedSet(hashes)
911913

914+
@property
915+
@serializable.view(SchemaVersion1Dot7)
916+
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
917+
def properties(self) -> 'SortedSet[Property]':
918+
"""
919+
Provides the ability to document properties in a key/value store. This provides flexibility to include data not
920+
officially supported in the standard without having to use additional namespaces or create extensions.
921+
922+
Return:
923+
Set of `Property`
924+
"""
925+
return self._properties
926+
927+
@properties.setter
928+
def properties(self, properties: Iterable['Property']) -> None:
929+
self._properties = SortedSet(properties)
930+
912931
def __comparable_tuple(self) -> _ComparableTuple:
913932
return _ComparableTuple((
914933
self._type, self._url, self._comment,
915-
_ComparableTuple(self._hashes)
934+
_ComparableTuple(self._hashes), _ComparableTuple(self.properties),
916935
))
917936

918937
def __eq__(self, other: object) -> bool:

tests/_data/models.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def get_bom_just_complete_metadata() -> Bom:
588588

589589
def get_bom_with_external_references() -> Bom:
590590
bom = _make_bom(external_references=[
591-
get_external_reference_1(), get_external_reference_2()
591+
get_external_reference_1(), get_external_reference_2(), get_external_reference_with_properties()
592592
])
593593
return bom
594594

@@ -896,6 +896,17 @@ def get_external_reference_2() -> ExternalReference:
896896
)
897897

898898

899+
def get_external_reference_with_properties() -> ExternalReference:
900+
return ExternalReference(
901+
type=ExternalReferenceType.VCS,
902+
url=XsUri('https://cyclonedx.org'),
903+
properties=[
904+
Property(name='property_1', value='value_1'),
905+
Property(name='property_2', value='value_2')
906+
]
907+
)
908+
909+
899910
def get_issue_1() -> IssueType:
900911
return IssueType(
901912
type=IssueClassification.SECURITY, id='CVE-2021-44228', name='Apache Log3Shell',

tests/_data/snapshots/get_bom_with_external_references-1.1.xml.bin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<url>https://cyclonedx.org</url>
77
<comment>No comment</comment>
88
</reference>
9+
<reference type="vcs">
10+
<url>https://cyclonedx.org</url>
11+
</reference>
912
<reference type="website">
1013
<url>https://cyclonedx.org</url>
1114
</reference>

tests/_data/snapshots/get_bom_with_external_references-1.2.json.bin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"type": "distribution",
66
"url": "https://cyclonedx.org"
77
},
8+
{
9+
"type": "vcs",
10+
"url": "https://cyclonedx.org"
11+
},
812
{
913
"type": "website",
1014
"url": "https://cyclonedx.org"

tests/_data/snapshots/get_bom_with_external_references-1.2.xml.bin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<url>https://cyclonedx.org</url>
99
<comment>No comment</comment>
1010
</reference>
11+
<reference type="vcs">
12+
<url>https://cyclonedx.org</url>
13+
</reference>
1114
<reference type="website">
1215
<url>https://cyclonedx.org</url>
1316
</reference>

tests/_data/snapshots/get_bom_with_external_references-1.3.json.bin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "distribution",
1212
"url": "https://cyclonedx.org"
1313
},
14+
{
15+
"type": "vcs",
16+
"url": "https://cyclonedx.org"
17+
},
1418
{
1519
"type": "website",
1620
"url": "https://cyclonedx.org"

tests/_data/snapshots/get_bom_with_external_references-1.3.xml.bin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
1212
</hashes>
1313
</reference>
14+
<reference type="vcs">
15+
<url>https://cyclonedx.org</url>
16+
</reference>
1417
<reference type="website">
1518
<url>https://cyclonedx.org</url>
1619
</reference>

tests/_data/snapshots/get_bom_with_external_references-1.4.json.bin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "distribution",
1212
"url": "https://cyclonedx.org"
1313
},
14+
{
15+
"type": "vcs",
16+
"url": "https://cyclonedx.org"
17+
},
1418
{
1519
"type": "website",
1620
"url": "https://cyclonedx.org"

tests/_data/snapshots/get_bom_with_external_references-1.4.xml.bin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
1212
</hashes>
1313
</reference>
14+
<reference type="vcs">
15+
<url>https://cyclonedx.org</url>
16+
</reference>
1417
<reference type="website">
1518
<url>https://cyclonedx.org</url>
1619
</reference>

tests/_data/snapshots/get_bom_with_external_references-1.5.json.bin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "distribution",
1212
"url": "https://cyclonedx.org"
1313
},
14+
{
15+
"type": "vcs",
16+
"url": "https://cyclonedx.org"
17+
},
1418
{
1519
"type": "website",
1620
"url": "https://cyclonedx.org"

0 commit comments

Comments
 (0)