Ejemplo n.º 1
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
Ejemplo n.º 2
0
def serve_file(
    file_name: str,
    content: bytes,
    default_content_type="text/plain; charset=utf-8",
) -> Response:
    """Construct and cache a Response from a static file."""
    content_type, _ = mimetypes.guess_type(file_name)

    resp = Response()
    resp.direct_passthrough = True
    resp.data = content
    if content_type is not None:
        resp.headers["Content-Type"] = content_type
    else:
        resp.headers["Content-Type"] = default_content_type
    resp.freeze()
    return resp
Ejemplo n.º 3
0
def serve_spec(
    site: str,
    target: EndpointTarget,
    url: str,
    content_type: str,
    serializer: Callable[[Dict[str, Any]], str],
) -> Response:
    data = generate_data(target=target)
    data.setdefault("servers", [])
    add_once(
        data["servers"],
        {
            "url": url,
            "description": f"Site: {site}",
        },
    )
    response = Response(status=200)
    response.data = serializer(data)
    response.content_type = content_type
    response.freeze()
    return response