Skip to content

Building blocks

This page provides an overview of the building blocks for creating your custom templates. See Templating - Jinja2 for details on how the variables can be included in the templates.

This is so far valid for the report.tex.j2 and sow.tex.j2 templates.

Variables

  • c: The VersionConfig object for the current version of the project.
  • config: The full Config object (most of the time, you should use c instead).
  • version: The version of the project.
  • project_path: Path object to the project directory.

VersionConfig variables

The attributes of the c object are also accessible directly. Primarily, the c object is used for invoking methods.

  • id: The ID of the project.
  • name: The name of the project.
  • version_description: The description of the version (e.g. "retest").
  • targets: List of targets.
  • dates: List of dates.
  • people: List of people.

Methods for the c object

The following methods can be invoked from the c object.

Example usage:

c.filter_targets(category=["dast", "sast"], name="^foo")]
c.filter_dates(type="pentest_ongoing", start="01-Jan-2024", end="31-Jan-2024")
c.filter_people(type="author", email="@foo.bar$")

sereto.models.config.VersionConfig.filter_targets(category=None, name=None, inverse=False)

Filter targets based on specified criteria.

The regular expressions support the syntax of Python's re module.

Parameters:

Name Type Description Default
category str | Iterable[str] | None

The category of the target. Can be a single category, a list of categories, or None.

None
name str | None

Regular expression to match the name of the target.

None
inverse bool

If True, return the inverse of the usual results.

False

Returns:

Type Description
list[Target]

A list of targets matching the criteria.

Source code in sereto/models/config.py
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
@validate_call
def filter_targets(
    self,
    category: str | Iterable[str] | None = None,
    name: str | None = None,
    inverse: bool = False,
) -> list[Target]:
    """Filter targets based on specified criteria.

    The regular expressions support the syntax of Python's `re` module.

    Args:
        category: The category of the target. Can be a single category, a list of categories, or None.
        name: Regular expression to match the name of the target.
        inverse: If True, return the inverse of the usual results.

    Returns:
        A list of targets matching the criteria.
    """
    if isinstance(category, str):
        category = [category]

    filtered_targets = [
        t
        for t in self.targets
        if (category is None or t.category in category) and (name is None or re.search(name, t.name))
    ]

    if inverse:
        return [t for t in self.targets if t not in filtered_targets]
    return filtered_targets

sereto.models.config.VersionConfig.filter_dates(type=None, start=None, end=None, inverse=False)

Filter dates based on specified criteria.

The start and end dates are inclusive. For date ranges, a date is considered matching if it completely overlaps with the specified range.

Parameters:

Name Type Description Default
type str | DateType | Iterable[str] | Iterable[DateType] | None

The type of the date. Can be a single type, a list of types, or None.

None
start str | SeretoDate | None

Only dates on or after this date will be included.

None
end str | SeretoDate | None

Only dates on or before this date will be included.

None
inverse bool

If True, return the inverse of the usual results.

False

Returns:

Type Description
list[Date]

A list of dates matching the criteria.

Source code in sereto/models/config.py
 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@validate_call
def filter_dates(
    self,
    type: str | DateType | Iterable[str] | Iterable[DateType] | None = None,
    start: str | SeretoDate | None = None,
    end: str | SeretoDate | None = None,
    inverse: bool = False,
) -> list[Date]:
    """Filter dates based on specified criteria.

    The start and end dates are inclusive. For date ranges, a date is considered matching if it completely overlaps
    with the specified range.

    Args:
        type: The type of the date. Can be a single type, a list of types, or None.
        start: Only dates on or after this date will be included.
        end: Only dates on or before this date will be included.
        inverse: If True, return the inverse of the usual results.

    Returns:
        A list of dates matching the criteria.
    """
    match type:
        case str():
            type = [DateType(type)]
        case Iterable():
            type = [DateType(t) for t in type]
        case None:
            pass

    if isinstance(start, str):
        start = SeretoDate.from_str(start)
    if isinstance(end, str):
        end = SeretoDate.from_str(end)

    filtered_dates = [
        d
        for d in self.dates
        if (type is None or d.type in type)
        and (
            start is None
            or (isinstance(d.date, SeretoDate) and d.date >= start)
            or (isinstance(d.date, DateRange) and d.date.start >= start)
        )
        and (
            end is None
            or (isinstance(d.date, SeretoDate) and d.date <= end)
            or (isinstance(d.date, DateRange) and d.date.end <= end)
        )
    ]

    if inverse:
        return [d for d in self.dates if d not in filtered_dates]
    return filtered_dates

sereto.models.config.VersionConfig.filter_people(type=None, name=None, business_unit=None, email=None, role=None, inverse=False)

Filter people based on specified criteria.

The regular expressions support the syntax of Python's re module.

Parameters:

Name Type Description Default
type str | PersonType | Iterable[str] | Iterable[PersonType] | None

The type of the person. Can be a single type, a list of types, or None.

None
name str | None

Regular expression to match the name of the person.

None
business_unit str | None

Regular expression to match the business unit of the person.

None
email str | None

Regular expression to match the email of the person.

None
role str | None

Regular expression to match the role of the person.

None
inverse bool

If True, return the inverse of the usual results.

False

Returns:

Type Description
list[Person]

A list of people matching the criteria.

Source code in sereto/models/config.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@validate_call
def filter_people(
    self,
    type: str | PersonType | Iterable[str] | Iterable[PersonType] | None = None,
    name: str | None = None,
    business_unit: str | None = None,
    email: str | None = None,
    role: str | None = None,
    inverse: bool = False,
) -> list[Person]:
    """Filter people based on specified criteria.

    The regular expressions support the syntax of Python's `re` module.

    Args:
        type: The type of the person. Can be a single type, a list of types, or None.
        name: Regular expression to match the name of the person.
        business_unit: Regular expression to match the business unit of the person.
        email: Regular expression to match the email of the person.
        role: Regular expression to match the role of the person.
        inverse: If True, return the inverse of the usual results.

    Returns:
        A list of people matching the criteria.
    """
    match type:
        case str():
            type = [PersonType(type)]
        case Iterable():
            type = [PersonType(t) for t in type]
        case None:
            pass

    filtered_people = [
        p
        for p in self.people
        if (type is None or p.type in type)
        and (name is None or (p.name is not None and re.search(name, p.name)))
        and (business_unit is None or (p.business_unit is not None and re.search(business_unit, p.business_unit)))
        and (email is None or (p.email is not None and re.search(email, p.email)))
        and (role is None or (p.role is not None and re.search(role, p.role)))
    ]

    if inverse:
        return [p for p in self.people if p not in filtered_people]
    return filtered_people