예제 #1
0
def problem(
    status: int = 400,
    title: str = "A problem occured.",
    detail: Optional[str] = None,
    type_: Optional[str] = None,
    ext: Optional[Dict[str, Any]] = None,
):
    problem_dict = {
        "title": title,
        "status": status,
    }
    if detail is not None:
        problem_dict["detail"] = detail
    if type_ is not None:
        problem_dict["type"] = type_

    if isinstance(ext, dict):
        problem_dict.update(ext)
    else:
        if ext:
            problem_dict["ext"] = ext

    response = Response()
    response.status_code = status
    response.set_content_type("application/problem+json")
    response.set_data(json.dumps(problem_dict))
    return response
예제 #2
0
def download_agent(params):
    """Download agents shipped with Checkmk"""
    os_type: str = params.get("os_type")

    if os_type == "windows_msi":
        agent_path = agent.packed_agent_path_windows_msi()
    elif os_type == "linux_rpm":
        agent_path = agent.packed_agent_path_linux_rpm()
    elif os_type == "linux_deb":
        agent_path = agent.packed_agent_path_linux_deb()
    else:
        # This should never happen. Due to validation `os_type` can only be one
        # of the three elements above.
        raise AssertionError(
            f"Agent: os_type '{os_type}' not known in raw edition.")

    response = Response()
    response.headers["Content-Type"] = "application/octet-stream"
    response.headers[
        "Content-Disposition"] = f'attachment; filename="{agent_path.name}"'

    with open(agent_path, mode="rb") as f:
        response.data = f.read()
    response.status_code = 200
    return response
예제 #3
0
파일: utils.py 프로젝트: LinuxHaus/checkmk
def problem(
    status: int = 400,
    title: str = "A problem occurred.",
    detail: Optional[str] = None,
    type_: Optional[str] = None,
    fields: Optional[dict[str, list[str]]] = None,
    ext: Optional[dict[str, Any]] = None,
) -> Response:
    problem_dict = {
        "title": title,
        "status": status,
    }
    if detail is not None:
        problem_dict["detail"] = detail
    if type_ is not None:
        problem_dict["type"] = type_

    if fields is not None:
        problem_dict["fields"] = fields

    if ext is not None:
        problem_dict["ext"] = ext

    response = Response()
    response.status_code = status
    response.set_content_type("application/problem+json")
    response.set_data(json.dumps(problem_dict))
    return response