Skip to content

Commit ec569e2

Browse files
author
Saquib Saifee
committed
feat: add XsUri cls method to generate bom_link
Signed-off-by: Saquib Saifee <[email protected]>
1 parent 2ce5d8f commit ec569e2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cyclonedx/model/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from enum import Enum
2828
from functools import reduce
2929
from json import loads as json_loads
30-
from typing import Any, Dict, FrozenSet, Generator, Iterable, List, Optional, Tuple, Type
30+
from typing import Any, Dict, FrozenSet, Generator, Iterable, List, Optional, Tuple, Type, Union
31+
from uuid import UUID
3132
from warnings import warn
3233
from xml.etree.ElementTree import Element as XmlElement # nosec B405
3334

@@ -767,6 +768,23 @@ def deserialize(cls, o: Any) -> 'XsUri':
767768
f'XsUri string supplied does not parse: {o!r}'
768769
) from err
769770

771+
@classmethod
772+
def make_bom_link(cls, serialnumber: Union[UUID, str], version: int = 1, bom_ref: Optional[str] = None) -> 'XsUri':
773+
"""
774+
Generate a BOM-Link URI.
775+
776+
Args:
777+
serialnumber (Union[UUID, str]): Unique identifier for the BOM, either as a UUID or a string.
778+
version (int, optional): Version number of the BOM-Link. Defaults to 1.
779+
bom_ref (Optional[str], optional): Reference to a specific component in the BOM. Defaults to None.
780+
781+
Returns:
782+
XsUri: Instance of XsUri with the generated BOM-Link URI.
783+
"""
784+
bom_ref_part = f'#{bom_ref}' if bom_ref else ''
785+
uri = f'urn:cdx:{serialnumber}/{version}{bom_ref_part}'
786+
return cls(uri)
787+
770788

771789
@serializable.serializable_class
772790
class ExternalReference:

0 commit comments

Comments
 (0)