Implementing poc spec behavior in append route.

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-08-20 10:59:26 +02:00
parent b86454179a
commit c07638601b
4 changed files with 62 additions and 21 deletions
+21 -8
View File
@@ -16,11 +16,12 @@
# limitations under the License.
#
from urllib.parse import urlparse
from itertools import repeat
from urllib.parse import urlparse
from uuid import uuid4
import asyncio
import io
import json
import logging
import os
import shlex
@@ -280,13 +281,25 @@ def append_route(app):
app.router._frozen = False
content = await request.json()
name = "ROUTE_" + str(uuid4()).replace('-', '_')
app.router.add_route(content["method"],
content["url_pattern"],
handle_route(content["entrypoint"],
content["command"]),
name=name)
print(f'Route created {content["method"]} {content["url_pattern"]}')
return web.json_response(name)
try:
app.router.add_route(content["method"],
content["url_pattern"],
handle_route(content["entrypoint"],
content["command"]),
name=name)
except KeyError as exc:
missing = list()
for field in ("method", "url_pattern", "entrypoint", "command"):
if field not in content:
missing.append(field)
return web.Response(status=422,
reason="Missing Mandatory Field",
body=json.dumps({"missing_mandatory_fields": missing}))
except ValueError as exc:
return web.Response(status=422, reason="Invalid Route Spec")
else:
print(f'Route created {content["method"]} {content["url_pattern"]}')
return web.json_response(name)
return _append_route
BIN
View File
Binary file not shown.