Skip to content

Commit 22fa873

Browse files
fix: serialization of model.component.Diff (#557)
Fixes #556 --------- Signed-off-by: rcross-lc <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Jan Kowalleck <[email protected]>
1 parent 53cb8a9 commit 22fa873

18 files changed

+121
-9
lines changed

cyclonedx/model/component.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ def deserialize(cls, o: Any) -> ComponentType:
405405
return ComponentType(o)
406406

407407

408+
@serializable.serializable_class
408409
class Diff:
409410
"""
410411
Our internal representation of the `diffType` complex type.

tests/_data/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
ComponentEvidence,
5252
ComponentScope,
5353
ComponentType,
54+
Diff,
5455
Patch,
5556
PatchClassification,
5657
Pedigree,
@@ -586,7 +587,13 @@ def get_pedigree_1() -> Pedigree:
586587
get_component_setuptools_simple(bom_ref='ded1d73e-1fca-4302-b520-f1bc53979958')
587588
],
588589
commits=[Commit(uid='a-random-uid', message='A commit message')],
589-
patches=[Patch(type=PatchClassification.BACKPORT)],
590+
patches=[Patch(type=PatchClassification.BACKPORT, diff=Diff(
591+
url=XsUri('https://acme.com/my-patch.diff'),
592+
text=AttachedText(encoding=Encoding.BASE_64, content_type='text/x-diff',
593+
content='LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMt'
594+
'MDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitI'
595+
'ZWxsbyB3b3JsZC4KIAo=')
596+
))],
590597
notes='Some notes here please'
591598
)
592599

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@
153153
"notes": "Some notes here please",
154154
"patches": [
155155
{
156+
"diff": {
157+
"text": {
158+
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
159+
"contentType": "text/x-diff",
160+
"encoding": "base64"
161+
},
162+
"url": "https://acme.com/my-patch.diff"
163+
},
156164
"type": "backport"
157165
}
158166
],

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@
137137
</commit>
138138
</commits>
139139
<patches>
140-
<patch type="backport"/>
140+
<patch type="backport">
141+
<diff>
142+
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
143+
<url>https://acme.com/my-patch.diff</url>
144+
</diff>
145+
</patch>
141146
</patches>
142147
<notes>Some notes here please</notes>
143148
</pedigree>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@
181181
"notes": "Some notes here please",
182182
"patches": [
183183
{
184+
"diff": {
185+
"text": {
186+
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
187+
"contentType": "text/x-diff",
188+
"encoding": "base64"
189+
},
190+
"url": "https://acme.com/my-patch.diff"
191+
},
184192
"type": "backport"
185193
}
186194
],

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@
143143
</commit>
144144
</commits>
145145
<patches>
146-
<patch type="backport"/>
146+
<patch type="backport">
147+
<diff>
148+
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
149+
<url>https://acme.com/my-patch.diff</url>
150+
</diff>
151+
</patch>
147152
</patches>
148153
<notes>Some notes here please</notes>
149154
</pedigree>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@
179179
"notes": "Some notes here please",
180180
"patches": [
181181
{
182+
"diff": {
183+
"text": {
184+
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
185+
"contentType": "text/x-diff",
186+
"encoding": "base64"
187+
},
188+
"url": "https://acme.com/my-patch.diff"
189+
},
182190
"type": "backport"
183191
}
184192
],

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@
167167
</commit>
168168
</commits>
169169
<patches>
170-
<patch type="backport"/>
170+
<patch type="backport">
171+
<diff>
172+
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
173+
<url>https://acme.com/my-patch.diff</url>
174+
</diff>
175+
</patch>
171176
</patches>
172177
<notes>Some notes here please</notes>
173178
</pedigree>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@
179179
"notes": "Some notes here please",
180180
"patches": [
181181
{
182+
"diff": {
183+
"text": {
184+
"content": "LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=",
185+
"contentType": "text/x-diff",
186+
"encoding": "base64"
187+
},
188+
"url": "https://acme.com/my-patch.diff"
189+
},
182190
"type": "backport"
183191
}
184192
],

tests/_data/snapshots/get_bom_just_complete_metadata-1.5.xml.bin

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@
167167
</commit>
168168
</commits>
169169
<patches>
170-
<patch type="backport"/>
170+
<patch type="backport">
171+
<diff>
172+
<text content-type="text/x-diff" encoding="base64">LS0tIGZvbwkyMDI0LTAzLTA0IDEyOjQxOjExLjQxODc1OTE0NSArMDEwMAorKysgYmFyCTIwMjQtMDMtMDQgMTI6NDE6MjguMzE1NTE3ODQ3ICswMTAwCkBAIC0xLDIgKzEsMiBAQAotaGVsbG8gd29ybGQuCitIZWxsbyB3b3JsZC4KIAo=</text>
173+
<url>https://acme.com/my-patch.diff</url>
174+
</diff>
175+
</patch>
171176
</patches>
172177
<notes>Some notes here please</notes>
173178
</pedigree>

0 commit comments

Comments
 (0)