Skip to content

harborapi.ext.cve

The harborapi.ext.cve module provides functionality for working with CVSSv3 data.

CVSSData

Bases: BaseModel

Key CVSS statistics for a scanned artifact.

Source code in harborapi/ext/cve.py
class CVSSData(BaseModel):
    """Key CVSS statistics for a scanned artifact."""

    mean: float
    median: float
    stdev: float
    min: float
    max: float

    @classmethod
    def from_artifactinfo(cls, artifact: "ArtifactInfo") -> "CVSSData":
        """Create a CVSSData instance from an ArtifactInfo object.

        Parameters
        ----------
        artifact : ArtifactInfo
            The artifact to extract CVSS data from.

        Returns
        -------
        CVSSData
            The CVSS data for the artifact.

        See Also
        --------
        [ArtifactInfo.cvss][harborapi.ext.artifact.ArtifactInfo.cvss]
        """
        scores = artifact.report.cvss_scores
        return cls(
            mean=stats.mean(scores),
            median=stats.median(scores),
            stdev=stats.stdev(scores),
            min=stats.min(scores),
            max=stats.max(scores),
        )

    @classmethod
    def from_report(cls, report: "ArtifactReport") -> "CVSSData":
        """Create a CVSSData instance from an ArtifactReport object.

        Parameters
        ----------
        report : ArtifactReport
            The report to extract CVSS data from.

        Returns
        -------
        CVSSData
            The CVSS data for the report.
        """
        # Wrap generator in list to allow for re-use
        scores = list(
            chain.from_iterable([a.report.cvss_scores for a in report.artifacts])
        )
        return cls(
            mean=stats.mean(scores),
            median=stats.median(scores),
            stdev=stats.stdev(scores),
            min=stats.min(scores),
            max=stats.max(scores),
        )

from_artifactinfo(artifact) classmethod

Create a CVSSData instance from an ArtifactInfo object.

Parameters:

Name Type Description Default
artifact ArtifactInfo

The artifact to extract CVSS data from.

required

Returns:

Type Description
CVSSData

The CVSS data for the artifact.

See Also

ArtifactInfo.cvss

Source code in harborapi/ext/cve.py
@classmethod
def from_artifactinfo(cls, artifact: "ArtifactInfo") -> "CVSSData":
    """Create a CVSSData instance from an ArtifactInfo object.

    Parameters
    ----------
    artifact : ArtifactInfo
        The artifact to extract CVSS data from.

    Returns
    -------
    CVSSData
        The CVSS data for the artifact.

    See Also
    --------
    [ArtifactInfo.cvss][harborapi.ext.artifact.ArtifactInfo.cvss]
    """
    scores = artifact.report.cvss_scores
    return cls(
        mean=stats.mean(scores),
        median=stats.median(scores),
        stdev=stats.stdev(scores),
        min=stats.min(scores),
        max=stats.max(scores),
    )

from_report(report) classmethod

Create a CVSSData instance from an ArtifactReport object.

Parameters:

Name Type Description Default
report ArtifactReport

The report to extract CVSS data from.

required

Returns:

Type Description
CVSSData

The CVSS data for the report.

Source code in harborapi/ext/cve.py
@classmethod
def from_report(cls, report: "ArtifactReport") -> "CVSSData":
    """Create a CVSSData instance from an ArtifactReport object.

    Parameters
    ----------
    report : ArtifactReport
        The report to extract CVSS data from.

    Returns
    -------
    CVSSData
        The CVSS data for the report.
    """
    # Wrap generator in list to allow for re-use
    scores = list(
        chain.from_iterable([a.report.cvss_scores for a in report.artifacts])
    )
    return cls(
        mean=stats.mean(scores),
        median=stats.median(scores),
        stdev=stats.stdev(scores),
        min=stats.min(scores),
        max=stats.max(scores),
    )