From e1e7386164f1df2eb13ce4ce2da420534036e55c Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Tue, 13 Nov 2012 23:18:52 -0500 Subject: Refactored str2bool(). --- base/deploy/src/scriptlets/pkihelper.py | 38 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'base/deploy/src/scriptlets/pkihelper.py') diff --git a/base/deploy/src/scriptlets/pkihelper.py b/base/deploy/src/scriptlets/pkihelper.py index 3461e635c..09e624094 100644 --- a/base/deploy/src/scriptlets/pkihelper.py +++ b/base/deploy/src/scriptlets/pkihelper.py @@ -52,6 +52,10 @@ import pkimessages as log from pkiparser import read_simple_configuration_file +# PKI Deployment Helper Functions +def str2bool(string): + return string.lower() in ("yes", "true", "t", "1") + # PKI Deployment Helper Functions def pki_copytree(src, dst, symlinks=False, ignore=None): """Recursively copy a directory tree using copy2(). @@ -450,7 +454,7 @@ class configuration_file: extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) # Verify existence of Admin Password (except for Clones) - if not config.str2bool(master['pki_clone']): + if not str2bool(master['pki_clone']): if not sensitive.has_key('pki_admin_password') or\ not len(sensitive['pki_admin_password']): pkilogging.pki_log.error( @@ -460,7 +464,7 @@ class configuration_file: extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) # If required, verify existence of Backup Password - if config.str2bool(master['pki_backup_keys']): + if str2bool(master['pki_backup_keys']): if not sensitive.has_key('pki_backup_password') or\ not len(sensitive['pki_backup_password']): pkilogging.pki_log.error( @@ -488,7 +492,7 @@ class configuration_file: extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) # Verify existence of PKCS #12 Password (ONLY for Clones) - if config.str2bool(master['pki_clone']): + if str2bool(master['pki_clone']): if not sensitive.has_key('pki_clone_pkcs12_password') or\ not len(sensitive['pki_clone_pkcs12_password']): pkilogging.pki_log.error( @@ -499,9 +503,9 @@ class configuration_file: sys.exit(1) # Verify existence of Security Domain Password File # (ONLY for Clones, KRA, OCSP, TKS, or Subordinate CA) - if config.str2bool(master['pki_clone']) or\ + if str2bool(master['pki_clone']) or\ not master['pki_subsystem'] == "CA" or\ - config.str2bool(master['pki_subordinate']): + str2bool(master['pki_subordinate']): if not sensitive.has_key('pki_security_domain_password') or\ not len(sensitive['pki_security_domain_password']): pkilogging.pki_log.error( @@ -526,30 +530,30 @@ class configuration_file: # Silently verify the existence of 'mutually exclusive' data if master['pki_subsystem'] in PKIConfig.PKI_TOMCAT_SUBSYSTEMS: if master['pki_subsystem'] == "CA": - if config.str2bool(master['pki_clone']) and\ - config.str2bool(master['pki_external']) and\ - config.str2bool(master['pki_subordinate']): + if str2bool(master['pki_clone']) and\ + str2bool(master['pki_external']) and\ + str2bool(master['pki_subordinate']): pkilogging.pki_log.error( log.PKIHELPER_MUTUALLY_EXCLUSIVE_CLONE_EXTERNAL_SUB_CA, master['pki_deployment_cfg'], extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) - elif config.str2bool(master['pki_clone']) and\ - config.str2bool(master['pki_external']): + elif str2bool(master['pki_clone']) and\ + str2bool(master['pki_external']): pkilogging.pki_log.error( log.PKIHELPER_MUTUALLY_EXCLUSIVE_CLONE_EXTERNAL_CA, master['pki_deployment_cfg'], extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) - elif config.str2bool(master['pki_clone']) and\ - config.str2bool(master['pki_subordinate']): + elif str2bool(master['pki_clone']) and\ + str2bool(master['pki_subordinate']): pkilogging.pki_log.error( log.PKIHELPER_MUTUALLY_EXCLUSIVE_CLONE_SUB_CA, master['pki_deployment_cfg'], extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) - elif config.str2bool(master['pki_external']) and\ - config.str2bool(master['pki_subordinate']): + elif str2bool(master['pki_external']) and\ + str2bool(master['pki_subordinate']): pkilogging.pki_log.error( log.PKIHELPER_MUTUALLY_EXCLUSIVE_EXTERNAL_SUB_CA, master['pki_deployment_cfg'], @@ -568,7 +572,7 @@ class configuration_file: # 'True' or 'False', etc.) of ALL required "value" parameters. # if master['pki_subsystem'] in PKIConfig.PKI_TOMCAT_SUBSYSTEMS: - if config.str2bool(master['pki_clone']): + if str2bool(master['pki_clone']): # Verify existence of clone parameters if not master.has_key('pki_ds_base_dn') or\ not len(master['pki_ds_base_dn']): @@ -680,7 +684,7 @@ class configuration_file: extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) elif master['pki_subsystem'] == "CA" and\ - config.str2bool(master['pki_external']): + str2bool(master['pki_external']): if not master.has_key('pki_external_step_two') or\ not len(master['pki_external_step_two']): pkilogging.pki_log.error( @@ -689,7 +693,7 @@ class configuration_file: master['pki_deployment_cfg'], extra=PKIConfig.PKI_INDENTATION_LEVEL_2) sys.exit(1) - if not config.str2bool(master['pki_step_two']): + if not str2bool(master['pki_step_two']): if not master.has_key('pki_external_csr_path') or\ not len(master['pki_external_csr_path']): pkilogging.pki_log.error( -- cgit