From 8e81b8091ebabd7b98e443432d3a7f5044ed2538 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Parra Date: Wed, 26 Feb 2020 10:42:18 +0100 Subject: Search the key in the parsed json Testing the ogClient I found that if a value of the json match a key the ogClient has an exception. For example: body = "... shell/run {"run": "fdisk -l"} ..." CURRENT Enters in if "disk" in body:... if "run" in body:... EXPECTED Enters in if "run" in body:... This commit changes the behaviour to search for the keys in the dictionary returned by json.loads() instead of searching in the raw string. This way the ogClient looks for the keys without searching in the values. --- src/restRequest.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/restRequest.py b/src/restRequest.py index 2354143..6ed00c4 100644 --- a/src/restRequest.py +++ b/src/restRequest.py @@ -60,42 +60,41 @@ class restRequest: print ("Error: Json message incomplete") return - if "run" in body: + if "run" in json_param: self.run = json_param["run"] try: self.echo = json_param["echo"] except: pass - if "disk" in body: + if "disk" in json_param: self.disk = json_param["disk"] - if "partition" in body: - if not "partition_setup" in body: - self.partition = json_param["partition"] + if "partition" in json_param: + self.partition = json_param["partition"] - if "cache" in body: + if "cache" in json_param: self.cache = json_param["cache"] - if "cache_size" in body: + if "cache_size" in json_param: self.cache_size = json_param["cache_size"] - if "partition_setup" in body: + if "partition_setup" in json_param: self.partition_setup = json_param["partition_setup"] - if "name" in body: + if "name" in json_param: self.name = json_param["name"] - if "repository" in body: + if "repository" in json_param: self.repo = json_param["repository"] - if "type" in body: + if "type" in json_param: self.type = json_param["type"] - if "profile" in body: + if "profile" in json_param: self.profile = json_param["profile"] - if "id" in body: + if "id" in json_param: self.id = json_param["id"] if "code" in json_param: -- cgit v1.2.3-18-g5258