From 8278da6967dbe425b4e0c6cf37dc1c53052525b2 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Tue, 28 Jun 2016 11:05:01 +0200 Subject: client: add placeholders for required remote plugins Add placeholders for remote plugins which are required by client-side commands. They are used when the remote plugins are not available. This fixes API initialization error when the remote server does not have the plugins. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka --- ipaclient/plugins/automount.py | 17 ++++++++++++- ipaclient/plugins/otptoken_yubikey.py | 17 ++++++++++++- ipaclient/plugins/vault.py | 47 ++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/ipaclient/plugins/automount.py b/ipaclient/plugins/automount.py index 7ac541358..8405f9f4f 100644 --- a/ipaclient/plugins/automount.py +++ b/ipaclient/plugins/automount.py @@ -25,7 +25,7 @@ import six from ipaclient.frontend import MethodOverride from ipalib import api, errors from ipalib import Flag, Str -from ipalib.frontend import Command +from ipalib.frontend import Command, Method, Object from ipalib.plugable import Registry from ipalib import _ from ipapython.dn import DN @@ -39,8 +39,23 @@ DEFAULT_MAPS = (u'auto.direct', ) DEFAULT_KEYS = (u'/-', ) +@register(no_fail=True) +class _fake_automountlocation(Object): + name = 'automountlocation' + + +@register(no_fail=True) +class _fake_automountlocation_show(Method): + name = 'automountlocation_show' + NO_CLI = True + + @register(override=True, no_fail=True) class automountlocation_tofiles(MethodOverride): + @property + def NO_CLI(self): + return self.api.Command.automountlocation_show.NO_CLI + def output_for_cli(self, textui, result, *keys, **options): maps = result['result']['maps'] keys = result['result']['keys'] diff --git a/ipaclient/plugins/otptoken_yubikey.py b/ipaclient/plugins/otptoken_yubikey.py index e9aaba934..5e0d99462 100644 --- a/ipaclient/plugins/otptoken_yubikey.py +++ b/ipaclient/plugins/otptoken_yubikey.py @@ -25,7 +25,7 @@ import yubico from ipalib import _, IntEnum from ipalib.errors import NotFound -from ipalib.frontend import Command +from ipalib.frontend import Command, Method, Object from ipalib.plugable import Registry if six.PY3: @@ -50,6 +50,17 @@ register = Registry() topic = 'otp' +@register(no_fail=True) +class _fake_otptoken(Object): + name = 'otptoken' + + +@register(no_fail=True) +class _fake_otptoken_add(Method): + name = 'otptoken_add' + NO_CLI = True + + @register() class otptoken_add_yubikey(Command): __doc__ = _('Add a new YubiKey OTP token.') @@ -63,6 +74,10 @@ class otptoken_add_yubikey(Command): ) has_output_params = takes_options + @property + def NO_CLI(self): + return self.api.Command.otptoken_add.NO_CLI + def get_args(self): for arg in self.api.Command.otptoken_add.args(): yield arg diff --git a/ipaclient/plugins/vault.py b/ipaclient/plugins/vault.py index 2674970b5..11210d6e1 100644 --- a/ipaclient/plugins/vault.py +++ b/ipaclient/plugins/vault.py @@ -37,7 +37,7 @@ from cryptography.hazmat.primitives.serialization import load_pem_public_key,\ import nss.nss as nss from ipaclient.frontend import MethodOverride -from ipalib.frontend import Local +from ipalib.frontend import Local, Method, Object from ipalib import errors from ipalib import Bytes, Flag, Str from ipalib.plugable import Registry @@ -169,6 +169,17 @@ def decrypt(data, symmetric_key=None, private_key=None): message=_('Invalid credentials')) +@register(no_fail=True) +class _fake_vault(Object): + name = 'vault' + + +@register(no_fail=True) +class _fake_vault_add_internal(Method): + name = 'vault_add_internal' + NO_CLI = True + + @register() class vault_add(Local): __doc__ = _('Create a new vault.') @@ -191,6 +202,10 @@ class vault_add(Local): ), ) + @property + def NO_CLI(self): + return self.api.Command.vault_add_internal.NO_CLI + def get_args(self): for arg in self.api.Command.vault_add_internal.args(): yield arg @@ -327,6 +342,12 @@ class vault_add(Local): return response +@register(no_fail=True) +class _fake_vault_mod_internal(Method): + name = 'vault_mod_internal' + NO_CLI = True + + @register() class vault_mod(Local): __doc__ = _('Modify a vault.') @@ -373,6 +394,10 @@ class vault_mod(Local): ), ) + @property + def NO_CLI(self): + return self.api.Command.vault_mod_internal.NO_CLI + def get_args(self): for arg in self.api.Command.vault_mod_internal.args(): yield arg @@ -512,6 +537,12 @@ class vaultconfig_show(MethodOverride): return response +@register(no_fail=True) +class _fake_vault_archive_internal(Method): + name = 'vault_archive_internal' + NO_CLI = True + + @register() class vault_archive(Local): __doc__ = _('Archive data into a vault.') @@ -541,6 +572,10 @@ class vault_archive(Local): ), ) + @property + def NO_CLI(self): + return self.api.Command.vault_archive_internal.NO_CLI + def get_args(self): for arg in self.api.Command.vault_archive_internal.args(): yield arg @@ -741,6 +776,12 @@ class vault_archive(Local): return self.api.Command.vault_archive_internal(*args, **options) +@register(no_fail=True) +class _fake_vault_retrieve_internal(Method): + name = 'vault_retrieve_internal' + NO_CLI = True + + @register() class vault_retrieve(Local): __doc__ = _('Retrieve a data from a vault.') @@ -779,6 +820,10 @@ class vault_retrieve(Local): ), ) + @property + def NO_CLI(self): + return self.api.Command.vault_retrieve_internal.NO_CLI + def get_args(self): for arg in self.api.Command.vault_retrieve_internal.args(): yield arg -- cgit