summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rwxr-xr-xsrc/services/vyos-http-api-server42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index b5ad8b159..c36cbd640 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -22,6 +22,7 @@ import grp
import json
import traceback
import threading
+import signal
import vyos.config
@@ -317,11 +318,20 @@ def generate_op():
command = json.loads(command)
try:
- cmd = command['cmd']
- res = session.generate(cmd)
+ op = command['op']
+ path = command['path']
except KeyError:
- return error(400, "Missing required field \"cmd\"")
- except VyOSError as e:
+ return error(400, "Missing required field. \"op\" and \"path\" fields are required")
+
+ if not isinstance(path, list):
+ return error(400, "Malformed command: \"path\" field must be a list of strings")
+
+ try:
+ if op == 'generate':
+ res = session.generate(path)
+ else:
+ return error(400, "\"{0}\" is not a valid operation".format(op))
+ except ConfigSessionError as e:
return error(400, str(e))
except Exception as e:
print(traceback.format_exc(), file=sys.stderr)
@@ -338,11 +348,20 @@ def show_op():
command = json.loads(command)
try:
- cmd = command['cmd']
- res = session.show(cmd)
+ op = command['op']
+ path = command['path']
except KeyError:
- return error(400, "Missing required field \"cmd\"")
- except VyOSError as e:
+ return error(400, "Missing required field. \"op\" and \"path\" fields are required")
+
+ if not isinstance(path, list):
+ return error(400, "Malformed command: \"path\" field must be a list of strings")
+
+ try:
+ if op == 'show':
+ res = session.show(path)
+ else:
+ return error(400, "\"{0}\" is not a valid operation".format(op))
+ except ConfigSessionError as e:
return error(400, str(e))
except Exception as e:
print(traceback.format_exc(), file=sys.stderr)
@@ -350,6 +369,8 @@ def show_op():
return success(res)
+def shutdown():
+ raise KeyboardInterrupt
if __name__ == '__main__':
# systemd's user and group options don't work, do it by hand here,
@@ -372,4 +393,9 @@ if __name__ == '__main__':
app.config['vyos_keys'] = server_config['api_keys']
app.config['vyos_debug'] = server_config['debug']
+ def sig_handler(signum, frame):
+ shutdown()
+
+ signal.signal(signal.SIGTERM, sig_handler)
+
bottle.run(app, host=server_config["listen_address"], port=server_config["port"], debug=True)