summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2020-04-22 09:50:54 -0500
committerJohn Estabrook <jestabro@vyos.io>2020-04-22 10:44:53 -0500
commitd2477601a6c4f5f11773493cacfdc54e5f9a01ae (patch)
treec3e80b639edbe9bd19c9cb979d9ebcff40833e66
parent675f400bacb03ae93be928e7270f89205d1036b9 (diff)
downloadvyos-1x-d2477601a6c4f5f11773493cacfdc54e5f9a01ae.tar.gz
vyos-1x-d2477601a6c4f5f11773493cacfdc54e5f9a01ae.zip
http api: T2096: form of show/generate should be consistent with other cmds
-rw-r--r--python/vyos/configsession.py8
-rwxr-xr-xsrc/services/vyos-http-api-server34
2 files changed, 30 insertions, 12 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py
index aaf08e726..f2524b37e 100644
--- a/python/vyos/configsession.py
+++ b/python/vyos/configsession.py
@@ -181,11 +181,11 @@ class ConfigSession(object):
out = self.__run_command(REMOVE_IMAGE + [name])
return out
- def generate(self, cmd):
- out = self.__run_command(GENERATE + cmd.split())
+ def generate(self, path):
+ out = self.__run_command(GENERATE + path)
return out
- def show(self, cmd):
- out = self.__run_command(SHOW + cmd.split())
+ def show(self, path):
+ out = self.__run_command(SHOW + path)
return out
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index a3624052e..c36cbd640 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -318,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)
@@ -339,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)