aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--snekbox/api/resources/__init__.py6
-rw-r--r--snekbox/api/resources/eval.py23
-rw-r--r--snekbox/api/resources/info.py44
-rw-r--r--snekbox/api/snekapi.py4
4 files changed, 51 insertions, 26 deletions
diff --git a/snekbox/api/resources/__init__.py b/snekbox/api/resources/__init__.py
index fe422b8..66c72fb 100644
--- a/snekbox/api/resources/__init__.py
+++ b/snekbox/api/resources/__init__.py
@@ -1,3 +1,7 @@
from .eval import EvalResource
+from .info import InformationResource
-__all__ = ("EvalResource",)
+__all__ = (
+ "EvalResource",
+ "InformationResource",
+)
diff --git a/snekbox/api/resources/eval.py b/snekbox/api/resources/eval.py
index a4a9d5e..c883ddb 100644
--- a/snekbox/api/resources/eval.py
+++ b/snekbox/api/resources/eval.py
@@ -59,29 +59,6 @@ class EvalResource:
def __init__(self, nsjail: NsJail):
self.nsjail = nsjail
- @validate(
- resp_schema={
- "versions": {"type": "array", "items": {"type": "str"}},
- }
- )
- def on_get(self, _: falcon.Request, resp: falcon.Response) -> None:
- """
- Get information about the server.
-
- Response format:
- >>> {
- ... "versions": ["Python 3.9", "Python 3.10", "Python 3.12 Beta 1"]
- ... }
-
- Status codes:
-
- - 200
- Success.
- """
- resp.media = {
- "versions": VERSION_DISPLAY_NAMES,
- }
-
@validate(REQ_SCHEMA)
def on_post(self, req: falcon.Request, resp: falcon.Response) -> None:
"""
diff --git a/snekbox/api/resources/info.py b/snekbox/api/resources/info.py
new file mode 100644
index 0000000..0dbf316
--- /dev/null
+++ b/snekbox/api/resources/info.py
@@ -0,0 +1,44 @@
+import logging
+
+import falcon
+from falcon.media.validators.jsonschema import validate
+
+from scripts.python_version import VERSION_DISPLAY_NAMES
+
+__all__ = ("InformationResource",)
+
+log = logging.getLogger(__name__)
+
+
+class InformationResource:
+ """
+ Information about the server.
+
+ Supported methods:
+
+ - GET /info
+ Get information about the current server, and supported features.
+ """
+
+ RESP_SCHEMA = {
+ "versions": {"type": "array", "items": {"type": "str"}},
+ }
+
+ @validate(resp_schema=RESP_SCHEMA)
+ def on_get(self, _: falcon.Request, resp: falcon.Response) -> None:
+ """
+ Get information about the server.
+
+ Response format:
+ >>> {
+ ... "python_versions": ["Python 3.9", "Python 3.10", "Python 3.12 Beta 1"]
+ ... }
+
+ Status codes:
+
+ - 200
+ Success.
+ """
+ resp.media = {
+ "python_versions": VERSION_DISPLAY_NAMES,
+ }
diff --git a/snekbox/api/snekapi.py b/snekbox/api/snekapi.py
index 5a8d390..a48bc9f 100644
--- a/snekbox/api/snekapi.py
+++ b/snekbox/api/snekapi.py
@@ -1,9 +1,8 @@
import falcon
+from snekbox.api.resources import EvalResource, InformationResource
from snekbox.nsjail import NsJail
-from .resources import EvalResource
-
class SnekAPI(falcon.App):
"""
@@ -29,3 +28,4 @@ class SnekAPI(falcon.App):
nsjail = NsJail(*args, **kwargs)
self.add_route("/eval", EvalResource(nsjail))
+ self.add_route("/info", InformationResource())