pgreco / rpms / ipa

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

Blame SOURCES/0158-ca-cert-show-check-certificate_out-in-options.patch

483b06
From c1258d68268bc93536ba66921d65a2550bdf475e Mon Sep 17 00:00:00 2001
483b06
From: Stanislav Laznicka <slaznick@redhat.com>
483b06
Date: Tue, 9 May 2017 17:45:20 +0200
483b06
Subject: [PATCH] ca/cert-show: check certificate_out in options
483b06
483b06
If --certificate-out was specified on the command line, it will appear
483b06
among the options. If it was empty, it will be None.
483b06
483b06
This check was done properly in the ca plugin. Lets' just unify how this
483b06
is handled and improve user experience by announcing which option causes
483b06
the failure.
483b06
483b06
https://pagure.io/freeipa/issue/6885
483b06
483b06
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
483b06
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
483b06
---
483b06
 ipaclient/plugins/ca.py   |  8 ++++++--
483b06
 ipaclient/plugins/cert.py | 12 +++++++++---
483b06
 2 files changed, 15 insertions(+), 5 deletions(-)
483b06
483b06
diff --git a/ipaclient/plugins/ca.py b/ipaclient/plugins/ca.py
483b06
index fcdf484635c7611d905f28629a380a0152c7bde1..fe9c55f4c07b4682de1ad882b6c5651dafece716 100644
483b06
--- a/ipaclient/plugins/ca.py
483b06
+++ b/ipaclient/plugins/ca.py
483b06
@@ -4,7 +4,7 @@
483b06
 
483b06
 import base64
483b06
 from ipaclient.frontend import MethodOverride
483b06
-from ipalib import util, x509, Str
483b06
+from ipalib import errors, util, x509, Str
483b06
 from ipalib.plugable import Registry
483b06
 from ipalib.text import _
483b06
 
483b06
@@ -26,7 +26,11 @@ class WithCertOutArgs(MethodOverride):
483b06
         filename = None
483b06
         if 'certificate_out' in options:
483b06
             filename = options.pop('certificate_out')
483b06
-            util.check_writable_file(filename)
483b06
+            try:
483b06
+                util.check_writable_file(filename)
483b06
+            except errors.FileError as e:
483b06
+                raise errors.ValidationError(name='certificate-out',
483b06
+                                             error=str(e))
483b06
 
483b06
         result = super(WithCertOutArgs, self).forward(*keys, **options)
483b06
         if filename:
483b06
diff --git a/ipaclient/plugins/cert.py b/ipaclient/plugins/cert.py
483b06
index 9ec6970b18d0cdc3863259faee3a697f63799c3f..93cd3cef1a14925bc0795b32e97e44d69897be5c 100644
483b06
--- a/ipaclient/plugins/cert.py
483b06
+++ b/ipaclient/plugins/cert.py
483b06
@@ -50,9 +50,15 @@ class CertRetrieveOverride(MethodOverride):
483b06
     )
483b06
 
483b06
     def forward(self, *args, **options):
483b06
-        certificate_out = options.pop('certificate_out', None)
483b06
-        if certificate_out is not None:
483b06
-            util.check_writable_file(certificate_out)
483b06
+        if 'certificate_out' in options:
483b06
+            certificate_out = options.pop('certificate_out')
483b06
+            try:
483b06
+                util.check_writable_file(certificate_out)
483b06
+            except errors.FileError as e:
483b06
+                raise errors.ValidationError(name='certificate-out',
483b06
+                                             error=str(e))
483b06
+        else:
483b06
+            certificate_out = None
483b06
 
483b06
         result = super(CertRetrieveOverride, self).forward(*args, **options)
483b06
 
483b06
-- 
483b06
2.9.4
483b06