Skip to content

Commit

Permalink
fix: serialization of model.component.Diff (#557)
Browse files Browse the repository at this point in the history
Fixes #556 

---------

Signed-off-by: rcross-lc <151086351+rcross-lc@users.noreply.github.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Co-authored-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
rcross-lc and jkowalleck authored Mar 4, 2024
1 parent 53cb8a9 commit 22fa873
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 9 deletions.
1 change: 1 addition & 0 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def deserialize(cls, o: Any) -> ComponentType:
return ComponentType(o)


@serializable.serializable_class
class Diff:
"""
Our internal representation of the `diffType` complex type.
Expand Down
9 changes: 8 additions & 1 deletion tests/_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ComponentEvidence,
ComponentScope,
ComponentType,
Diff,
Patch,
PatchClassification,
Pedigree,
Expand Down Expand Up @@ -586,7 +587,13 @@ def get_pedigree_1() -> Pedigree:
get_component_setuptools_simple(bom_ref='ded1d73e-1fca-4302-b520-f1bc53979958')
],
commits=[Commit(uid='a-random-uid', message='A commit message')],
patches=[Patch(type=PatchClassification.BACKPORT)],
patches=[Patch(type=PatchClassification.BACKPORT, diff=Diff(
url=XsUri('https://acme.com/my-patch.diff'),
text=AttachedText(encoding=Encoding.BASE_64, content_type='text/x-diff',
content='LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMt'
'MDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitI'
'ZWxsbyB3b3JsZC4KIAo=')
))],
notes='Some notes here please'
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@
"notes": "Some notes here please",
"patches": [
{
"diff": {
"text": {
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
"contentType": "text/x-diff",
"encoding": "base64"
},
"url": "https://acme.com/my-patch.diff"
},
"type": "backport"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@
</commit>
</commits>
<patches>
<patch type="backport"/>
<patch type="backport">
<diff>
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
<url>https://acme.com/my-patch.diff</url>
</diff>
</patch>
</patches>
<notes>Some notes here please</notes>
</pedigree>
Expand Down

0 comments on commit 22fa873

Please sign in to comment.