Source code for ntia_conformance_checker.probes.presence
# SPDX-FileContributor: Arthit Suriyawongkul
# SPDX-FileCopyrightText: 2026-present SPDX contributors
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
"""Built-in presence probes.
Together these two probes cover every active rule in the NTIA and FSCT
catalogues -- rule-id reuse is high because the question being asked is
always the same shape ("is this attribute present?").
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from ..model import COMPONENT_ELEMENT_IDS, DOCUMENT_ELEMENT_IDS, Finding
from ._registry import CheckerProtocol, probe
if TYPE_CHECKING:
from collections.abc import Iterable
[docs]
@probe("require_component_attribute", attributes=COMPONENT_ELEMENT_IDS)
def require_component_attribute(
checker: CheckerProtocol, *, attribute: str
) -> Iterable[Finding]:
"""Require every component in the SBOM to declare ``attribute``.
Yields one :class:`Finding` per component where ``attribute`` is absent
or empty. The component's SPDX-style id and human name are surfaced so
SARIF / JSON / text emitters can locate the failure precisely.
Args:
checker: the running checker instance.
attribute: an element id from
:data:`ntia_conformance_checker.model.COMPONENT_ELEMENT_IDS`,
e.g. ``"supplier"`` / ``"concluded_license"``.
"""
for comp_name, comp_id in checker.components_without(attribute):
yield Finding(
component_id=comp_id or "",
component_name=comp_name or "",
)
[docs]
@probe("require_document_attribute", attributes=DOCUMENT_ELEMENT_IDS)
def require_document_attribute(
checker: CheckerProtocol, *, attribute: str
) -> Iterable[Finding]:
"""Require the SBOM document to declare ``attribute``.
Yields a single document-level :class:`Finding` when the attribute is
absent; yields nothing when present.
Args:
checker: the running checker instance.
attribute: an element id from
:data:`ntia_conformance_checker.model.DOCUMENT_ELEMENT_IDS`,
e.g. ``"author"`` / ``"dependency_relationship"``.
"""
if not checker.document_has(attribute):
yield Finding(component_id="document", component_name="")