Skip to content

Finding

sereto.cli.finding

add_finding(project, template_path, finding_name=None, risk=None, target_selector=None, group_uname=None, group_name=None, variables=(), overwrite=False)

Add a finding from a template non-interactively.

Parameters:

Name Type Description Default
project Project

Project's representation.

required
template_path FilePath

Path to the finding template file.

required
finding_name str | None

Name for the sub-finding.

None
risk Risk | None

Risk level override.

None
target_selector str | None

Target selector (index or uname).

None
group_uname str | None

Uname of existing finding group to append to.

None
group_name str | None

Name for the new finding group.

None
variables tuple[str, ...]

Template variables as KEY=VALUE strings.

()
overwrite bool

If True, overwrite existing sub-finding instead of generating a unique suffix.

False
Source code in sereto/cli/finding.py
15
16
17
18
19
20
21
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
@validate_call
def add_finding(
    project: Project,
    template_path: FilePath,
    finding_name: str | None = None,
    risk: Risk | None = None,
    target_selector: str | None = None,
    group_uname: str | None = None,
    group_name: str | None = None,
    variables: tuple[str, ...] = (),
    overwrite: bool = False,
) -> None:
    """Add a finding from a template non-interactively.

    Args:
        project: Project's representation.
        template_path: Path to the finding template file.
        finding_name: Name for the sub-finding.
        risk: Risk level override.
        target_selector: Target selector (index or uname).
        group_uname: Uname of existing finding group to append to.
        group_name: Name for the new finding group.
        variables: Template variables as KEY=VALUE strings.
        overwrite: If True, overwrite existing sub-finding instead of generating a unique suffix.
    """
    parsed_vars: dict[str, Any] = {}
    for var_str in variables:
        if "=" not in var_str:
            raise SeretoValueError(f"invalid variable format: {var_str!r}; expected KEY=VALUE")
        key, _, value_str = var_str.partition("=")
        try:
            parsed_vars[key] = json.loads(value_str)
        except json.JSONDecodeError:
            parsed_vars[key] = value_str

    target = project.config.last_config.select_target(categories=project.settings.categories, selector=target_selector)

    if group_uname is not None and not any(g.uname == group_uname for g in target.findings.groups):
        raise SeretoValueError(f"finding group with uname {group_uname!r} not found in target {target.uname!r}")

    target.findings.add_from_template(
        templates=project.settings.templates_path,
        template_path=template_path,
        category=target.data.category,
        sub_finding_name=finding_name,
        risk=risk,
        variables=parsed_vars,
        group_uname=group_uname,
        group_name=group_name,
        overwrite=overwrite,
    )

show_findings(version_config)

Show the findings for a specific version.

Parameters:

Name Type Description Default
version_config VersionConfig

The project configuration for specific version.

required
Source code in sereto/cli/finding.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@validate_call
def show_findings(version_config: VersionConfig) -> None:
    """Show the findings for a specific version.

    Args:
        version_config: The project configuration for specific version.
    """

    for target in version_config.targets:
        Console().line()
        table = Table(
            "%", "Finding name", "Category", "Risk", title=f"Target {version_config.version}", box=box.MINIMAL
        )

        for ix, finding_group in enumerate(target.findings.groups, start=1):
            table.add_row(str(ix), finding_group.suggested_name, target.data.category, finding_group.risk)

        Console().print(table, justify="center")