From db6760bb9b0814dbba5d0bb1032c4a08a05ea441 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20K=C3=BCnzel?= <simonk@fsmpi.rwth-aachen.de>
Date: Fri, 24 May 2024 22:56:36 +0200
Subject: [PATCH] Add server name

---
 api_specification.md         | 19 ++++++++++++-------
 config/api_example_config.py |  3 +++
 src/api/routes/site.py       |  3 +++
 tests/routes/site.py         |  2 ++
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/api_specification.md b/api_specification.md
index fe095fe..6f4410f 100644
--- a/api_specification.md
+++ b/api_specification.md
@@ -1,4 +1,4 @@
-# Specification of the Web API for the Video-AG Website (v0.50).
+# Specification of the Web API for the Video-AG Website (v0.51).
 
 ## Introduction
 
@@ -66,12 +66,13 @@ This may be used even if the site is read-only or disabled.
 
 ###### Response:
 
-| Field           | Type                                   | Notes                                                   |
-|-----------------|----------------------------------------|---------------------------------------------------------|
-| status          | id_string                              | possible values: `available`, `readonly`, `unavailable` |
-| is_debug        | boolean                                |                                                         |
-| git_commit_hash | ?string                                |                                                         |
-| announcements   | array of [announcement](#announcement) |                                                         |
+| Field           | Type                                    | Notes                                                   |
+|-----------------|-----------------------------------------|---------------------------------------------------------|
+| status          | id_string                               | possible values: `available`, `readonly`, `unavailable` |
+| is_debug        | boolean                                 |                                                         |
+| git_commit_hash | ?string                                 |                                                         |
+| server_name     | string                                  | Name of the server which is answering the request       |
+| announcements   | array of [announcement](#announcement)  |                                                         |
 
 <details>
 <summary>Example: <code>GET /announcement</code></summary>
@@ -1519,6 +1520,10 @@ Possible `error_code`:
 
 ## Changelog
 
+### v0.51
+
+* Added `server_name` to `GET /status`
+
 ### v0.50
 
 * Removed `GET /announcements`
diff --git a/config/api_example_config.py b/config/api_example_config.py
index 0465506..32996cc 100644
--- a/config/api_example_config.py
+++ b/config/api_example_config.py
@@ -1,6 +1,9 @@
 # Defaults for development, do not use in production!
 DEBUG = True
 
+# Name of this instance
+SERVER_NAME = "dev"
+
 # Prefix which is prepended to paths (which are saved in the database) before they are provided by the api
 # Must include the last /
 FILE_PATH_PREFIX = "https://video.fsmpi.rwth-aachen.de/files/"
diff --git a/src/api/routes/site.py b/src/api/routes/site.py
index 308190a..f9c420d 100644
--- a/src/api/routes/site.py
+++ b/src/api/routes/site.py
@@ -11,6 +11,8 @@ _GIT_COMMIT_HASH = os.environ.get("VIDEOAG_API_GIT_COMMIT_HASH", None)
 if _GIT_COMMIT_HASH is not None and len(_GIT_COMMIT_HASH) == 0:
     _GIT_COMMIT_HASH = None
 
+_SERVER_NAME = api.config["SERVER_NAME"]
+
 
 @api_route("/status", ["GET"], allow_while_readonly=True, allow_while_disabled=True)
 def api_route_status():
@@ -31,6 +33,7 @@ def api_route_status():
     response = {
         "status": status,
         "is_debug": DEBUG_ENABLED,
+        "server_name": _SERVER_NAME,
         "announcements": announcements
     }
     if _GIT_COMMIT_HASH is not None:
diff --git a/tests/routes/site.py b/tests/routes/site.py
index 90b437e..705cbc8 100644
--- a/tests/routes/site.py
+++ b/tests/routes/site.py
@@ -12,6 +12,7 @@ class SiteTest(ApiTest):
             None,
             {
                 "status": "available",
+                "server_name": "dev",
                 "announcements": [
                     TEST_DATA_ANNOUNCEMENT_1,
                     TEST_DATA_ANNOUNCEMENT_2
@@ -26,6 +27,7 @@ class SiteTest(ApiTest):
             None,
             {
                 "status": "available",
+                "server_name": "dev",
                 "announcements": [
                     TEST_DATA_ANNOUNCEMENT_1_MOD,
                     TEST_DATA_ANNOUNCEMENT_2_MOD,
-- 
GitLab