27
27
28
28
class BomMetaData :
29
29
"""
30
- Our internal representation of the metadata complex type within the CycloneDX standard.
30
+ This is our internal representation of the metadata complex type within the CycloneDX standard.
31
31
32
- See https://cyclonedx.org/docs/1.3/#type_metadata
32
+ .. note::
33
+ See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.3/#type_metadata
33
34
"""
34
35
35
36
_timestamp : datetime .datetime
@@ -38,15 +39,24 @@ def __init__(self):
38
39
self ._timestamp = datetime .datetime .now (tz = datetime .timezone .utc )
39
40
40
41
def get_timestamp (self ) -> datetime .datetime :
42
+ """
43
+ The date and time (in UTC) when this BomMetaData was created.
44
+
45
+ Returns:
46
+ `datetime.datetime` instance in UTC timezone
47
+ """
41
48
return self ._timestamp
42
49
43
50
44
51
class Bom :
45
52
"""
46
- This is our internal representation of the BOM.
53
+ This is our internal representation of a bill-of-materials (BOM).
54
+
55
+ You can either create a `cyclonedx.model.bom.Bom` yourself programmatically, or generate a `cyclonedx.model.bom.Bom`
56
+ from a `cyclonedx.parser.BaseParser` implementation.
47
57
48
- We can pass a BOM instance to a Generator to produce CycloneDX in the required format and according
49
- to the requested schema version.
58
+ Once you have an instance of `cyclonedx.model.bom.Bom`, you can pass this to an instance of
59
+ `cyclonedx.output.BaseOutput` to produce a CycloneDX document according to a specific schema version and format .
50
60
"""
51
61
52
62
_uuid : str
@@ -55,37 +65,116 @@ class Bom:
55
65
56
66
@staticmethod
57
67
def from_parser (parser : BaseParser ):
68
+ """
69
+ Create a Bom instance from a Parser object.
70
+
71
+ Args:
72
+ parser (`cyclonedx.parser.BaseParser`): A valid parser instance.
73
+
74
+ Returns:
75
+ `cyclonedx.model.bom.Bom`: A Bom instance that represents the valid data held in the supplied parser.
76
+ """
58
77
bom = Bom ()
59
78
bom .add_components (parser .get_components ())
60
79
return bom
61
80
62
81
def __init__ (self ):
82
+ """
83
+ Create a new Bom that you can manually/programmatically add data to later.
84
+
85
+ Returns:
86
+ New, empty `cyclonedx.model.bom.Bom` instance.
87
+ """
63
88
self ._uuid = uuid4 ()
64
89
self ._metadata = BomMetaData ()
65
90
self ._components .clear ()
66
91
67
92
def add_component (self , component : Component ):
93
+ """
94
+ Add a Component to this Bom instance.
95
+
96
+ Args:
97
+ component:
98
+ `cyclonedx.model.component.Component` instance to add to this Bom.
99
+
100
+ Returns:
101
+ None
102
+ """
68
103
self ._components .append (component )
69
104
70
105
def add_components (self , components : List [Component ]):
106
+ """
107
+ Add multiple Components at once to this Bom instance.
108
+
109
+ Args:
110
+ components:
111
+ List of `cyclonedx.model.component.Component` instances to add to this Bom.
112
+
113
+ Returns:
114
+ None
115
+ """
71
116
self ._components = self ._components + components
72
117
73
118
def component_count (self ) -> int :
119
+ """
120
+ Returns the current count of Components within this Bom.
121
+
122
+ Returns:
123
+ The number of Components in this Bom as `int`.
124
+ """
74
125
return len (self ._components )
75
126
76
127
def get_components (self ) -> List [Component ]:
128
+ """
129
+ Get all the Components currently in this Bom.
130
+
131
+ Returns:
132
+ List of all Components in this Bom.
133
+ """
77
134
return self ._components
78
135
79
136
def get_metadata (self ) -> BomMetaData :
137
+ """
138
+ Get our internal metadata object for this Bom.
139
+
140
+ Returns:
141
+ Metadata object instance for this Bom.
142
+
143
+ .. note::
144
+ See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.3/#type_metadata
145
+ """
80
146
return self ._metadata
81
147
82
148
def get_urn_uuid (self ) -> str :
149
+ """
150
+ Get the unique reference for this Bom.
151
+
152
+ Returns:
153
+ URN formatted UUID that uniquely identified this Bom instance.
154
+ """
83
155
return 'urn:uuid:{}' .format (self ._uuid )
84
156
85
157
def has_component (self , component : Component ) -> bool :
158
+ """
159
+ Check whether this Bom contains the provided Component.
160
+
161
+ Args:
162
+ component:
163
+ The instance of `cyclonedx.model.component.Component` to check if this Bom contains.
164
+
165
+ Returns:
166
+ `bool` - `True` if the supplied Component is part of this Bom, `False` otherwise.
167
+ """
86
168
return component in self ._components
87
169
88
170
def has_vulnerabilities (self ) -> bool :
171
+ """
172
+ Check whether this Bom has any declared vulnerabilities.
173
+
174
+ Returns:
175
+ `bool` - `True` if at least one `cyclonedx.model.component.Component` has at least one Vulnerability,
176
+ `False` otherwise.
177
+ """
89
178
for c in self .get_components ():
90
179
if c .has_vulnerabilities ():
91
180
return True
0 commit comments