summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins
diff options
context:
space:
mode:
authorFraser Tweedale <ftweedal@redhat.com>2015-07-02 03:31:31 -0400
committerTomas Babej <tbabej@redhat.com>2015-07-08 00:25:46 +0200
commitbed6f402e2d5587c35ff7e84ba3b80026c6db73d (patch)
treefe20caae489a567855f0dbe56605f85a80a1d8a5 /ipalib/plugins
parent62e8002bc43ddd890c3db35a123cb7daf35e3121 (diff)
downloadfreeipa-bed6f402e2d5587c35ff7e84ba3b80026c6db73d.tar.gz
freeipa-bed6f402e2d5587c35ff7e84ba3b80026c6db73d.tar.xz
freeipa-bed6f402e2d5587c35ff7e84ba3b80026c6db73d.zip
certprofile: add option to export profile config
Add the `--out=FILENAME' option to `certprofile-show'. When given, it exports the profile configuration from Dogtag and writes it to the named file. Fixes: https://fedorahosted.org/freeipa/ticket/5091 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipalib/plugins')
-rw-r--r--ipalib/plugins/certprofile.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/ipalib/plugins/certprofile.py b/ipalib/plugins/certprofile.py
index 9e1e47e94..abb62434e 100644
--- a/ipalib/plugins/certprofile.py
+++ b/ipalib/plugins/certprofile.py
@@ -5,7 +5,7 @@
import re
from ipalib import api, Bool, File, Str
-from ipalib import output
+from ipalib import output, util
from ipalib.plugable import Registry
from ipalib.plugins.virtual import VirtualCommand
from ipalib.plugins.baseldap import (
@@ -175,9 +175,42 @@ class certprofile_find(LDAPSearch):
class certprofile_show(LDAPRetrieve):
__doc__ = _("Display the properties of a Certificate Profile.")
- def execute(self, *args, **kwargs):
+ has_output_params = LDAPRetrieve.has_output_params + (
+ Str('config',
+ label=_('Profile configuration'),
+ ),
+ )
+
+ takes_options = LDAPRetrieve.takes_options + (
+ Str('out?',
+ doc=_('Write profile configuration to file'),
+ ),
+ )
+
+ def execute(self, *keys, **options):
ca_enabled_check()
- return super(certprofile_show, self).execute(*args, **kwargs)
+ result = super(certprofile_show, self).execute(*keys, **options)
+
+ if 'out' in options:
+ with self.api.Backend.ra_certprofile as profile_api:
+ result['result']['config'] = profile_api.read_profile(keys[0])
+
+ return result
+
+ def forward(self, *keys, **options):
+ if 'out' in options:
+ util.check_writable_file(options['out'])
+
+ result = super(certprofile_show, self).forward(*keys, **options)
+ if 'out' in options and 'config' in result['result']:
+ with open(options['out'], 'w') as f:
+ f.write(result['result'].pop('config'))
+ result['summary'] = (
+ _("Profile configuration stored in file '%(file)s'")
+ % dict(file=options['out'])
+ )
+
+ return result
@register()