summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2016-05-18 10:03:39 +0200
committerJan Cholasta <jcholast@redhat.com>2016-05-25 16:06:26 +0200
commit2f6b333187e150369e9f761520aaebca0b45c011 (patch)
treeae02eeb7cd0d3bcfbaf78cebd5b938d9d14c8488 /ipalib
parente0275abe6f5192e68b7f57acf37b01aaa89003ea (diff)
downloadfreeipa-2f6b333187e150369e9f761520aaebca0b45c011.tar.gz
freeipa-2f6b333187e150369e9f761520aaebca0b45c011.tar.xz
freeipa-2f6b333187e150369e9f761520aaebca0b45c011.zip
frontend: re-raise remote RequirementError using CLI name in CLI
https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/frontend.py21
-rw-r--r--ipalib/parameters.py13
-rw-r--r--ipalib/plugins/group.py4
-rw-r--r--ipalib/plugins/trust.py2
4 files changed, 17 insertions, 23 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index ba830f2dd..341eedc5b 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -37,7 +37,7 @@ from ipalib.text import _
from ipalib.errors import (ZeroArgumentError, MaxArgumentError, OverlapError,
VersionError, OptionError, InvocationError,
ValidationError, ConversionError)
-from ipalib import messages
+from ipalib import errors, messages
from ipalib.request import context, context_frame
from ipalib.util import json_serialize
@@ -351,13 +351,6 @@ class HasParam(Plugin):
for spec in get():
param = create_param(spec)
if env is None or param.use_in_context(env):
- if env is not None and not hasattr(param, 'env'):
- # Force specified environment. The way it is done is violation of ReadOnly promise.
- # Unfortunately, all alternatives are worse from both performance and code complexity
- # points of view. See following threads on freeipa-devel@ for references:
- # https://www.redhat.com/archives/freeipa-devel/2011-August/msg00000.html
- # https://www.redhat.com/archives/freeipa-devel/2011-August/msg00011.html
- object.__setattr__(param, 'env', env)
yield param
def _create_param_namespace(self, name, env=None):
@@ -735,7 +728,7 @@ class Command(HasParam):
"""
for param in self.params():
value = kw.get(param.name, None)
- param.validate(value, self.env.context, supplied=param.name in kw)
+ param.validate(value, supplied=param.name in kw)
def verify_client_version(self, client_version):
"""
@@ -796,7 +789,15 @@ class Command(HasParam):
"""
Forward call over RPC to this same command on server.
"""
- return self.Backend.rpcclient.forward(self.name, *args, **kw)
+ try:
+ return self.Backend.rpcclient.forward(self.name, *args, **kw)
+ except errors.RequirementError as e:
+ if self.api.env.context != 'cli':
+ raise
+ name = getattr(e, 'name', None)
+ if name is None or name not in self.params:
+ raise
+ raise errors.RequirementError(name=self.params[name].cli_name)
def _on_finalize(self):
"""
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index d1d065ef2..1b35b396a 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -572,10 +572,7 @@ class Param(ReadOnly):
value = self.get_default(**kw)
else:
value = self.convert(self.normalize(value))
- if hasattr(self, 'env'):
- self.validate(value, self.env.context, supplied=self.name in kw) #pylint: disable=E1101
- else:
- self.validate(value, supplied=self.name in kw)
+ self.validate(value, supplied=self.name in kw)
return value
def get_param_name(self):
@@ -811,20 +808,16 @@ class Param(ReadOnly):
return value
raise ConversionError(name=self.name, error=ugettext(self.type_error))
- def validate(self, value, context=None, supplied=None):
+ def validate(self, value, supplied=None):
"""
Check validity of ``value``.
:param value: A proposed value for this parameter.
- :param context: The context we are running in.
:param supplied: True if this parameter was supplied explicitly.
"""
if value is None:
if self.required or (supplied and 'nonempty' in self.flags):
- if context == 'cli':
- raise RequirementError(name=self.cli_name)
- else:
- raise RequirementError(name=self.name)
+ raise RequirementError(name=self.name)
return
if self.multivalue:
if type(value) is not tuple:
diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py
index 85ed1d2b0..b9d38592a 100644
--- a/ipalib/plugins/group.py
+++ b/ipalib/plugins/group.py
@@ -413,7 +413,7 @@ class group_mod(LDAPUpdate):
# Can't check for this in a validator because we lack context
if 'gidnumber' in options and options['gidnumber'] is None:
- raise errors.RequirementError(name='gid')
+ raise errors.RequirementError(name='gidnumber')
return dn
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
@@ -422,7 +422,7 @@ class group_mod(LDAPUpdate):
if call_func.__name__ == 'update_entry':
if isinstance(exc, errors.ObjectclassViolation):
if 'gidNumber' in exc.message and 'posixGroup' in exc.message:
- raise errors.RequirementError(name='gid')
+ raise errors.RequirementError(name='gidnumber')
raise exc
diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py
index 6d6ac6096..44049aeb3 100644
--- a/ipalib/plugins/trust.py
+++ b/ipalib/plugins/trust.py
@@ -787,7 +787,7 @@ sides.
)
if 'trust_type' not in options:
- raise errors.RequirementError(name=_('trust type'))
+ raise errors.RequirementError(name='trust_type')
if options['trust_type'] != u'ad':
raise errors.ValidationError(