def get_scenarios()

in dyno/app/api/control.py [0:0]


def get_scenarios() -> dict:
    """
    Fetch a list of scenarios.

    Exposed via HTTP at /api/scenarios
    Supported HTTP methods: GET

    Returns
    -------
    dict
        A dictionary containing a list of scenarios under the `scenarios` key.
        HTTP clients will receive the return as JSON.

    Note
    ----
    To add a new scenario to the application, it must be added to the
    scenarios/ folder before it appears in this list.

    Examples
    --------
    ❯ curl -s http://localhost:8999/api/scenarios|jq
    {
        "scenarios": [
            "dyno",
            "molotov_scenarios",
            "high_error_rates"
        ]
    }
    """
    cur_dir = os.path.dirname(os.path.realpath(__file__))
    scenario_dir = os.path.join(cur_dir, "../../../scenarios")

    files = os.listdir(scenario_dir)

    ret = {'scenarios': []}

    for file in files:
        if file.startswith('__'):
            continue
        base_name = Path(file).stem
        ret['scenarios'].append(base_name)
    return ret