Skip to content

Risks

sereto.models.risks

Risk

Bases: SeretoBaseModel

Represents a risk with a name, count, and color.

Attributes:

Name Type Description
name str

The name of the risk.

cnt NonNegativeInt

How many findings share the same risk level.

color str

The color associated with the risk.

Source code in sereto/models/risks.py
 8
 9
10
11
12
13
14
15
16
17
18
19
class Risk(SeretoBaseModel):
    """Represents a risk with a name, count, and color.

    Attributes:
        name: The name of the risk.
        cnt: How many findings share the same risk level.
        color: The color associated with the risk.
    """

    name: str
    cnt: NonNegativeInt
    color: str

Risks

Bases: SeretoBaseModel

A class representing the full spectre of risk severity levels.

This class contains Risk objects representing different severity levels of risks. It provides methods to retrieve the names, counters, and colors of the risks, as well as a method to set the count of each risk.

Attributes:

Name Type Description
critical Risk

A Risk object representing the critical severity level.

high Risk

A Risk object representing the high severity level.

medium Risk

A Risk object representing the medium severity level.

low Risk

A Risk object representing the low severity level.

info Risk

A Risk object representing the info severity level.

Source code in sereto/models/risks.py
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
class Risks(SeretoBaseModel):
    """A class representing the full spectre of risk severity levels.

    This class contains Risk objects representing different severity levels of risks.
    It provides methods to retrieve the names, counters, and colors of the risks,
    as well as a method to set the count of each risk.

    Attributes:
        critical: A Risk object representing the critical severity level.
        high: A Risk object representing the high severity level.
        medium: A Risk object representing the medium severity level.
        low: A Risk object representing the low severity level.
        info: A Risk object representing the info severity level.
    """

    critical: Risk = Risk(name="critical", cnt=0, color="red")
    high: Risk = Risk(name="high", cnt=0, color="orange")
    medium: Risk = Risk(name="medium", cnt=0, color="#f0f000")
    low: Risk = Risk(name="low", cnt=0, color="#33cc33")
    info: Risk = Risk(name="info", cnt=0, color="#3366ff")

    def names(self) -> tuple[str, ...]:
        """Return a tuple of the names for each severity.

        The risk names are sorted from the most severe ones to the least severe.

        Returns:
            A tuple containing the names of all the Risk objects.
        """
        return (
            self.critical.name,
            self.high.name,
            self.medium.name,
            self.low.name,
            self.info.name,
        )

    def counts(self) -> tuple[int, ...]:
        """Return a tuple of the counters for each severity level.

        The counters are sorted from the most severe risks to the least severe.

        Returns:
            A tuple of per risk counters for each severity level.
        """
        return (self.critical.cnt, self.high.cnt, self.medium.cnt, self.low.cnt, self.info.cnt)

    def colors(self) -> tuple[str, ...]:
        """Return a tuple of the colors for each severity level.

        The risk colors are sorted by severity, from the most severe ones to the least severe.

        Returns:
            A tuple containing the colors of the Risk objects.
        """
        return (self.critical.color, self.high.color, self.medium.color, self.low.color, self.info.color)

    def set_counts(
        self,
        critical: NonNegativeInt,
        high: NonNegativeInt,
        medium: NonNegativeInt,
        low: NonNegativeInt,
        info: NonNegativeInt,
    ) -> Self:
        """Set the count of each Risk object in the Risks object.

        Args:
            critical: An integer representing the count of the critical Risk object.
            high: An integer representing the count of the high Risk object.
            medium: An integer representing the count of the medium Risk object.
            low: An integer representing the count of the low Risk object.
            info: An integer representing the count of the info Risk object.

        Returns:
            The Risks object with updated counts for each Risk object.
        """
        self.critical.cnt = critical
        self.high.cnt = high
        self.medium.cnt = medium
        self.low.cnt = low
        self.info.cnt = info
        return self

colors()

Return a tuple of the colors for each severity level.

The risk colors are sorted by severity, from the most severe ones to the least severe.

Returns:

Type Description
tuple[str, ...]

A tuple containing the colors of the Risk objects.

Source code in sereto/models/risks.py
69
70
71
72
73
74
75
76
77
def colors(self) -> tuple[str, ...]:
    """Return a tuple of the colors for each severity level.

    The risk colors are sorted by severity, from the most severe ones to the least severe.

    Returns:
        A tuple containing the colors of the Risk objects.
    """
    return (self.critical.color, self.high.color, self.medium.color, self.low.color, self.info.color)

counts()

Return a tuple of the counters for each severity level.

The counters are sorted from the most severe risks to the least severe.

Returns:

Type Description
tuple[int, ...]

A tuple of per risk counters for each severity level.

Source code in sereto/models/risks.py
59
60
61
62
63
64
65
66
67
def counts(self) -> tuple[int, ...]:
    """Return a tuple of the counters for each severity level.

    The counters are sorted from the most severe risks to the least severe.

    Returns:
        A tuple of per risk counters for each severity level.
    """
    return (self.critical.cnt, self.high.cnt, self.medium.cnt, self.low.cnt, self.info.cnt)

names()

Return a tuple of the names for each severity.

The risk names are sorted from the most severe ones to the least severe.

Returns:

Type Description
tuple[str, ...]

A tuple containing the names of all the Risk objects.

Source code in sereto/models/risks.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def names(self) -> tuple[str, ...]:
    """Return a tuple of the names for each severity.

    The risk names are sorted from the most severe ones to the least severe.

    Returns:
        A tuple containing the names of all the Risk objects.
    """
    return (
        self.critical.name,
        self.high.name,
        self.medium.name,
        self.low.name,
        self.info.name,
    )

set_counts(critical, high, medium, low, info)

Set the count of each Risk object in the Risks object.

Parameters:

Name Type Description Default
critical NonNegativeInt

An integer representing the count of the critical Risk object.

required
high NonNegativeInt

An integer representing the count of the high Risk object.

required
medium NonNegativeInt

An integer representing the count of the medium Risk object.

required
low NonNegativeInt

An integer representing the count of the low Risk object.

required
info NonNegativeInt

An integer representing the count of the info Risk object.

required

Returns:

Type Description
Self

The Risks object with updated counts for each Risk object.

Source code in sereto/models/risks.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def set_counts(
    self,
    critical: NonNegativeInt,
    high: NonNegativeInt,
    medium: NonNegativeInt,
    low: NonNegativeInt,
    info: NonNegativeInt,
) -> Self:
    """Set the count of each Risk object in the Risks object.

    Args:
        critical: An integer representing the count of the critical Risk object.
        high: An integer representing the count of the high Risk object.
        medium: An integer representing the count of the medium Risk object.
        low: An integer representing the count of the low Risk object.
        info: An integer representing the count of the info Risk object.

    Returns:
        The Risks object with updated counts for each Risk object.
    """
    self.critical.cnt = critical
    self.high.cnt = high
    self.medium.cnt = medium
    self.low.cnt = low
    self.info.cnt = info
    return self