1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-30 18:50:58 +00:00

Option to record curl requests into a file (to replay them later).

This commit is contained in:
Jeremy 2015-03-13 14:43:39 -06:00
parent db69b93100
commit 221befa73e
2 changed files with 13 additions and 0 deletions

View File

@ -86,6 +86,7 @@ def parse_arguments(argv, config):
"ssl": config.getboolean("ssl", False), "ssl": config.getboolean("ssl", False),
"certfile": config.get("certfile", ""), "certfile": config.get("certfile", ""),
"certkey": config.get("certkey", ""), "certkey": config.get("certkey", ""),
"record": config.get("record", ""),
"local": config.getboolean("local", False), "local": config.getboolean("local", False),
"allow": config.getboolean("allow_remote_console", False), "allow": config.getboolean("allow_remote_console", False),
"quiet": config.getboolean("quiet", 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("--ssl", action="store_true", help="run in SSL mode")
parser.add_argument("--certfile", help="SSL cert file") parser.add_argument("--certfile", help="SSL cert file")
parser.add_argument("--certkey", help="SSL key 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("-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("-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") 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["ssl"] = str(args.ssl)
server_config["certfile"] = args.certfile server_config["certfile"] = args.certfile
server_config["certkey"] = args.certkey server_config["certkey"] = args.certkey
server_config["record"] = args.record
server_config["debug"] = str(args.debug) server_config["debug"] = str(args.debug)
server_config["live"] = str(args.live) server_config["live"] = str(args.live)
server_config["shell"] = str(args.shell) server_config["shell"] = str(args.shell)

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
from ..modules.vm_error import VMError from ..modules.vm_error import VMError
from .response import Response from .response import Response
from ..crash_report import CrashReport from ..crash_report import CrashReport
from ..config import Config
@asyncio.coroutine @asyncio.coroutine
@ -125,6 +126,15 @@ class Route(object):
# API call # API call
try: try:
request = yield from parse_request(request, input_schema) 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) response = Response(route=route, output_schema=output_schema)
yield from func(request, response) yield from func(request, response)
except aiohttp.web.HTTPException as e: except aiohttp.web.HTTPException as e: