>From 84e98cd37d0299e3070b88309e331f721dd8d058 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 21 Dec 2016 05:38:07 +0100
Subject: [PATCH] Refactored user_config object in pkiconfig.py.

To improve reusability the user_config object has been converted
from a global variable in pkiconfig.py into an attribute in
PKIDeployer.
---
 base/server/python/pki/server/deployment/pkihelper.py  |  1 +
 base/server/python/pki/server/deployment/pkiparser.py  | 18 +++++++++---------
 .../deployment/scriptlets/infrastructure_layout.py     |  6 +++---
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py
index 58188657db2546bdca83c766acc16d9f8968603b..acab7152823e17f5782ef71dcbdcb031e345c035 100644
--- a/base/server/python/pki/server/deployment/pkihelper.py
+++ b/base/server/python/pki/server/deployment/pkihelper.py
@@ -4588,6 +4588,7 @@ class PKIDeployer:
         # Global dictionary variables
         self.mdict = {}
         self.slots = {}
+        self.user_config = None
         self.manifest_db = []
 
         self.identity = None
diff --git a/base/server/python/pki/server/deployment/pkiparser.py b/base/server/python/pki/server/deployment/pkiparser.py
index 027703bbc4730b5e192b93f73b5c64687e679834..7931d7cc70add6d47aecaeae3632597a22612483 100644
--- a/base/server/python/pki/server/deployment/pkiparser.py
+++ b/base/server/python/pki/server/deployment/pkiparser.py
@@ -222,8 +222,8 @@ class PKIConfigParser:
         # Make keys case-sensitive!
         self.pki_config.optionxform = str
 
-        config.user_config = configparser.SafeConfigParser()
-        config.user_config.optionxform = str
+        self.deployer.user_config = configparser.SafeConfigParser()
+        self.deployer.user_config.optionxform = str
 
         with open(config.default_deployment_cfg) as f:
             self.pki_config.readfp(f)
@@ -258,10 +258,10 @@ class PKIConfigParser:
         self.pki_config.set(section, key, value)
         self.flatten_master_dict()
 
-        if section != "DEFAULT" and not config.user_config.has_section(
+        if section != "DEFAULT" and not self.deployer.user_config.has_section(
                 section):
-            config.user_config.add_section(section)
-        config.user_config.set(section, key, value)
+            self.deployer.user_config.add_section(section)
+        self.deployer.user_config.set(section, key, value)
 
     def print_text(self, message):
         print(' ' * self.indent + message)
@@ -363,7 +363,7 @@ class PKIConfigParser:
                 print('Loading deployment configuration from ' +
                       config.user_deployment_cfg + '.')
                 self.pki_config.read([config.user_deployment_cfg])
-                config.user_config.read([config.user_deployment_cfg])
+                self.deployer.user_config.read([config.user_deployment_cfg])
 
                 # Look through each section and see if any password settings
                 # are present.  If so, escape any '%' characters.
@@ -382,17 +382,17 @@ class PKIConfigParser:
                             except configparser.NoOptionError:
                                 continue
 
-                sections = config.user_config.sections()
+                sections = self.deployer.user_config.sections()
                 if sections:
                     sections.append('DEFAULT')
                     for section in sections:
                         for key in no_interpolation:
                             try:
-                                val = config.user_config.get(
+                                val = self.deployer.user_config.get(
                                     section, key, raw=True)
                                 val = val.replace("%", "%%")  # pylint: disable=E1101
                                 if val:
-                                    config.user_config.set(
+                                    self.deployer.user_config.set(
                                         section, key, val)
                             except configparser.NoOptionError:
                                 continue
diff --git a/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py b/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py
index a04ec158bc684661586aa9fc9cdb56ab8bf468f6..b105378f8e20b8e294c0df0c9b8cbad0971741a9 100644
--- a/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py
+++ b/base/server/python/pki/server/deployment/scriptlets/infrastructure_layout.py
@@ -69,12 +69,12 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
         # Archive the user deployment configuration excluding the sensitive
         # parameters
         sensitive_parameters = deployer.mdict['sensitive_parameters'].split()
-        sections = config.user_config.sections()
+        sections = deployer.user_config.sections()
         for s in sections:
             for k in sensitive_parameters:
-                config.user_config.set(s, k, 'XXXXXXXX')
+                deployer.user_config.set(s, k, 'XXXXXXXX')
         with open(deployer.mdict['pki_user_deployment_cfg_replica'], 'w') as f:
-            config.user_config.write(f)
+            deployer.user_config.write(f)
 
         # establish top-level infrastructure, instance, and subsystem
         # base directories and create the "registry" symbolic link that
-- 
2.5.5

