[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Pki-devel] [PATCH] 540 Fixed problem cloning Dogtag 10.1.x to 10.2.x.



The JSON format of security domain info has changed between Dogtag
10.1.x and 10.2.x, so the Python client library has been changed
to accommodate both formats.

https://fedorahosted.org/pki/ticket/1235

--
Endi S. Dewata
From fbebfd2aff27c1c255b907f556a7bb27afd65abc Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Wed, 14 Jan 2015 10:36:37 -0500
Subject: [PATCH] Fixed problem cloning Dogtag 10.1.x to 10.2.x.

The JSON format of security domain info has changed between Dogtag
10.1.x and 10.2.x, so the Python client library has been changed
to accommodate both formats.

https://fedorahosted.org/pki/ticket/1235
---
 base/common/python/pki/system.py | 65 ++++++++++++++++++++++++++++++++--------
 1 file changed, 53 insertions(+), 12 deletions(-)

diff --git a/base/common/python/pki/system.py b/base/common/python/pki/system.py
index a4b5c2feea265ebe49a6ba7ebacdb3c4d2e86405..d3ba44ce9bfdf06b3af9f7f3f4025975b8d8dd94 100644
--- a/base/common/python/pki/system.py
+++ b/base/common/python/pki/system.py
@@ -44,17 +44,27 @@ class SecurityDomainHost(object):
 
     @classmethod
     def from_json(cls, json_value):
+
         host = cls()
+
+        try:
+            # 10.2.x
+            host.id = json_value['id']
+
+        except KeyError:
+            # 10.1.x
+            host.id = json_value['@id']
+
         host.admin_port = json_value['SecureAdminPort']
         host.agent_port = json_value['SecureAgentPort']
         host.clone = json_value['Clone']
         host.domain_manager = json_value['DomainManager']
         host.ee_client_auth_port = json_value['SecureEEClientAuthPort']
         host.hostname = json_value['Hostname']
-        host.id = json_value['id']
         host.secure_port = json_value['SecurePort']
         host.subsystem_name = json_value['SubsystemName']
         host.unsecure_port = json_value['Port']
+
         return host
 
 
@@ -65,11 +75,26 @@ class SecurityDomainSubsystem(object):
 
     @classmethod
     def from_json(cls, json_value):
-        ret = cls()
-        ret.name = json_value['id']
-        for host in json_value['Host']:
-            ret.hosts[host['id']] = SecurityDomainHost.from_json(host)
-        return ret
+
+        subsystem = cls()
+
+        try:
+            # 10.2.x
+            subsystem.name = json_value['id']
+
+        except KeyError:
+            # 10.1.x
+            subsystem.name = json_value['@id']
+
+        hosts = json_value['Host']
+        if type(hosts) is dict:
+            hosts = [ hosts ]
+
+        for h in hosts:
+            host = SecurityDomainHost.from_json(h)
+            subsystem.hosts[host.id] = host
+
+        return subsystem
 
 
 class SecurityDomainInfo(object):
@@ -79,12 +104,28 @@ class SecurityDomainInfo(object):
 
     @classmethod
     def from_json(cls, json_value):
-        ret = cls()
-        ret.name = json_value['id']
-        for slist in json_value['Subsystem']:
-            subsystem = SecurityDomainSubsystem.from_json(slist)
-            ret.systems[slist['id']] = subsystem
-        return ret
+
+        security_domain = cls()
+
+        try:
+            # 10.2.x
+            security_domain.name = json_value['id']
+            subsystems = json_value['Subsystem']
+
+        except KeyError:
+            # 10.1.x
+            domain_info = json_value['DomainInfo']
+            security_domain.name = domain_info['@id']
+
+            subsystems = domain_info['Subsystem']
+            if type(subsystems) is dict:
+                subsystems = [ subsystems ]
+
+        for s in subsystems:
+            subsystem = SecurityDomainSubsystem.from_json(s)
+            security_domain.systems[subsystem.name] = subsystem
+
+        return security_domain
 
 
 class SecurityDomainClient(object):
-- 
1.8.4.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]