483b06
From fd7b5b32f907fff7c454a91838f5483501220971 Mon Sep 17 00:00:00 2001
483b06
From: Tomas Krizek <tkrizek@redhat.com>
483b06
Date: Wed, 3 May 2017 10:05:25 +0200
483b06
Subject: [PATCH] ca install: merge duplicated code for DM password
483b06
483b06
Extract copy-pasted code to a single function.
483b06
483b06
Related https://pagure.io/freeipa/issue/6892
483b06
483b06
Signed-off-by: Tomas Krizek <tkrizek@redhat.com>
483b06
Reviewed-By: Martin Basti <mbasti@redhat.com>
483b06
Reviewed-By: Christian Heimes <cheimes@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 install/tools/ipa-ca-install | 40 +++++++++++++++++-----------------------
483b06
 1 file changed, 17 insertions(+), 23 deletions(-)
483b06
483b06
diff --git a/install/tools/ipa-ca-install b/install/tools/ipa-ca-install
483b06
index c05abb9646884ad5a4411dba98df466c37f09613..4bcb59a29d5a64c118649374104ae8f1cd451ea4 100755
483b06
--- a/install/tools/ipa-ca-install
483b06
+++ b/install/tools/ipa-ca-install
483b06
@@ -116,9 +116,19 @@ def parse_options():
483b06
     return safe_options, options, filename
483b06
 
483b06
 
483b06
-def get_dirman_password():
483b06
-    return installutils.read_password(
483b06
-        "Directory Manager (existing master)", confirm=False, validate=False)
483b06
+def _get_dirman_password(password=None, unattended=False):
483b06
+    if not password:
483b06
+        if unattended:
483b06
+            sys.exit('Directory Manager password required')
483b06
+        try:
483b06
+            password = installutils.read_password(
483b06
+                "Directory Manager (existing master)", confirm=False,
483b06
+                validate=False)
483b06
+        except KeyboardInterrupt:
483b06
+            sys.exit(0)
483b06
+        if password is None:
483b06
+            sys.exit("Directory Manager password required")
483b06
+    return password
483b06
 
483b06
 
483b06
 def install_replica(safe_options, options, filename):
483b06
@@ -142,16 +152,8 @@ def install_replica(safe_options, options, filename):
483b06
         check_creds(options, api.env.realm)
483b06
 
483b06
     # get the directory manager password
483b06
-    dirman_password = options.password
483b06
-    if not dirman_password:
483b06
-        if options.unattended:
483b06
-            sys.exit('Directory Manager password required')
483b06
-        try:
483b06
-            dirman_password = get_dirman_password()
483b06
-        except KeyboardInterrupt:
483b06
-            sys.exit(0)
483b06
-        if dirman_password is None:
483b06
-            sys.exit("Directory Manager password required")
483b06
+    dirman_password = _get_dirman_password(
483b06
+        options.password, options.unattended)
483b06
 
483b06
     if (not options.promote and not options.admin_password and
483b06
             not options.skip_conncheck and options.unattended):
483b06
@@ -199,16 +201,8 @@ def install_replica(safe_options, options, filename):
483b06
 
483b06
 
483b06
 def install_master(safe_options, options):
483b06
-    dm_password = options.password
483b06
-    if not dm_password:
483b06
-        if options.unattended:
483b06
-            sys.exit('Directory Manager password required')
483b06
-        try:
483b06
-            dm_password = get_dirman_password()
483b06
-        except KeyboardInterrupt:
483b06
-            sys.exit(0)
483b06
-        if dm_password is None:
483b06
-            sys.exit("Directory Manager password required")
483b06
+    dm_password = _get_dirman_password(
483b06
+        options.password, options.unattended)
483b06
 
483b06
     options.realm_name = api.env.realm
483b06
     options.domain_name = api.env.domain
483b06
-- 
483b06
2.9.4
483b06