Skip to content

Commit abf6abf

Browse files
committed
ft: update validate and register_dependency to read provides
Signed-off-by: Uzair Chhapra <[email protected]>
1 parent 00536a7 commit abf6abf

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

cyclonedx/model/bom.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,23 +644,36 @@ def has_vulnerabilities(self) -> bool:
644644
"""
645645
return bool(self.vulnerabilities)
646646

647-
def register_dependency(self, target: Dependable, depends_on: Optional[Iterable[Dependable]] = None) -> None:
647+
def register_dependency(
648+
self,
649+
target: Dependable,
650+
depends_on: Optional[Iterable[Dependable]] = None,
651+
provides: Optional[Iterable[Dependable]] = None,
652+
) -> None:
648653
_d = next(filter(lambda _d: _d.ref == target.bom_ref, self.dependencies), None)
649654
if _d:
650655
# Dependency Target already registered - but it might have new dependencies to add
651656
if depends_on:
652657
_d.dependencies.update(map(lambda _d: Dependency(ref=_d.bom_ref), depends_on))
658+
if provides:
659+
_d.provides.update(map(lambda _p: Dependency(ref=_p.bom_ref), provides))
653660
else:
654661
# First time we are seeing this target as a Dependency
655-
self._dependencies.add(Dependency(
656-
ref=target.bom_ref,
657-
dependencies=map(lambda _dep: Dependency(ref=_dep.bom_ref), depends_on) if depends_on else []
658-
))
662+
self._dependencies.add(
663+
Dependency(
664+
ref=target.bom_ref,
665+
dependencies=map(lambda _dep: Dependency(ref=_dep.bom_ref), depends_on) if depends_on else [],
666+
provides=map(lambda _prov: Dependency(ref=_prov.bom_ref), provides) if provides else [],
667+
)
668+
)
659669

660670
if depends_on:
661671
# Ensure dependents are registered with no further dependents in the DependencyGraph
662672
for _d2 in depends_on:
663673
self.register_dependency(target=_d2, depends_on=None)
674+
if provides:
675+
for _p2 in provides:
676+
self.register_dependency(target=_p2, depends_on=None, provides=None)
664677

665678
def urn(self) -> str:
666679
return f'{_BOM_LINK_PREFIX}{self.serial_number}/{self.version}'
@@ -681,12 +694,14 @@ def validate(self) -> bool:
681694
for _s in self.services:
682695
self.register_dependency(target=_s)
683696

684-
# 1. Make sure dependencies are all in this Bom.
697+
# 1. Make sure dependencies and provides are all in this Bom.
685698
component_bom_refs = set(map(lambda c: c.bom_ref, self._get_all_components())) | set(
686699
map(lambda s: s.bom_ref, self.services))
700+
687701
dependency_bom_refs = set(chain(
688702
(d.ref for d in self.dependencies),
689-
chain.from_iterable(d.dependencies_as_bom_refs() for d in self.dependencies)
703+
chain.from_iterable(d.dependencies_as_bom_refs() for d in self.dependencies),
704+
chain.from_iterable(d.provides_as_bom_refs() for d in self.dependencies) # Include provides refs here
690705
))
691706
dependency_diff = dependency_bom_refs - component_bom_refs
692707
if len(dependency_diff) > 0:

0 commit comments

Comments
 (0)