Martin Kosek wrote:
On Wed, 2011-09-14 at 14:23 +0200, Martin Kosek wrote:
On Tue, 2011-09-13 at 14:35 -0400, Rob Crittenden wrote:
Add an escape clause to the CSR validator in the cert plugin. If the csr
is a file just return and let the load_files() call slurp in the
contents. It will still get validated.
rob
This works fine for CSR file.
Shouldn't we fix this also for other File params? For example,
entitle-import command will be affected as well:
takes_args = (
File('usercertificate*', validate_certificate,
cli_name='certificate_file',
),
)
We can create a separate ticket for entitle-import if you want.
Martin
Oh, and one more thing - API.txt has to be updated since you added a
label to the CSR parameter.
Martin
Updated patch with API attached. I had that fixed, dropped my changes,
re-made them and forgot to update API again.
entitle-import doesn't have stdin_if_missing set so will only read from
a file, there is no interactive option.
rob
>From 1d00575813aaa3ff4366f11100303fa029ad8bb4 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Tue, 13 Sep 2011 14:25:16 -0400
Subject: [PATCH] Skip the cert validator if the csr we are passed in is a
valid filename
The validator will still fire, just after the load_files() call. Basically
it will hit the validator twice. The first time it will exit because the
value of csr is a filename. The second time it will run the validator against
the contents of the file.
ticket https://fedorahosted.org/freeipa/ticket/1777
---
API.txt | 2 +-
ipalib/plugins/cert.py | 7 +++++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/API.txt b/API.txt
index 5f8e72d..aee0c88 100644
--- a/API.txt
+++ b/API.txt
@@ -420,7 +420,7 @@ arg: Str('serial_number', validate_serial_number, label=Gettext('Serial number',
output: Output('result', None, None)
command: cert_request
args: 1,3,1
-arg: File('csr', validate_csr, cli_name='csr_file', normalizer=normalize_csr)
+arg: File('csr', validate_csr, cli_name='csr_file', label=Gettext('CSR', domain='ipa', localedir=None), normalizer=normalize_csr)
option: Str('principal', label=Gettext('Principal', domain='ipa', localedir=None))
option: Str('request_type', autofill=True, default=u'pkcs10')
option: Flag('add', autofill=True, default=False)
diff --git a/ipalib/plugins/cert.py b/ipalib/plugins/cert.py
index e32004e..aa3cf21 100644
--- a/ipalib/plugins/cert.py
+++ b/ipalib/plugins/cert.py
@@ -23,6 +23,7 @@ from ipalib import api, SkipPluginModule
if api.env.enable_ra is not True:
# In this case, abort loading this plugin module...
raise SkipPluginModule(reason='env.enable_ra is not True')
+import os
from ipalib import Command, Str, Int, Bytes, Flag, File
from ipalib import errors
from ipalib import pkcs10
@@ -129,6 +130,11 @@ def validate_csr(ugettext, csr):
Ensure the CSR is base64-encoded and can be decoded by our PKCS#10
parser.
"""
+ if api.env.context == 'cli':
+ # If we are passed in a pointer to a valid file on the client side
+ # escape and let the load_files() handle things
+ if csr and os.path.exists(csr):
+ return
try:
request = pkcs10.load_certificate_request(csr)
except TypeError, e:
@@ -203,6 +209,7 @@ class cert_request(VirtualCommand):
takes_args = (
File('csr', validate_csr,
+ label=_('CSR'),
cli_name='csr_file',
normalizer=normalize_csr,
),
--
1.7.6
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel