Skip to content

Commit

Permalink
feat(metadata): endpoint returns info as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Dec 19, 2024
1 parent dcc8e43 commit 4afa479
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions eligibility_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from flask_restful import Api

from eligibility_server import __version__, db, sentry
from eligibility_server.db.models import Metadata
from eligibility_server.keypair import get_server_public_key
from eligibility_server.settings import Configuration
from eligibility_server.verify import Verify
Expand Down Expand Up @@ -53,6 +54,17 @@ def healthcheck():
return TextResponse("Healthy")


@app.route("/metadata")
def metadata():
app.logger.info("Request metadata")

md = Metadata.query.first()
return {
"app": {"version": __version__},
"db": {"timestamp": md.timestamp, "users": md.users, "eligibility": md.eligibility},
}


@app.route("/publickey")
def publickey():
app.logger.info("Request public key")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import re

from eligibility_server import __version__
from eligibility_server.settings import APP_NAME
from eligibility_server.keypair import get_server_public_key

Expand All @@ -20,6 +21,23 @@ def test_healthcheck(client):
assert "Strict-Transport-Security" in response.headers


def test_metadata(client):
response = client.get("metadata")
assert response.status_code == 200
assert response.mimetype == "application/json"
assert "Strict-Transport-Security" in response.headers

data = response.json

assert "app" in data
assert data["app"]["version"] == __version__
assert "db" in data
assert isinstance(data["db"]["timestamp"], str)
assert isinstance(data["db"]["users"], int)
assert isinstance(data["db"]["eligibility"], list)
assert len(data["db"]["eligibility"]) > 0


def test_404(client):
response = client.get("/random")

Expand Down

0 comments on commit 4afa479

Please sign in to comment.