summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-06-17 20:12:24 +0200
committerDaniil Baturin <daniil@baturin.org>2019-06-17 20:12:24 +0200
commit7f06879361999e3b3aab6f66bb267841d958bfdb (patch)
treed45e72bc9229aae2ab4885fd7bc539e298b94ec5 /src/services
parentac2b3fbede362348b94c3e759ff90a15f0fef62a (diff)
downloadvyos-1x-7f06879361999e3b3aab6f66bb267841d958bfdb.tar.gz
vyos-1x-7f06879361999e3b3aab6f66bb267841d958bfdb.zip
[HTTP API] T1431: allow sending a single command, and make sure commands are dicts.
Diffstat (limited to 'src/services')
-rwxr-xr-xsrc/services/vyos-http-api-server8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index 45723010a..301c083a1 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -87,6 +87,10 @@ def configure():
except Exception as e:
return error(400, "Failed to parse JSON: {0}".format(e))
+ # Allow users to pass just one command
+ if not isinstance(commands, list):
+ commands = [commands]
+
# We don't want multiple people/apps to be able to commit at once,
# or modify the shared session while someone else is doing the same,
# so the lock is really global
@@ -96,6 +100,10 @@ def configure():
error_msg = None
try:
for c in commands:
+ # What we've got may not even be a dict
+ if not isinstance(c, dict):
+ raise ConfigSessionError("Malformed command \"{0}\": any command must be a dict".format(json.dumps(c)))
+
# Missing op or path is a show stopper
if not ('op' in c):
raise ConfigSessionError("Malformed command \"{0}\": missing \"op\" field".format(json.dumps(c)))