pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0139-ca-install-merge-duplicated-code-for-DM-password.patch

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