Skip to content

Commit

Permalink
Allow specifying the SWID link hrefs by name as well as UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Sep 18, 2023
1 parent dac50fd commit 54035f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ NOTE: The GUID can be constructed from the tool or library name combined with
the version, e.g using `appstream-util generate-guid gcc-12.1.1` or the
[online tool hosted by the LVFS](https://fwupd.org/lvfs/guid).

...or, if a component has been previously defined, you can use the name to
contruct the SWID automatically:

[uSWID-Link:image_loading_lib]
rel = requires
href = swid:libjpeg

RAW Blobs
---------

Expand Down
17 changes: 16 additions & 1 deletion uswid/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# pylint: disable=too-few-public-methods

from enum import IntEnum
import uuid

from typing import Optional

Expand Down Expand Up @@ -36,7 +37,7 @@ def __init__(
href: Optional[str] = None,
rel: Optional[str] = None,
):
self.href: Optional[str] = href
self._href: Optional[str] = href
self._rel: Optional[str] = rel

@property
Expand All @@ -52,6 +53,20 @@ def rel(self) -> Optional[str]:
def rel(self, rel: Optional[str]) -> None:
self._rel = rel

@property
def href(self) -> Optional[str]:
return self._href

@href.setter
def href(self, href: Optional[str]) -> None:
if href.startswith("swid:"):
maybe_uuid: str = href.split(":")[1]
try:
_ = uuid.UUID(maybe_uuid)
except ValueError:
href = f"swid:{str(uuid.uuid5(uuid.NAMESPACE_DNS, maybe_uuid))}"
self._href = href

@property
def href_for_display(self) -> Optional[str]:
if not self.href:
Expand Down

0 comments on commit 54035f6

Please sign in to comment.