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

Endi Sukma Dewata edewata at redhat.com
Thu Feb 5 03:25:36 UTC 2015


On 1/14/2015 1:34 PM, Endi Sukma Dewata wrote:
> 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

New patch attched for master branch. The previous patch was for 10.2.0 
branch.

-- 
Endi S. Dewata
-------------- next part --------------
>From 7357dbc88d31b36e91603252a2db15c0113b6e99 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata at 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 1cc2a7a5a2fbf0527643f89e461ed427c6303ac6..24deefca4a9d789ff025f9d32ac49f15a6571b5e 100644
--- a/base/common/python/pki/system.py
+++ b/base/common/python/pki/system.py
@@ -55,17 +55,27 @@ class SecurityDomainHost(object):
         :type json_value: str
         :returns: SecurityDomainHost
         """
+
         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
 
 
@@ -89,11 +99,26 @@ class SecurityDomainSubsystem(object):
         :type json_value: str
         :returns: SecurityDomainSubsystem
         """
-        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):
@@ -115,12 +140,28 @@ class SecurityDomainInfo(object):
         :type json_value: str
         :returns: SecurityDomainInfo
         """
-        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



More information about the Pki-devel mailing list