From 711c255421fa6125a748ca6f17145e11bff85313 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Wed, 28 Nov 2012 13:12:24 -0500
Subject: [PATCH] Simplified the configuration file using defaults.

Previously to create a subsystem the admin would have to copy the
entire default deployment configuration, which contains many
parameters, and then customize it. Now the deployment code has been
changed such that the default config file will be used to provide
the default values, so the admin will only need to provide the
non-default parameters, thus reducing the size of the file.

Sample configuration files are provided in /usr/share/pki/
deployment/config.

Ticket #399
---
 base/deploy/CMakeLists.txt                               | 11 +++--------
 base/deploy/config/{pkideployment.cfg => deployment.cfg} |  0
 base/deploy/config/sample.cfg                            |  6 ++++++
 base/deploy/src/scriptlets/infrastructure_layout.py      |  4 ++--
 base/deploy/src/scriptlets/pkiconfig.py                  | 11 ++++++++---
 base/deploy/src/scriptlets/pkimessages.py                |  2 +-
 base/deploy/src/scriptlets/pkiparser.py                  | 10 ++++++----
 7 files changed, 26 insertions(+), 18 deletions(-)
 rename base/deploy/config/{pkideployment.cfg => deployment.cfg} (100%)
 create mode 100644 base/deploy/config/sample.cfg

diff --git a/base/deploy/CMakeLists.txt b/base/deploy/CMakeLists.txt
index 9838b0343bd27287ad5399e8301831ac718aa751..26abe5346fcec05e6efb0b117eddc1f17eef6dda 100644
--- a/base/deploy/CMakeLists.txt
+++ b/base/deploy/CMakeLists.txt
@@ -56,15 +56,10 @@ install(
 )
 
 install(
-    FILES
-        config/pkideployment.cfg
-        config/pkislots.cfg
+    DIRECTORY
+        config
     DESTINATION
-        ${DATA_INSTALL_DIR}/deployment/config
-    PERMISSIONS
-        OWNER_WRITE OWNER_READ
-        GROUP_READ
-        WORLD_READ
+        ${DATA_INSTALL_DIR}/deployment
 )
 
 find_package(PythonInterp REQUIRED)
diff --git a/base/deploy/config/pkideployment.cfg b/base/deploy/config/deployment.cfg
similarity index 100%
rename from base/deploy/config/pkideployment.cfg
rename to base/deploy/config/deployment.cfg
diff --git a/base/deploy/config/sample.cfg b/base/deploy/config/sample.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..6e95303341a76acfcf7ab9fa681d61bc69b460a8
--- /dev/null
+++ b/base/deploy/config/sample.cfg
@@ -0,0 +1,6 @@
+[Common]
+pki_admin_password=
+pki_backup_password=
+pki_client_pkcs12_password=
+pki_ds_password=
+pki_security_domain_password=
diff --git a/base/deploy/src/scriptlets/infrastructure_layout.py b/base/deploy/src/scriptlets/infrastructure_layout.py
index 31c788bfd37aba9ff69569d4818ac6b0b8d07fc9..ee405f2c129b7817738b388c2f5ad9b2fc01d441 100644
--- a/base/deploy/src/scriptlets/infrastructure_layout.py
+++ b/base/deploy/src/scriptlets/infrastructure_layout.py
@@ -40,7 +40,7 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                             extra=config.PKI_INDENTATION_LEVEL_1)
         # NOTE:  It was determined that since the "pkidestroy" command
         #        relies upon a symbolic link to a replica of the original
-        #        "pkideployment.cfg" configuration file used by the
+        #        deployment configuration file used by the
         #        "pkispawn" command of an instance, it is necessary to
         #        create any required instance and subsystem directories
         #        in this top-level "infrastructure_layout" scriptlet
@@ -50,7 +50,7 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
         #
         # establish the top-level infrastructure, instance, and subsystem
         # registry directories for storage of a copy of the original
-        # "pkideployment.cfg" configuration file used to spawn this instance,
+        # deployment configuration file used to spawn this instance,
         # and save a copy of this file
         util.directory.create(master['pki_registry_path'])
         util.directory.create(master['pki_instance_type_registry_path'])
diff --git a/base/deploy/src/scriptlets/pkiconfig.py b/base/deploy/src/scriptlets/pkiconfig.py
index 7e426b0f9a8ea94efa2d4123da7c3a4a4393aaff..ab3cebb67112e894279df2e4ca09eface1cbce5a 100644
--- a/base/deploy/src/scriptlets/pkiconfig.py
+++ b/base/deploy/src/scriptlets/pkiconfig.py
@@ -99,9 +99,14 @@ PKI_DEPLOYMENT_DEFAULT_APACHE_SERVICE_NAME = "apache"
 PKI_DEPLOYMENT_DEFAULT_TOMCAT_SERVICE_NAME = "tomcat"
 PKI_DEPLOYMENT_DEFAULT_APACHE_INSTANCE_NAME = "pki-apache"
 PKI_DEPLOYMENT_DEFAULT_TOMCAT_INSTANCE_NAME = "pki-tomcat"
-PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE = "pkideployment.cfg"
+
+PKI_DEPLOYMENT_CONFIGURATION_DIR =\
+    "/usr/share/pki/deployment/config"
+PKI_DEPLOYMENT_CONFIGURATION_FILE = "deployment.cfg"
+PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE =\
+    PKI_DEPLOYMENT_CONFIGURATION_DIR + "/" + PKI_DEPLOYMENT_CONFIGURATION_FILE
 PKI_DEPLOYMENT_SLOTS_CONFIGURATION_FILE =\
-    "/usr/share/pki/deployment/config/pkislots.cfg"
+    PKI_DEPLOYMENT_CONFIGURATION_DIR + "/pkislots.cfg"
 
 # subtypes of PKI subsystems
 PKI_DEPLOYMENT_CLONED_PKI_SUBSYSTEM = "Cloned"
@@ -151,7 +156,7 @@ def str2bool(string):
 #        and 'wait_to_attach_an_external_java_debugger(master)' functions,
 #        change 'pki_enable_java_debugger=False' to
 #        'pki_enable_java_debugger=True' in the appropriate
-#        'pkideployment.cfg' configuration file.
+#        deployment configuration file.
 def prepare_for_an_external_java_debugger(instance):
     print
     print PKI_DEPLOYMENT_INTERRUPT_BANNER
diff --git a/base/deploy/src/scriptlets/pkimessages.py b/base/deploy/src/scriptlets/pkimessages.py
index 99647946c6cad4d9f7cf10ac94fdfc8c2e15df04..09ad0cfc7d50341c9b88426601cb0f53c4ca04cd 100644
--- a/base/deploy/src/scriptlets/pkimessages.py
+++ b/base/deploy/src/scriptlets/pkimessages.py
@@ -114,7 +114,7 @@ PKIDESTROY_EPILOG =\
 "REMINDER:\n\n"\
 "    The default PKI instance path will be calculated and placed in front\n"\
 "    of the mandatory '-i <instance>' parameter, and the values that reside\n"\
-"    in a copy of the 'pkideployment.cfg' file that was most recently used\n"\
+"    in deployment configuration file that was most recently used\n"\
 "    by this instance's 'pkispawn' (or 'pkispawn -u') command will be\n"\
 "    utilized by 'pkidestroy' to remove this instance.\n\n"\
 "    Finally, if an optional '-p <prefix>' is defined, this value WILL be\n"\
diff --git a/base/deploy/src/scriptlets/pkiparser.py b/base/deploy/src/scriptlets/pkiparser.py
index 0d811af6ea9c5886c2a2bcef7d9994b75d3a07ff..6103ce9e5b8a0bc12794348087c77c479a674a37 100644
--- a/base/deploy/src/scriptlets/pkiparser.py
+++ b/base/deploy/src/scriptlets/pkiparser.py
@@ -171,7 +171,7 @@ class PKIConfigParser:
                 deployed_pki_subsystem_path + "/" +\
                 "registry" + "/" +\
                 config.pki_subsystem.lower() + "/" +\
-                config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE
+                config.PKI_DEPLOYMENT_CONFIGURATION_FILE
         # always verify that configuration file exists
         if not os.path.exists(config.pkideployment_cfg) or\
            not os.path.isfile(config.pkideployment_cfg):
@@ -215,7 +215,9 @@ class PKIConfigParser:
             self.pki_config = ConfigParser.ConfigParser()
             # Make keys case-sensitive!
             self.pki_config.optionxform = str
-            self.pki_config.read(config.pkideployment_cfg)
+            self.pki_config.read([
+                config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE,
+                config.pkideployment_cfg])
             config.pki_default_dict = self.pki_config.defaults()
             pkilogging.sensitive_parameters = config.pki_default_dict['sensitive_parameters'].split()
             config.pki_common_dict = dict(self.pki_config._sections['Common'])
@@ -2302,11 +2304,11 @@ class PKIConfigParser:
             # Finalization name/value pairs
             config.pki_master_dict['pki_deployment_cfg_replica'] =\
                 os.path.join(config.pki_master_dict['pki_subsystem_registry_path'],
-                             config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE)
+                             config.PKI_DEPLOYMENT_CONFIGURATION_FILE)
             config.pki_master_dict['pki_deployment_cfg_spawn_archive'] =\
                 config.pki_master_dict['pki_subsystem_archive_log_path'] + "/" +\
                 "spawn" + "_" +\
-                config.PKI_DEPLOYMENT_DEFAULT_CONFIGURATION_FILE + "." +\
+                config.PKI_DEPLOYMENT_CONFIGURATION_FILE + "." +\
                 config.pki_master_dict['pki_timestamp']
             config.pki_master_dict['pki_manifest'] =\
                 config.pki_master_dict['pki_subsystem_registry_path'] + "/" +\
-- 
1.7.12.1

