mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-29 02:08:10 +00:00
Option to record curl requests into a file (to replay them later).
This commit is contained in:
parent
db69b93100
commit
221befa73e
@ -86,6 +86,7 @@ def parse_arguments(argv, config):
|
||||
"ssl": config.getboolean("ssl", False),
|
||||
"certfile": config.get("certfile", ""),
|
||||
"certkey": config.get("certkey", ""),
|
||||
"record": config.get("record", ""),
|
||||
"local": config.getboolean("local", False),
|
||||
"allow": config.getboolean("allow_remote_console", False),
|
||||
"quiet": config.getboolean("quiet", False),
|
||||
@ -101,6 +102,7 @@ def parse_arguments(argv, config):
|
||||
parser.add_argument("--ssl", action="store_true", help="run in SSL mode")
|
||||
parser.add_argument("--certfile", help="SSL cert file")
|
||||
parser.add_argument("--certkey", help="SSL key file")
|
||||
parser.add_argument("--record", help="save curl requests into a file")
|
||||
parser.add_argument("-L", "--local", action="store_true", help="local mode (allows some insecure operations)")
|
||||
parser.add_argument("-A", "--allow", action="store_true", help="allow remote connections to local console ports")
|
||||
parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout")
|
||||
@ -122,6 +124,7 @@ def set_config(args):
|
||||
server_config["ssl"] = str(args.ssl)
|
||||
server_config["certfile"] = args.certfile
|
||||
server_config["certkey"] = args.certkey
|
||||
server_config["record"] = args.record
|
||||
server_config["debug"] = str(args.debug)
|
||||
server_config["live"] = str(args.live)
|
||||
server_config["shell"] = str(args.shell)
|
||||
|
@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
from ..modules.vm_error import VMError
|
||||
from .response import Response
|
||||
from ..crash_report import CrashReport
|
||||
from ..config import Config
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -125,6 +126,15 @@ class Route(object):
|
||||
# API call
|
||||
try:
|
||||
request = yield from parse_request(request, input_schema)
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
record_file = server_config.get("record")
|
||||
if record_file:
|
||||
try:
|
||||
with open(record_file, "a") as f:
|
||||
f.write("curl -X {} 'http://{}{}' -d '{}'".format(request.method, request.host, request.path_qs, json.dumps(request.json)))
|
||||
f.write("\n")
|
||||
except OSError as e:
|
||||
log.warn("Could not write to the record file {}: {}".format(record_file, e))
|
||||
response = Response(route=route, output_schema=output_schema)
|
||||
yield from func(request, response)
|
||||
except aiohttp.web.HTTPException as e:
|
||||
|
Loading…
Reference in New Issue
Block a user