mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
c7064494e5
Commands `ipa ca-show` and `ipa cert-show` share the same code,
this commit updates the former, closing the gap between them.
Reflecting the changes done in 5a44ca6383
.
https://pagure.io/freeipa/issue/7628
Signed-off-by: Armando Neto <abiagion@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
#
|
|
# Copyright (C) 2016 FreeIPA Contributors see COPYING for license
|
|
#
|
|
import base64
|
|
|
|
from ipaclient.frontend import MethodOverride
|
|
from ipalib import errors, util, x509, Str
|
|
from ipalib.plugable import Registry
|
|
from ipalib.text import _
|
|
|
|
register = Registry()
|
|
|
|
|
|
class WithCertOutArgs(MethodOverride):
|
|
|
|
takes_options = (
|
|
Str(
|
|
'certificate_out?',
|
|
doc=_('Write certificate (chain if --chain used) to file'),
|
|
include='cli',
|
|
cli_metavar='FILE',
|
|
),
|
|
)
|
|
|
|
def forward(self, *keys, **options):
|
|
filename = None
|
|
if 'certificate_out' in options:
|
|
filename = options.pop('certificate_out')
|
|
try:
|
|
util.check_writable_file(filename)
|
|
except errors.FileError as e:
|
|
raise errors.ValidationError(name='certificate-out',
|
|
error=str(e))
|
|
|
|
result = super(WithCertOutArgs, self).forward(*keys, **options)
|
|
if filename:
|
|
if options.get('chain', False):
|
|
certs = result['result']['certificate_chain']
|
|
else:
|
|
certs = [result['result']['certificate']]
|
|
certs = (x509.load_der_x509_certificate(base64.b64decode(cert))
|
|
for cert in certs)
|
|
x509.write_certificate_list(certs, filename)
|
|
|
|
return result
|
|
|
|
|
|
@register(override=True, no_fail=True)
|
|
class ca_add(WithCertOutArgs):
|
|
pass
|
|
|
|
|
|
@register(override=True, no_fail=True)
|
|
class ca_show(WithCertOutArgs):
|
|
pass
|