aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Pipfile1
-rw-r--r--Pipfile.lock31
-rw-r--r--snekbox/api/resources/eval.py16
3 files changed, 46 insertions, 2 deletions
diff --git a/Pipfile b/Pipfile
index 5a7ccc2..6a0c5b4 100644
--- a/Pipfile
+++ b/Pipfile
@@ -6,6 +6,7 @@ name = "pypi"
[packages]
falcon = "*"
gunicorn = "*"
+jsonschema = "*"
[dev-packages]
pytest = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index 4e4a053..e0c08a0 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "f2a5f388618a6609f28deb1bc71675d8a0deb5571aff8c79a698bad79cdbca79"
+ "sha256": "8dda3bfb1f2f9109b882225e4c55e3a561e25a7d80845889b4ffe5ad250cc86e"
},
"pipfile-spec": 6,
"requires": {
@@ -16,6 +16,13 @@
]
},
"default": {
+ "attrs": {
+ "hashes": [
+ "sha256:69c0dbf2ed392de1cb5ec704444b08a5ef81680a61cb899dc08127123af36a79",
+ "sha256:f0b870f674851ecbfbbbd364d6b5cbdff9dcedbc7f3f5e18a6891057f21fe399"
+ ],
+ "version": "==19.1.0"
+ },
"falcon": {
"hashes": [
"sha256:18157af2a4fc3feedf2b5dcc6196f448639acf01c68bc33d4d5a04c3ef87f494",
@@ -43,6 +50,28 @@
],
"index": "pypi",
"version": "==19.9.0"
+ },
+ "jsonschema": {
+ "hashes": [
+ "sha256:0c0a81564f181de3212efa2d17de1910f8732fa1b71c42266d983cd74304e20d",
+ "sha256:a5f6559964a3851f59040d3b961de5e68e70971afb88ba519d27e6a039efff1a"
+ ],
+ "index": "pypi",
+ "version": "==3.0.1"
+ },
+ "pyrsistent": {
+ "hashes": [
+ "sha256:16692ee739d42cf5e39cef8d27649a8c1fdb7aa99887098f1460057c5eb75c3a",
+ "sha256:1b304bab4d25fbe2b5bf32034d0d904bfc870f7f4ed9dccec6ae388978f0ef6f"
+ ],
+ "version": "==0.15.2"
+ },
+ "six": {
+ "hashes": [
+ "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
+ "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"
+ ],
+ "version": "==1.12.0"
}
},
"develop": {
diff --git a/snekbox/api/resources/eval.py b/snekbox/api/resources/eval.py
index 5558b4f..e6c5119 100644
--- a/snekbox/api/resources/eval.py
+++ b/snekbox/api/resources/eval.py
@@ -1,6 +1,7 @@
import logging
import falcon
+from falcon.media.validators.jsonschema import validate
from snekbox.nsjail import NsJail
@@ -8,11 +9,24 @@ log = logging.getLogger(__name__)
class EvalResource:
+ REQ_SCHEMA = {
+ "type": "object",
+ "properties": {
+ "input": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "input"
+ ]
+ }
+
def __init__(self):
self.nsjail = NsJail()
+ @validate(REQ_SCHEMA)
def on_post(self, req, resp):
- code = req.media.get("code")
+ code = req.media["input"]
try:
output = self.nsjail.python3(code)