Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iainland/healthz html response #158

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions evolver/app/html_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import socket

from fastapi import FastAPI
from fastapi.responses import HTMLResponse

from evolver import __project__, __version__

html_app = FastAPI()


@html_app.get("/network", operation_id="network_state_html", response_class=HTMLResponse)
async def network_html():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
html_content = f"""
<html>
<head>
<title>Evolver</title>
</head>
<body>
<h1>device network details</h1>
<p>Running '{__project__}' ver: '{__version__}'</p>
<p>Hostname: {hostname}</p>
<p>IP Address: {ip_address}</p>
</body>
</html>
"""
return html_content
4 changes: 4 additions & 0 deletions evolver/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import evolver.util
from evolver import __project__, __version__
from evolver.app.exceptions import CalibratorNotFoundError, HardwareNotFoundError
from evolver.app.html_routes import html_app
from evolver.app.models import SchemaResponse
from evolver.base import require_all_fields
from evolver.device import Evolver
Expand Down Expand Up @@ -118,6 +119,9 @@ async def calibrate(name: str, data: dict = None):
return calibrator.run_calibration_procedure(data) # TODO: or **data?


app.mount("/html", html_app)


def start():
import uvicorn

Expand Down
17 changes: 17 additions & 0 deletions evolver/app/tests/test_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from evolver import __version__


class TestHtmlApp:
def test_html_network(self, app_client):
response = app_client.get("/html/network")
assert response.status_code == 200
assert response.headers["content-type"] == "text/html; charset=utf-8"

html_content = response.text
assert "<html>" in html_content
assert "<title>Evolver</title>" in html_content
if __version__:
assert __version__ in html_content
assert "device network details" in html_content
assert "Hostname:" in html_content
assert "IP Address:" in html_content
Loading