From dd182c19cd8f31ec60a577a5429ab80a1cb435fb Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Mon, 9 Jan 2017 13:17:28 +0100 Subject: [PATCH] atomic_dbus: fix VulnerableInfo method As of ef984ed, atomic.get_all_vulnerable_info() sometimes returns a JSON object instead of a string. Make it always return an object and amend its documentation. Closes: #817 Approved by: baude --- Atomic/atomic.py | 7 +++---- atomic_dbus.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Atomic/atomic.py b/Atomic/atomic.py index 386da05..1f89b5e 100644 --- a/Atomic/atomic.py +++ b/Atomic/atomic.py @@ -544,13 +544,12 @@ class Atomic(object): def get_all_vulnerable_info(self): """ - Will simply read and return the entire /var/lib/atomic/scan_summary.json - as a JSON string so it can then be parsed appropriately. + Read and parse the /var/lib/atomic/scan_summary.json object. """ try: return json.loads(open(os.path.join(self.results, "scan_summary.json"), "r").read()) - except IOError: - return "{}" + except (IOError, ValueError): + return {} def get_vulnerable_ids(self): diff --git a/atomic_dbus.py b/atomic_dbus.py index c961483..0091984 100755 --- a/atomic_dbus.py +++ b/atomic_dbus.py @@ -272,7 +272,7 @@ class atomic_dbus(slip.dbus.service.Object): def VulnerableInfo(self): args = self.Args() self.atomic.set_args(args) - return self.atomic.get_all_vulnerable_info() + return json.dumps(self.atomic.get_all_vulnerable_info()) # atomic install section # The Install method will install the specified image