Skip to content

Commit c31aacd

Browse files
author
Alan Christie
committed
feat: Initial support for /version query
1 parent 169239d commit c31aacd

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

.github/workflows/tag.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
run: echo "owner=${OWNER,,}" >> "$GITHUB_ENV"
4343
env:
4444
OWNER: '${{ github.repository_owner }}'
45+
- name: Set version
46+
run: echo ${{ github.ref_name }} > VERSION
4547
- name: Build and Push (Tag)
4648
uses: docker/build-push-action@v6
4749
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ repos:
3030
- id: check-shebang-scripts-are-executable
3131
- id: detect-private-key
3232
- id: end-of-file-fixer
33+
exclude: 'VERSION'
3334
- id: trailing-whitespace
3435
args:
3536
- --markdown-linebreak-ext=md

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ ENV PATH=/.venv/bin:$PATH
5151
COPY app/ ./app/
5252
COPY logging.config .
5353
COPY docker-entrypoint.sh .
54-
COPY internal.env ./
55-
COPY public.env ./
54+
COPY internal.env .
55+
COPY public.env .
56+
COPY VERSION .
5657

5758
# Probes...
5859
COPY probes/*.sh .

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.0

app/app.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
# SQLite database path
4242
_DATABASE_PATH = "/data/event-streams.db"
4343

44+
with open("VERSION", "r", encoding="utf-8") as version_file:
45+
_VERSION: str = version_file.read().strip()
46+
4447

4548
def _get_location(uuid: str) -> str:
4649
"""Returns the location (URL) for the event stream with the given UUID."""
@@ -95,6 +98,18 @@ class EventStreamPostRequestBody(BaseModel):
9598
routing_key: str
9699

97100

101+
class EventStreamGetVersionResponse(BaseModel):
102+
"""/event-stream/version/ GET response."""
103+
104+
# Category of the service (enumeration).
105+
# We're a 'WEBSOCKET'
106+
category: str
107+
# Our name (ours is 'Python FastAPI')
108+
name: str
109+
# Our version number
110+
version: str
111+
112+
98113
class EventStreamPostResponse(BaseModel):
99114
"""/event-stream/ POST response."""
100115

@@ -214,7 +229,18 @@ async def _get_from_queue(routing_key: str):
214229
# Endpoints for the 'internal' event-stream management API -----------------------------
215230

216231

217-
@app_internal.post("/event-stream/", status_code=status.HTTP_201_CREATED)
232+
@app_internal.post("/event-stream/version/", status_code=status.HTTP_200_CREATED)
233+
def get_es_version() -> EventStreamGetVersionResponse:
234+
"""Returns our version information."""
235+
# And construct the location we'll be listening on...
236+
return EventStreamPostResponse(
237+
category="WEBSOCKET",
238+
name="Python FastAPI",
239+
version=_VERSION,
240+
)
241+
242+
243+
@app_internal.post("/event-stream/", status_code=status.HTTP_201_OK)
218244
def post_es(request_body: EventStreamPostRequestBody) -> EventStreamPostResponse:
219245
"""Create a new event-stream returning the endpoint location.
220246

0 commit comments

Comments
 (0)