From f5e5c559315758739101b6f8603207b49e750692 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Sat, 2 Nov 2024 15:02:27 +0100 Subject: [PATCH 1/4] Fix JSON path to /json --- src/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.py b/src/app.py index 14911a9..17c32b5 100644 --- a/src/app.py +++ b/src/app.py @@ -101,7 +101,7 @@ def make_app(observer, picture_manager): return tornado.web.Application([ (version_path + r"/health", HealthHandler), (version_path + r"/oas3", Oas3Handler), - (r"/", SpaceAPIHandler, dict(observer=observer)), + (r"/json", SpaceAPIHandler, dict(observer=observer)), (r"/state.png", PictureHandler, dict(picture_manager=picture_manager)), ]) From c5f56a02bd2fcc353d54eed8e2a0919d9bc7e238 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Sat, 2 Nov 2024 15:05:32 +0100 Subject: [PATCH 2/4] Add the /text endpoint --- src/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/app.py b/src/app.py index 17c32b5..ee2679e 100644 --- a/src/app.py +++ b/src/app.py @@ -84,6 +84,16 @@ def get(self): self.write(json.dumps(self.observer.get_space_api_entry(), indent=4)) self.finish() +class SpaceStateTextHandler(tornado.web.RequestHandler, ABC): + # noinspection PyAttributeOutsideInit + def initialize(self, observer): + self.observer = observer + + def get(self): + self.set_header("Content-Type", "text/plain") + self.write("open" if self.observer.space_api_entry.is_open() else "closed") + self.finish() + class PictureHandler(tornado.web.RequestHandler, ABC): # noinspection PyAttributeOutsideInit @@ -102,6 +112,7 @@ def make_app(observer, picture_manager): (version_path + r"/health", HealthHandler), (version_path + r"/oas3", Oas3Handler), (r"/json", SpaceAPIHandler, dict(observer=observer)), + (r"/text", SpaceStateTextHandler, dict(observer=observer)), (r"/state.png", PictureHandler, dict(picture_manager=picture_manager)), ]) From 9c39830272da1796bd739827f87b3e7e17697309 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Sat, 2 Nov 2024 15:07:12 +0100 Subject: [PATCH 3/4] Remove the version tag The version tag has never been part of the space api spec --- Dockerfile | 2 +- src/app.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 968a753..c9247a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN git describe --always --dirty > /git-version.txt FROM python:3.12 EXPOSE 8080 -HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/v0/health || exit 1 +HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/health || exit 1 COPY src/OAS3.yml / diff --git a/src/app.py b/src/app.py index ee2679e..2768c0b 100644 --- a/src/app.py +++ b/src/app.py @@ -107,10 +107,9 @@ def get(self): def make_app(observer, picture_manager): - version_path = r"/v[0-9]" return tornado.web.Application([ - (version_path + r"/health", HealthHandler), - (version_path + r"/oas3", Oas3Handler), + (r"/health", HealthHandler), + (r"/oas3", Oas3Handler), (r"/json", SpaceAPIHandler, dict(observer=observer)), (r"/text", SpaceStateTextHandler, dict(observer=observer)), (r"/state.png", PictureHandler, dict(picture_manager=picture_manager)), From 3efa17fb63e7bcbd0e6f83bc1efdfff0cdaa9be2 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Sat, 2 Nov 2024 15:08:44 +0100 Subject: [PATCH 4/4] Add the OAS3 spec --- src/OAS3.yml | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/OAS3.yml b/src/OAS3.yml index e69de29..f06f9ed 100644 --- a/src/OAS3.yml +++ b/src/OAS3.yml @@ -0,0 +1,73 @@ +openapi: 3.0.0 +info: + title: Space Status API + version: 1.0.0 + description: API for retrieving space status and related information. +servers: + - url: http://localhost:8080/ + description: Local development server + - url: https://spaceapi.n39.eu/ + description: Netz39 SpaceAPI server +paths: + /health: + get: + summary: Health check endpoint + responses: + '200': + description: Health check information + content: + application/json: + schema: + type: object + properties: + api_version: + type: string + git_version: + type: string + timestamp: + type: string + format: date-time + uptime: + type: string + format: duration + /oas3: + get: + summary: OpenAPI Specification + responses: + '200': + description: OpenAPI Specification + content: + text/plain: + schema: + type: string + /json: + get: + summary: Space API entry in JSON format + responses: + '200': + description: Space API entry + content: + application/json: + schema: + type: object + /text: + get: + summary: Space state in plain text + responses: + '200': + description: Space state + content: + text/plain: + schema: + type: string + /state.png: + get: + summary: Space state as an image + responses: + '200': + description: Space state image + content: + image/png: + schema: + type: string + format: binary