Skip to content

Commit 2e32d57

Browse files
committed
rollback: discriminate EVERY bom-ref
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 313c279 commit 2e32d57

File tree

71 files changed

+242
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+242
-476
lines changed

cyclonedx/output/__init__.py

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
if TYPE_CHECKING: # pragma: no cover
3434
from ..model.bom import Bom
3535
from ..model.bom_ref import BomRef
36-
from ..model.contact import OrganizationalContact, OrganizationalEntity, PostalAddress
37-
from ..model.definition import Level, Requirement, Standard
38-
from ..model.license import License
3936
from .json import Json as JsonOutputter
4037
from .xml import Xml as XmlOutputter
4138

@@ -173,47 +170,8 @@ def _make_unique(self) -> str:
173170

174171
@classmethod
175172
def from_bom(cls, bom: 'Bom', prefix: str = 'BomRef') -> 'BomRefDiscriminator':
176-
"""
177-
Create an instance containing EVERY ``bom-ref`` in the bom.
178-
"""
179-
180-
components = tuple(bom._get_all_components())
181-
services = tuple(bom.services)
182-
vulnerabilities = tuple(bom.vulnerabilities)
183-
orgs: tuple['OrganizationalEntity', ...] = tuple(filter(lambda o: o is not None, chain( # type:ignore[arg-type]
184-
(bom.metadata.manufacture, bom.metadata.manufacturer, bom.metadata.supplier),
185-
chain.from_iterable((c.manufacturer, c.supplier,) for c in components),
186-
(s.provider for s in services),
187-
chain.from_iterable(v.credits.organizations for v in vulnerabilities if v.credits),
188-
)))
189-
contacts: Iterable['OrganizationalContact'] = chain(
190-
bom.metadata.authors,
191-
chain.from_iterable(c.authors for c in components),
192-
chain.from_iterable(v.credits.individuals for v in vulnerabilities if v.credits),
193-
chain.from_iterable(o.contacts for o in orgs),
194-
)
195-
addresses: Iterable['PostalAddress'] = (o.address for o in orgs if o.address is not None)
196-
licenses: Iterable['License'] = chain(
197-
bom.metadata.licenses,
198-
chain.from_iterable(c.licenses for c in components),
199-
chain.from_iterable(c.evidence.licenses for c in components if c.evidence is not None),
200-
chain.from_iterable(s.licenses for s in services),
201-
)
202-
standards: tuple['Standard', ...] = () \
203-
if bom.definitions is None \
204-
else tuple(bom.definitions.standards)
205-
requirements: Iterable['Requirement'] = chain.from_iterable(s.requirements for s in standards)
206-
levels: Iterable['Level'] = chain.from_iterable(s.levels for s in standards)
207-
relevant_bom_refs: Iterable['BomRef'] = (i.bom_ref for i in chain(
208-
components,
209-
services,
210-
vulnerabilities,
211-
orgs,
212-
contacts,
213-
addresses,
214-
licenses,
215-
standards,
216-
requirements,
217-
levels,
218-
))
219-
return cls(relevant_bom_refs, prefix)
173+
return cls(chain(
174+
map(lambda c: c.bom_ref, bom._get_all_components()),
175+
map(lambda s: s.bom_ref, bom.services),
176+
map(lambda v: v.bom_ref, bom.vulnerabilities)
177+
), prefix)

tests/_data/models.py

