diff options
author | 2023-03-17 19:44:02 +0400 | |
---|---|---|
committer | 2023-03-17 19:44:02 +0400 | |
commit | 837578786f5154d4758eb78741e5fc330af22da6 (patch) | |
tree | ca0421cbe5a874b6ac820a7293de58b8d51fce88 | |
parent | Refactor Python Version Parsing (diff) |
Move Info Endpoint
Move the information endpoint from the eval resource into its own
location. This endpoint currently only returns the python version but
can easily be expanded with more info later.
Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r-- | snekbox/api/resources/__init__.py | 6 | ||||
-rw-r--r-- | snekbox/api/resources/eval.py | 23 | ||||
-rw-r--r-- | snekbox/api/resources/info.py | 44 | ||||
-rw-r--r-- | snekbox/api/snekapi.py | 4 |
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()) |