URL: https://github.com/freeipa/freeipa/pull/557 Author: HonzaCholasta Title: #557: certmap: load certificate from file in certmap-match CLI Action: opened
PR body: """ Load the certificate from a file specified in the first argument. Raw certificate value can be specified using --certificate. https://pagure.io/freeipa/issue/6646 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/557/head:pr557 git checkout pr557
From 1dd6a438aabf3fe3f03a8b75d5dbed5aeb1b2fc4 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Thu, 9 Mar 2017 07:19:26 +0100 Subject: [PATCH] certmap: load certificate from file in certmap-match CLI Load the certificate from a file specified in the first argument. Raw certificate value can be specified using --certificate. https://pagure.io/freeipa/issue/6646 --- ipaclient/plugins/certmap.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ipaclient/plugins/certmap.py diff --git a/ipaclient/plugins/certmap.py b/ipaclient/plugins/certmap.py new file mode 100644 index 0000000..50a594f --- /dev/null +++ b/ipaclient/plugins/certmap.py @@ -0,0 +1,49 @@ +# +# Copyright (C) 2017 FreeIPA Contributors see COPYING for license +# + +from ipaclient.frontend import MethodOverride +from ipalib import errors, x509 +from ipalib.parameters import File +from ipalib.plugable import Registry +from ipalib.text import _ + +register = Registry() + + +@register(override=True, no_fail=True) +class certmap_match(MethodOverride): + takes_args = ( + File( + 'file?', + label=_("Input file"), + doc=_("File to load the certificate from"), + include='cli', + ), + ) + + def get_args(self): + for arg in super(certmap_match, self).get_args(): + if arg.name != 'certificate' or self.api.env.context != 'cli': + yield arg + + def get_options(self): + for arg in super(certmap_match, self).get_args(): + if arg.name == 'certificate' and self.api.env.context == 'cli': + yield arg.clone(required=False) + for option in super(certmap_match, self).get_options(): + yield option + + def forward(self, *args, **options): + if self.api.env.context == 'cli': + if args and 'certificate' in options: + raise errors.MutuallyExclusiveError( + reason=_("cannot specify both raw certificate and file")) + if args: + args = [x509.strip_header(args[0])] + elif 'certificate' in options: + args = [options.pop('certificate')] + else: + args = [] + + return super(certmap_match, self).forward(*args, **options)
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code