Lines changed: 65 additions & 87 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"licenses": [
66
{
77
"license": {
8-
"bom-ref": "dummy_license",
98
"name": "att.encoding: BASE_64",
109
"text": {
1110
"content": "att.encoding: BASE_64",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<component type="library" bom-ref="dummy">
88
<name>dummy</name>
99
<licenses>
10-
<license bom-ref="dummy_license">
10+
<license>
1111
<name>att.encoding: BASE_64</name>
1212
<text content-type="text/plain" encoding="base64">att.encoding: BASE_64</text>
1313
</license>

tests/_data/snapshots/enum_Encoding-1.6.json.bin

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"licenses": [
66
{
77
"license": {
8-
"bom-ref": "dummy_license",
98
"name": "att.encoding: BASE_64",
109
"text": {
1110
"content": "att.encoding: BASE_64",

tests/_data/snapshots/enum_Encoding-1.6.xml.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<component type="library" bom-ref="dummy">
88
<name>dummy</name>
99
<licenses>
10-
<license bom-ref="dummy_license">
10+
<license>
1111
<name>att.encoding: BASE_64</name>
1212
<text content-type="text/plain" encoding="base64">att.encoding: BASE_64</text>
1313
</license>

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
"metadata": {
88
"authors": [
99
{
10-
"bom-ref": "OrganizationalContact_ano_bom_authors",
1110
"email": "[email protected]",
1211
"name": "A N Other",
1312
"phone": "+44 (0)1234 567890"
1413
},
1514
{
16-
"bom-ref": "OrganizationalContact_ph_bom_authors",
1715
"email": "[email protected]",
1816
"name": "Paul Horton"
1917
}
@@ -28,7 +26,6 @@
2826
"licenses": [
2927
{
3028
"license": {
31-
"bom-ref": "pkg:pypi/[email protected]?extension=tar.gz_license",
3229
"id": "MIT"
3330
}
3431
}
@@ -94,7 +91,6 @@
9491
"licenses": [
9592
{
9693
"license": {
97-
"bom-ref": "my-specific-bom-ref-for-dings_license",
9894
"id": "MIT"
9995
}
10096
}
@@ -108,7 +104,6 @@
108104
"licenses": [
109105
{
110106
"license": {
111-
"bom-ref": "ccc8d7ee-4b9c-4750-aee0-a72585152291_license",
112107
"id": "MIT"
113108
}
114109
}
@@ -124,7 +119,6 @@
124119
"licenses": [
125120
{
126121
"license": {
127-
"bom-ref": "8a3893b3-9923-4adb-a1d3-47456636ba0a_license",
128122
"id": "MIT"
129123
}
130124
}
@@ -147,7 +141,6 @@
147141
"licenses": [
148142
{
149143
"license": {
150-
"bom-ref": "28b2d8ce-def0-446f-a221-58dee0b44acc_license",
151144
"id": "MIT"
152145
}
153146
}
@@ -204,7 +197,6 @@
204197
"licenses": [
205198
{
206199
"license": {
207-
"bom-ref": "ded1d73e-1fca-4302-b520-f1bc53979958_license",
208200
"id": "MIT"
209201
}
210202
}
@@ -315,16 +307,13 @@
315307
},
316308
"scope": "required",
317309
"supplier": {
318-
"bom-ref": "OrganizationalEntity_cdx_my-specific-bom-ref-for-dings",
319310
"contact": [
320311
{
321-
"bom-ref": "OrganizationalContact_ano_my-specific-bom-ref-for-dings",
322312
"email": "[email protected]",
323313
"name": "A N Other",
324314
"phone": "+44 (0)1234 567890"
325315
},
326316
{
327-
"bom-ref": "OrganizationalContact_ph_my-specific-bom-ref-for-dings",
328317
"email": "[email protected]",
329318
"name": "Paul Horton"
330319
}
@@ -351,7 +340,6 @@
351340
"licenses": [
352341
{
353342
"license": {
354-
"bom-ref": "bom_license",
355343
"id": "Apache-2.0",
356344
"text": {
357345
"content": "VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE=",
@@ -368,16 +356,13 @@
368356
}
369357
],
370358
"manufacture": {
371-
"bom-ref": "OrganizationalEntity_cdx_bom_manufacture",
372359
"contact": [
373360
{
374-
"bom-ref": "OrganizationalContact_ano_bom_manufacture",
375361
"email": "[email protected]",
376362
"name": "A N Other",
377363
"phone": "+44 (0)1234 567890"
378364
},
379365
{
380-
"bom-ref": "OrganizationalContact_ph_bom_manufacture",
381366
"email": "[email protected]",
382367
"name": "Paul Horton"
383368
}
@@ -399,10 +384,8 @@
399384
}
400385
],
401386
"supplier": {
402-
"bom-ref": "OrganizationalEntity_cd_x_bom_supplier",
403387
"contact": [
404388
{
405-
"bom-ref": "OrganizationalContact_ano_bom_supplier",
406389
"email": "[email protected]",
407390
"name": "A N Other",
408391
"phone": "+44 (0)1234 567890"

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
</lifecycle>
99
</lifecycles>
1010
<authors>
11-
<author bom-ref="OrganizationalContact_ano_bom_authors">
11+
<author>
1212
<name>A N Other</name>
1313
<email>[email protected]</email>
1414
<phone>+44 (0)1234 567890</phone>
1515
</author>
16-
<author bom-ref="OrganizationalContact_ph_bom_authors">
16+
<author>
1717
<name>Paul Horton</name>
1818
<email>[email protected]</email>
1919
</author>
2020
</authors>
2121
<component type="library" bom-ref="my-specific-bom-ref-for-dings">
22-
<supplier bom-ref="OrganizationalEntity_cdx_my-specific-bom-ref-for-dings">
22+
<supplier>
2323
<name>CycloneDX</name>
2424
<url>https://cyclonedx.org</url>
2525
<url>https://cyclonedx.org/docs</url>
26-
<contact bom-ref="OrganizationalContact_ano_my-specific-bom-ref-for-dings">
26+
<contact>
2727
<name>A N Other</name>
2828
<email>[email protected]</email>
2929
<phone>+44 (0)1234 567890</phone>
3030
</contact>
31-
<contact bom-ref="OrganizationalContact_ph_my-specific-bom-ref-for-dings">
31+
<contact>
3232
<name>Paul Horton</name>
3333
<email>[email protected]</email>
3434
</contact>
@@ -40,7 +40,7 @@
4040
<description>This component is awesome</description>
4141
<scope>required</scope>
4242
<licenses>
43-
<license bom-ref="my-specific-bom-ref-for-dings_license">
43+
<license>
4444
<id>MIT</id>
4545
</license>
4646
</licenses>
@@ -57,7 +57,7 @@
5757
<name>setuptools</name>
5858
<version>50.3.2</version>
5959
<licenses>
60-
<license bom-ref="ccc8d7ee-4b9c-4750-aee0-a72585152291_license">
60+
<license>
6161
<id>MIT</id>
6262
</license>
6363
</licenses>
@@ -67,7 +67,7 @@
6767
<author>Test Author</author>
6868
<name>setuptools</name>
6969
<licenses>
70-
<license bom-ref="8a3893b3-9923-4adb-a1d3-47456636ba0a_license">
70+
<license>
7171
<id>MIT</id>
7272
</license>
7373
</licenses>
@@ -79,7 +79,7 @@
7979
<author>Test Author</author>
8080
<name>setuptools</name>
8181
<licenses>
82-
<license bom-ref="28b2d8ce-def0-446f-a221-58dee0b44acc_license">
82+
<license>
8383
<id>MIT</id>
8484
</license>
8585
</licenses>
@@ -109,7 +109,7 @@
109109
<name>setuptools</name>
110110
<version>50.3.2</version>
111111
<licenses>
112-
<license bom-ref="ded1d73e-1fca-4302-b520-f1bc53979958_license">
112+
<license>
113113
<id>MIT</id>
114114
</license>
115115
</licenses>
@@ -168,7 +168,7 @@
168168
<name>setuptools</name>
169169
<version>50.3.2</version>
170170
<licenses>
171-
<license bom-ref="pkg:pypi/[email protected]?extension=tar.gz_license">
171+
<license>
172172
<id>MIT</id>
173173
</license>
174174
</licenses>
@@ -243,31 +243,31 @@
243243
</properties>
244244
</releaseNotes>
245245
</component>
246-
<manufacture bom-ref="OrganizationalEntity_cdx_bom_manufacture">
246+
<manufacture>
247247
<name>CycloneDX</name>
248248
<url>https://cyclonedx.org</url>
249249
<url>https://cyclonedx.org/docs</url>
250-
<contact bom-ref="OrganizationalContact_ano_bom_manufacture">
250+
<contact>
251251
<name>A N Other</name>
252252
<email>[email protected]</email>
253253
<phone>+44 (0)1234 567890</phone>
254254
</contact>
255-
<contact bom-ref="OrganizationalContact_ph_bom_manufacture">
255+
<contact>
256256
<name>Paul Horton</name>
257257
<email>[email protected]</email>
258258
</contact>
259259
</manufacture>
260-
<supplier bom-ref="OrganizationalEntity_cd_x_bom_supplier">
260+
<supplier>
261261
<name>Cyclone DX</name>
262262
<url>https://cyclonedx.org/</url>
263-
<contact bom-ref="OrganizationalContact_ano_bom_supplier">
263+
<contact>
264264
<name>A N Other</name>
265265
<email>[email protected]</email>
266266
<phone>+44 (0)1234 567890</phone>
267267
</contact>
268268
</supplier>
269269
<licenses>
270-
<license bom-ref="bom_license">
270+
<license>
271271
<id>Apache-2.0</id>
272272
<text content-type="text/plain" encoding="base64">VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE=</text>
273273
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>

0 commit comments

Comments
 (0)