Skip to content

Commit ea90034

Browse files
committed
Final feature addition
I think the fetaure addition is done. Now, on to adding tests.
1 parent 59bd0f3 commit ea90034

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

cyclonedx/model/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,9 @@ def __hash__(self) -> int:
11961196
def __repr__(self) -> str:
11971197
return f'<Copyright text={self.text}>'
11981198

1199+
11991200
# Importing here to avoid a circular import
1200-
from .tool import Tool # pylint: disable=wrong-import-position
1201+
from .tool import Tool # pylint: disable=wrong-import-position # noqa: E402
12011202

12021203
ThisTool = Tool(
12031204
vendor='CycloneDX',

cyclonedx/model/bom.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
from sortedcontainers import SortedSet
2727

2828
from .._internal.time import get_now_utc as _get_now_utc
29-
from ..exception.model import (
30-
LicenseExpressionAlongWithOthersException,
31-
UnknownComponentDependencyException,
32-
)
33-
from ..model.tool import Tool, ToolsRepository, ToolsRepositoryHelper
29+
from ..exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
30+
from .tool import Tool, ToolsRepository, ToolsRepositoryHelper
3431
from ..schema.schema import (
3532
SchemaVersion1Dot0,
3633
SchemaVersion1Dot1,
@@ -89,7 +86,7 @@ def __init__(self, *, tools: Optional[Union[Iterable[Tool], Dict[AnyStr, Any]]]
8986
DeprecationWarning)
9087

9188
if not tools:
92-
self.tools.add(ThisTool) # type: ignore[attr-defined]
89+
self.tools.add(ThisTool)
9390

9491
@property
9592
@serializable.type_mapping(serializable.helpers.XsdDateTime)

cyclonedx/model/tool.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,17 @@ def json_normalize(cls, o: ToolsRepository, *,
241241
return None
242242

243243
if o._tools: # pylint: disable=protected-access
244-
return [json_loads(Tool.as_json(t)) for t in o] # type: ignore[attr-defined]
244+
return [json_loads(Tool.as_json(t, view_=view)) for t in o] # type: ignore[attr-defined]
245245

246246
result = {}
247247

248248
if o.components:
249-
result['components'] = [json_loads(Component.as_json(c))
250-
for c in o.components] # type: ignore[attr-defined]
249+
result['components'] = [json_loads(Component.as_json(c, view_=view)) # type: ignore[attr-defined]
250+
for c in o.components]
251251

252252
if o.services:
253-
result['services'] = [json_loads(Service.as_json(s)) for s in o.services] # type: ignore[attr-defined]
253+
result['services'] = [json_loads(Service.as_json(s, view_=view)) # type: ignore[attr-defined]
254+
for s in o.services]
254255

255256
return result
256257

@@ -323,19 +324,19 @@ def xml_denormalize(cls, o: Element, *,
323324
prop_info: ObjectMetadataLibrary.SerializableProperty,
324325
ctx: Type[Any],
325326
**kwargs: Any) -> ToolsRepository:
326-
tools: list[Tool] = []
327-
components: list[Component] = []
328-
services: list[Service] = []
327+
tools: List[Tool] = []
328+
components: List[Component] = []
329+
services: List[Service] = []
329330

330331
for e in o:
331332
tag = e.tag if default_ns is None else e.tag.replace(f'{{{default_ns}}}', '')
332333
if tag == 'tool':
333-
tools.append(Tool.from_xml(e))
334+
tools.append(Tool.from_xml(e)) # type: ignore[attr-defined]
334335
if tag == 'components':
335336
for c in e:
336-
components.append(Component.from_xml(c))
337+
components.append(Component.from_xml(c)) # type: ignore[attr-defined]
337338
if tag == 'services':
338339
for s in e:
339-
services.append(Service.from_xml(s))
340+
services.append(Service.from_xml(s)) # type: ignore[attr-defined]
340341

341342
return ToolsRepository(tools=tools, components=components, services=services)

cyclonedx/model/vulnerability.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from datetime import datetime
3434
from decimal import Decimal
3535
from enum import Enum
36-
from typing import Any, Dict, FrozenSet, Iterable, Optional, Tuple, Type, Union
36+
from typing import Any, AnyStr, Dict, FrozenSet, Iterable, Optional, Tuple, Type, Union
3737

3838
import serializable
3939
from sortedcontainers import SortedSet
@@ -42,7 +42,7 @@
4242
from ..exception.model import MutuallyExclusivePropertiesException, NoPropertiesProvidedException
4343
from ..schema.schema import SchemaVersion1Dot4, SchemaVersion1Dot5, SchemaVersion1Dot6
4444
from ..serialization import BomRefHelper
45-
from . import Property, Tool, XsUri
45+
from . import Property, XsUri
4646
from .bom_ref import BomRef
4747
from .contact import OrganizationalContact, OrganizationalEntity
4848
from .impact_analysis import (
@@ -51,7 +51,7 @@
5151
ImpactAnalysisResponse,
5252
ImpactAnalysisState,
5353
)
54-
54+
from .tool import Tool, ToolsRepository, ToolsRepositoryHelper
5555

5656
@serializable.serializable_class
5757
class BomTargetVersionRange:
@@ -911,7 +911,8 @@ def __init__(self, *,
911911
advisories: Optional[Iterable[VulnerabilityAdvisory]] = None, created: Optional[datetime] = None,
912912
published: Optional[datetime] = None, updated: Optional[datetime] = None,
913913
credits: Optional[VulnerabilityCredits] = None,
914-
tools: Optional[Iterable[Tool]] = None, analysis: Optional[VulnerabilityAnalysis] = None,
914+
tools: Optional[Union[Iterable[Tool], Dict[AnyStr, Any]]] = None,
915+
analysis: Optional[VulnerabilityAnalysis] = None,
915916
affects: Optional[Iterable[BomTarget]] = None,
916917
properties: Optional[Iterable[Property]] = None
917918
) -> None:
@@ -932,7 +933,7 @@ def __init__(self, *,
932933
self.published = published
933934
self.updated = updated
934935
self.credits = credits
935-
self.tools = tools or [] # type:ignore[assignment]
936+
self.tools = tools or ToolsRepository() # type:ignore[assignment] # type:ignore[assignment]
936937
self.analysis = analysis
937938
self.affects = affects or [] # type:ignore[assignment]
938939
self.properties = properties or [] # type:ignore[assignment]
@@ -1193,20 +1194,24 @@ def credits(self, credits: Optional[VulnerabilityCredits]) -> None:
11931194
self._credits = credits
11941195

11951196
@property
1197+
@serializable.type_mapping(ToolsRepositoryHelper)
11961198
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'tool')
11971199
@serializable.xml_sequence(17)
1198-
def tools(self) -> 'SortedSet[Tool]':
1200+
def tools(self) -> ToolsRepository:
11991201
"""
1200-
The tool(s) used to identify, confirm, or score the vulnerability.
1202+
Tools used to create this BOM.
12011203
12021204
Returns:
1203-
Set of `Tool`
1205+
`ToolsRepository` objects.
12041206
"""
12051207
return self._tools
12061208

12071209
@tools.setter
1208-
def tools(self, tools: Iterable[Tool]) -> None:
1209-
self._tools = SortedSet(tools)
1210+
def tools(self, tools: Union[Iterable[Tool], ToolsRepository]) -> None:
1211+
if isinstance(tools, ToolsRepository):
1212+
self._tools = tools
1213+
else:
1214+
self._tools = ToolsRepository(tools=tools)
12101215

12111216
@property
12121217
@serializable.xml_sequence(18)

0 commit comments

Comments
 (0)