mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-14 12:29:02 +00:00
Support parameters for import
This commit is contained in:
parent
e50acf811c
commit
e50eae19e6
@ -268,6 +268,14 @@ class ProjectHandler:
|
||||
|
||||
controller = Controller.instance()
|
||||
|
||||
if request.get("path"):
|
||||
config = Config.instance()
|
||||
if config.get_section_config("Server").getboolean("local", False) is False:
|
||||
response.set_status(403)
|
||||
return
|
||||
path = request.json.get("path")
|
||||
name = request.json.get("name")
|
||||
|
||||
# We write the content to a temporary location and after we extract it all.
|
||||
# It could be more optimal to stream this but it is not implemented in Python.
|
||||
# Spooled means the file is temporary kept in memory until max_size is reached
|
||||
@ -278,7 +286,7 @@ class ProjectHandler:
|
||||
if not packet:
|
||||
break
|
||||
temp.write(packet)
|
||||
project = yield from import_project(controller, request.match_info["project_id"], temp)
|
||||
project = yield from import_project(controller, request.match_info["project_id"], temp, location=path, name=name)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not import the project: {}".format(e))
|
||||
|
||||
|
@ -21,6 +21,7 @@ import jsonschema
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import logging
|
||||
import urllib
|
||||
import traceback
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -36,8 +37,9 @@ from ..config import Config
|
||||
@asyncio.coroutine
|
||||
def parse_request(request, input_schema):
|
||||
"""Parse body of request and raise HTTP errors in case of problems"""
|
||||
|
||||
content_length = request.content_length
|
||||
if content_length is not None and content_length > 0:
|
||||
if content_length is not None and content_length > 0 and input_schema:
|
||||
body = yield from request.read()
|
||||
try:
|
||||
request.json = json.loads(body.decode('utf-8'))
|
||||
@ -46,13 +48,21 @@ def parse_request(request, input_schema):
|
||||
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON {}".format(e))
|
||||
else:
|
||||
request.json = {}
|
||||
try:
|
||||
jsonschema.validate(request.json, input_schema)
|
||||
except jsonschema.ValidationError as e:
|
||||
log.error("Invalid input query. JSON schema error: {}".format(e.message))
|
||||
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON: {} in schema: {}".format(
|
||||
e.message,
|
||||
json.dumps(e.schema)))
|
||||
|
||||
# Parse the query string
|
||||
if len(request.query_string) > 0:
|
||||
for (k, v) in urllib.parse.parse_qs(request.query_string).items():
|
||||
request.json[k] = v[0]
|
||||
|
||||
if input_schema:
|
||||
try:
|
||||
jsonschema.validate(request.json, input_schema)
|
||||
except jsonschema.ValidationError as e:
|
||||
log.error("Invalid input query. JSON schema error: {}".format(e.message))
|
||||
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON: {} in schema: {}".format(
|
||||
e.message,
|
||||
json.dumps(e.schema)))
|
||||
|
||||
return request
|
||||
|
||||
|
||||
@ -166,6 +176,7 @@ class Route(object):
|
||||
if api_version is None or raw is True:
|
||||
response = Response(request=request, route=route, output_schema=output_schema)
|
||||
|
||||
request = yield from parse_request(request, None)
|
||||
yield from func(request, response)
|
||||
return response
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user