2727
2828class BomMetaData :
2929 """
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.
3131
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
3334 """
3435
3536 _timestamp : datetime .datetime
@@ -38,15 +39,24 @@ def __init__(self):
3839 self ._timestamp = datetime .datetime .now (tz = datetime .timezone .utc )
3940
4041 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+ """
4148 return self ._timestamp
4249
4350
4451class Bom :
4552 """
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.
4757
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 .
5060 """
5161
5262 _uuid : str
@@ -55,37 +65,116 @@ class Bom:
5565
5666 @staticmethod
5767 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+ """
5877 bom = Bom ()
5978 bom .add_components (parser .get_components ())
6079 return bom
6180
6281 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+ """
6388 self ._uuid = uuid4 ()
6489 self ._metadata = BomMetaData ()
6590 self ._components .clear ()
6691
6792 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+ """
68103 self ._components .append (component )
69104
70105 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+ """
71116 self ._components = self ._components + components
72117
73118 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+ """
74125 return len (self ._components )
75126
76127 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+ """
77134 return self ._components
78135
79136 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+ """
80146 return self ._metadata
81147
82148 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+ """
83155 return 'urn:uuid:{}' .format (self ._uuid )
84156
85157 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+ """
86168 return component in self ._components
87169
88170 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+ """
89178 for c in self .get_components ():
90179 if c .has_vulnerabilities ():
91180 return True
0 commit comments