>From 2fc929b2fbfefe8cc7c35fd20ee5d5e8b803b357 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 21 Dec 2016 20:01:13 +0100
Subject: [PATCH] Refactored PKIConfigParser.flatten_master_dict().

To improve reusability the flatten_master_dict() has been moved
from PKIConfigParser into PKIDeployer.
---
 .../python/pki/server/deployment/__init__.py       | 21 +++++++++++++++++
 .../python/pki/server/deployment/pkiparser.py      | 26 +++-------------------
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/base/server/python/pki/server/deployment/__init__.py b/base/server/python/pki/server/deployment/__init__.py
index 641c05d39f235d21a1db592013b7e5d8b9ed27e0..2e95d2bf1b527044e9692acca0db8ca29c4fbb41 100644
--- a/base/server/python/pki/server/deployment/__init__.py
+++ b/base/server/python/pki/server/deployment/__init__.py
@@ -84,6 +84,27 @@ class PKIDeployer:
         self.tps_connector = util.TPSConnector(self)
         self.config_client = util.ConfigClient(self)
 
+    def flatten_master_dict(self):
+
+        self.mdict.update(__name__="PKI Master Dictionary")
+
+        default_dict = dict(self.main_config.items('DEFAULT'))
+        default_dict[0] = None
+        self.mdict.update(default_dict)
+
+        web_server_dict = None
+        if self.main_config.has_section('Tomcat'):
+            web_server_dict = dict(self.main_config.items('Tomcat'))
+
+        if web_server_dict:
+            web_server_dict[0] = None
+            self.mdict.update(web_server_dict)
+
+        if self.main_config.has_section(self.subsystem_name):
+            subsystem_dict = dict(self.main_config.items(self.subsystem_name))
+            subsystem_dict[0] = None
+            self.mdict.update(subsystem_dict)
+
     def deploy_webapp(self, name, doc_base, descriptor):
         """
         Deploy a web application into a Tomcat instance.
diff --git a/base/server/python/pki/server/deployment/pkiparser.py b/base/server/python/pki/server/deployment/pkiparser.py
index 6ea2867ba720c00c430f90710b69137e80ee8f00..2b7c77f2a6f8ae088eb1f64e576dd39acccfc513 100644
--- a/base/server/python/pki/server/deployment/pkiparser.py
+++ b/base/server/python/pki/server/deployment/pkiparser.py
@@ -227,7 +227,7 @@ class PKIConfigParser:
         with open(config.default_deployment_cfg) as f:
             self.deployer.main_config.readfp(f)
 
-        self.flatten_master_dict()
+        self.deployer.flatten_master_dict()
 
     # The following code is based heavily upon
     # "http://www.decalage.info/en/python/configparser"
@@ -255,7 +255,7 @@ class PKIConfigParser:
         if section != "DEFAULT" and not self.deployer.main_config.has_section(section):
             self.deployer.main_config.add_section(section)
         self.deployer.main_config.set(section, key, value)
-        self.flatten_master_dict()
+        self.deployer.flatten_master_dict()
 
         if section != "DEFAULT" and not self.deployer.user_config.has_section(
                 section):
@@ -400,26 +400,6 @@ class PKIConfigParser:
             rv = err
         return rv
 
-    def flatten_master_dict(self):
-        self.mdict.update(__name__="PKI Master Dictionary")
-
-        default_dict = dict(self.deployer.main_config.items('DEFAULT'))
-        default_dict[0] = None
-        self.mdict.update(default_dict)
-
-        web_server_dict = None
-        if self.deployer.main_config.has_section('Tomcat'):
-            web_server_dict = dict(self.deployer.main_config.items('Tomcat'))
-
-        if web_server_dict:
-            web_server_dict[0] = None
-            self.mdict.update(web_server_dict)
-
-        if self.deployer.main_config.has_section(self.deployer.subsystem_name):
-            subsystem_dict = dict(self.deployer.main_config.items(self.deployer.subsystem_name))
-            subsystem_dict[0] = None
-            self.mdict.update(subsystem_dict)
-
     def ds_connect(self):
 
         hostname = self.mdict['pki_ds_hostname']
@@ -602,7 +582,7 @@ class PKIConfigParser:
             self.mdict['pki_deployed_instance_name'] = \
                 config.pki_deployed_instance_name
 
-            self.flatten_master_dict()
+            self.deployer.flatten_master_dict()
 
             # Generate random 'pin's for use as security database passwords
             # and add these to the "sensitive" key value pairs read in from
-- 
2.5.5

