summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-06-17 19:59:16 +0200
committerDaniil Baturin <daniil@baturin.org>2019-06-17 20:00:10 +0200
commitac2b3fbede362348b94c3e759ff90a15f0fef62a (patch)
treea55143d8e1a68a870145da10610c4c2620883c1f /src/services
parent62822413b20a82c4738897c16d3120c04fbf27d6 (diff)
downloadvyos-1x-ac2b3fbede362348b94c3e759ff90a15f0fef62a.tar.gz
vyos-1x-ac2b3fbede362348b94c3e759ff90a15f0fef62a.zip
[HTTP API] T1431: make the value field optional and add better validation.
Diffstat (limited to 'src/services')
-rwxr-xr-xsrc/services/vyos-http-api-server26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index 7b9e3d671..45723010a 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -96,16 +96,36 @@ def configure():
error_msg = None
try:
for c in commands:
+ # 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)))
+ if not ('path' in c):
+ raise ConfigSessionError("Malformed command \"{0}\": missing \"path\" field".format(json.dumps(c)))
+ # Missing value is fine, substitute for empty string
+ if not ('value' in c):
+ value = ""
+
op = c['op']
path = c['path']
value = c['value']
- # Account for null values
+ # Type checking
+ if not isinstance(path, list):
+ raise ConfigSessionError("Malformed command \"{0}\": \"path\" field must be a list".format(json.dumps(c)))
+
+ if not isinstance(value, str):
+ raise ConfigSessionError("Malformed command \"{0}\": \"value\" field must be a string".format(json.dumps(c)))
+
+ # Account for the case when value field is present and set to null
if not value:
value = ""
- # For vyos.config calls
- cfg_path = " ".join(path + [value]).strip()
+ # For vyos.configsessios calls that have no separate value arguments,
+ # and for type checking too
+ try:
+ cfg_path = " ".join(path + [value]).strip()
+ except TypeError:
+ raise ConfigSessionError("Malformed command \"{0}\": \"path\" field must be a list of strings".format(json.dumps(c)))
if op == 'set':
# XXX: it would be nice to do a strict check for "path already exists",