483b06
From c702bb6ca3742cf7ea156e062840623f95a001b7 Mon Sep 17 00:00:00 2001
483b06
From: Martin Babinsky <mbabinsk@redhat.com>
483b06
Date: Thu, 22 Jun 2017 15:08:08 +0200
483b06
Subject: [PATCH] Use the compound statement formatting API for configuring
483b06
 PKINIT
483b06
483b06
Use `if_branch` and `else_branch` context managers instead of raw
483b06
`command` calls in the method that generates Bash snippet that
483b06
configures PKINIT on the master.
483b06
483b06
https://pagure.io/freeipa/issue/7036
483b06
483b06
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
---
483b06
 ipaserver/advise/plugins/smart_card_auth.py | 16 +++++++---------
483b06
 1 file changed, 7 insertions(+), 9 deletions(-)
483b06
483b06
diff --git a/ipaserver/advise/plugins/smart_card_auth.py b/ipaserver/advise/plugins/smart_card_auth.py
483b06
index 138a44316473f6b504a44a1b68d01fa4d5a58308..2dc9ddb25ce41a8c85aab827a92a1143784d9457 100644
483b06
--- a/ipaserver/advise/plugins/smart_card_auth.py
483b06
+++ b/ipaserver/advise/plugins/smart_card_auth.py
483b06
@@ -214,15 +214,13 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config):
483b06
 
483b06
     def check_and_enable_pkinit(self):
483b06
         self.log.comment('check whether PKINIT is configured on the master')
483b06
-        self.log.command(
483b06
-            "if ipa-pkinit-manage status | grep -q 'enabled'")
483b06
-        self.log.command('then')
483b06
-        self.log.command('  echo "PKINIT already enabled"')
483b06
-        self.log.command('else')
483b06
-        self.log.exit_on_failed_command(
483b06
-            'ipa-pkinit-manage enable',
483b06
-            ['Failed to issue PKINIT certificates to local KDC'])
483b06
-        self.log.command('fi')
483b06
+        with self.log.if_branch(
483b06
+                "ipa-pkinit-manage status | grep -q 'enabled'"):
483b06
+            self.log.command('echo "PKINIT already enabled"')
483b06
+        with self.log.else_branch():
483b06
+            self.log.exit_on_failed_command(
483b06
+                'ipa-pkinit-manage enable',
483b06
+                ['Failed to issue PKINIT certificates to local KDC'])
483b06
 
483b06
     def enable_ok_to_auth_as_delegate_on_http_principal(self):
483b06
         self.log.comment('Enable OK-AS-DELEGATE flag on the HTTP principal')
483b06
-- 
483b06
2.9.4
483b06