Skip to content

Commit 79f2bb0

Browse files
authored
Merge pull request #4 from netz39/adapt-api
Adapt API to the existing spec
2 parents 07e8324 + 3efa17f commit 79f2bb0

File tree

3 files changed

+88
-5
lines changed

3 files changed

+88
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN git describe --always --dirty > /git-version.txt
88
FROM python:3.12
99

1010
EXPOSE 8080
11-
HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/v0/health || exit 1
11+
HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/health || exit 1
1212

1313
COPY src/OAS3.yml /
1414

src/OAS3.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Space Status API
4+
version: 1.0.0
5+
description: API for retrieving space status and related information.
6+
servers:
7+
- url: http://localhost:8080/
8+
description: Local development server
9+
- url: https://spaceapi.n39.eu/
10+
description: Netz39 SpaceAPI server
11+
paths:
12+
/health:
13+
get:
14+
summary: Health check endpoint
15+
responses:
16+
'200':
17+
description: Health check information
18+
content:
19+
application/json:
20+
schema:
21+
type: object
22+
properties:
23+
api_version:
24+
type: string
25+
git_version:
26+
type: string
27+
timestamp:
28+
type: string
29+
format: date-time
30+
uptime:
31+
type: string
32+
format: duration
33+
/oas3:
34+
get:
35+
summary: OpenAPI Specification
36+
responses:
37+
'200':
38+
description: OpenAPI Specification
39+
content:
40+
text/plain:
41+
schema:
42+
type: string
43+
/json:
44+
get:
45+
summary: Space API entry in JSON format
46+
responses:
47+
'200':
48+
description: Space API entry
49+
content:
50+
application/json:
51+
schema:
52+
type: object
53+
/text:
54+
get:
55+
summary: Space state in plain text
56+
responses:
57+
'200':
58+
description: Space state
59+
content:
60+
text/plain:
61+
schema:
62+
type: string
63+
/state.png:
64+
get:
65+
summary: Space state as an image
66+
responses:
67+
'200':
68+
description: Space state image
69+
content:
70+
image/png:
71+
schema:
72+
type: string
73+
format: binary

src/app.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ def get(self):
8484
self.write(json.dumps(self.observer.get_space_api_entry(), indent=4))
8585
self.finish()
8686

87+
class SpaceStateTextHandler(tornado.web.RequestHandler, ABC):
88+
# noinspection PyAttributeOutsideInit
89+
def initialize(self, observer):
90+
self.observer = observer
91+
92+
def get(self):
93+
self.set_header("Content-Type", "text/plain")
94+
self.write("open" if self.observer.space_api_entry.is_open() else "closed")
95+
self.finish()
96+
8797

8898
class PictureHandler(tornado.web.RequestHandler, ABC):
8999
# noinspection PyAttributeOutsideInit
@@ -97,11 +107,11 @@ def get(self):
97107

98108

99109
def make_app(observer, picture_manager):
100-
version_path = r"/v[0-9]"
101110
return tornado.web.Application([
102-
(version_path + r"/health", HealthHandler),
103-
(version_path + r"/oas3", Oas3Handler),
104-
(r"/", SpaceAPIHandler, dict(observer=observer)),
111+
(r"/health", HealthHandler),
112+
(r"/oas3", Oas3Handler),
113+
(r"/json", SpaceAPIHandler, dict(observer=observer)),
114+
(r"/text", SpaceStateTextHandler, dict(observer=observer)),
105115
(r"/state.png", PictureHandler, dict(picture_manager=picture_manager)),
106116
])
107117

0 commit comments

Comments
 (0)