|
16 | 16 | #
|
17 | 17 | # SPDX-License-Identifier: Apache-2.0
|
18 | 18 | # Copyright (c) OWASP Foundation. All Rights Reserved.
|
19 |
| - |
| 19 | +import warnings |
20 | 20 | from datetime import datetime, timezone
|
21 | 21 | from typing import Iterable, Optional, Set
|
22 | 22 | from uuid import UUID, uuid4
|
@@ -374,13 +374,25 @@ def validate(self) -> bool:
|
374 | 374 | """
|
375 | 375 |
|
376 | 376 | # 1. Make sure dependencies are all in this Bom.
|
377 |
| - all_component_bom_refs = set(map(lambda c: c.bom_ref, self.components)) |
| 377 | + all_bom_refs = set([self.metadata.component.bom_ref] if self.metadata.component else []).union( |
| 378 | + set(map(lambda c: c.bom_ref, self.components)), |
| 379 | + set(map(lambda s: s.bom_ref, self.services)) |
| 380 | + ) |
378 | 381 | all_dependency_bom_refs = set().union(*(c.dependencies for c in self.components))
|
379 |
| - dependency_diff = list(all_dependency_bom_refs.difference(all_component_bom_refs)) |
| 382 | + dependency_diff = list(all_dependency_bom_refs.difference(all_bom_refs)) |
380 | 383 | if len(dependency_diff) > 0:
|
381 | 384 | raise UnknownComponentDependencyException(
|
382 |
| - f'One or more Components have Dependency references to Components that are not known in this BOM. ' |
383 |
| - f'They are: {dependency_diff}') |
| 385 | + f'One or more Components have Dependency references to Components/Services that are not known in this ' |
| 386 | + f'BOM. They are: {dependency_diff}') |
| 387 | + |
| 388 | + # 2. Dependencies should exist for the Component this BOM is describing, if one is set |
| 389 | + if self.metadata.component and not self.metadata.component.dependencies: |
| 390 | + warnings.warn( |
| 391 | + f'The Component this BOM is describing {self.metadata.component.purl} has no defined dependencies' |
| 392 | + f'which means the Dependency Graph is incomplete - you should add direct dependencies to this Component' |
| 393 | + f'to complete the Dependency Graph data.', |
| 394 | + UserWarning |
| 395 | + ) |
384 | 396 |
|
385 | 397 | return True
|
386 | 398 |
|
|
0 commit comments