From 7f06879361999e3b3aab6f66bb267841d958bfdb Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 17 Jun 2019 20:12:24 +0200 Subject: [HTTP API] T1431: allow sending a single command, and make sure commands are dicts. --- src/services/vyos-http-api-server | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/services/vyos-http-api-server') 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))) -- cgit v1.2.3