Skip to content

Target

sereto.cli.target

prompt_user_for_target(categories)

Interactively prompt for a target's details.

Parameters:

Name Type Description Default
categories Iterable[str]

List of all categories to present to the user for selection.

required

Returns:

Type Description
TargetModel

The target as provided by the user.

Source code in sereto/cli/target.py
12
13
14
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
def prompt_user_for_target(categories: Iterable[str]) -> TargetModel:
    """Interactively prompt for a target's details.

    Args:
        categories: List of all categories to present to the user for selection.

    Returns:
        The target as provided by the user.
    """
    Console().line()
    category = radiolist_dialog(
        title="New target",
        text="Category:",
        values=[(c, c.upper()) for c in list(categories)],
    ).run()
    name = prompt("Name: ")

    match category:
        case "dast":
            target: TargetModel = TargetDastModel(category=category, name=name)
        case "sast":
            target = TargetSastModel(category=category, name=name)
        case _:
            target = TargetModel(category=category, name=name)

    target_edited = click.edit(target.model_dump_json(indent=2))

    if target_edited is None:
        raise SeretoRuntimeError("aborting, editor closed without saving")

    return TargetModel.model_validate_json(target_edited)