mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
More work on xmlrpc stuff, started migrated more code to use errors2 instead of errors
This commit is contained in:
committed by
Rob Crittenden
parent
833088955c
commit
244346dbcb
@@ -36,7 +36,7 @@ import frontend
|
||||
import backend
|
||||
import plugable
|
||||
import util
|
||||
from errors2 import PublicError, CommandError
|
||||
from errors2 import PublicError, CommandError, HelpError
|
||||
from constants import CLI_TAB
|
||||
from parameters import Password, Bytes
|
||||
|
||||
@@ -398,7 +398,7 @@ class help(frontend.Application):
|
||||
return
|
||||
key = str(command)
|
||||
if key not in self.application:
|
||||
raise errors.UnknownHelpError(key)
|
||||
raise HelpError(topic=key)
|
||||
cmd = self.application[key]
|
||||
print 'Purpose: %s' % cmd.doc
|
||||
self.application.build_parser(cmd).print_help()
|
||||
|
||||
@@ -61,10 +61,10 @@ FORMAT_STDERR = ': '.join([
|
||||
# Log format for log file:
|
||||
FORMAT_FILE = '\t'.join([
|
||||
'%(created)f',
|
||||
'%(levelname)s',
|
||||
'%(message)r', # Using %r for repr() so message is a single line
|
||||
'%(process)d',
|
||||
'%(threadName)s',
|
||||
'%(levelname)s',
|
||||
'%(message)r', # Using %r for repr() so message is a single line
|
||||
])
|
||||
|
||||
|
||||
|
||||
@@ -85,7 +85,9 @@ current block assignments:
|
||||
|
||||
- **4001 - 4099** Open for general execution errors
|
||||
|
||||
- **4100 - 4199** `LDAPError` and its subclasses
|
||||
- **4100 - 4199** `BuiltinError` and its subclasses
|
||||
|
||||
- **4200 - 4299** `LDAPError` and its subclasses
|
||||
|
||||
- **4300 - 4999** *Reserved for future use*
|
||||
|
||||
@@ -581,14 +583,38 @@ class ExecutionError(PublicError):
|
||||
errno = 4000
|
||||
|
||||
|
||||
class LDAPError(ExecutionError):
|
||||
class BuiltinError(ExecutionError):
|
||||
"""
|
||||
**4100** Base class for LDAP execution errors (*4100 - 4199*).
|
||||
**4100** Base class for builtin execution errors (*4100 - 4199*).
|
||||
"""
|
||||
|
||||
errno = 4100
|
||||
|
||||
|
||||
class HelpError(BuiltinError):
|
||||
"""
|
||||
**4101** Raised when requesting help for an unknown topic.
|
||||
|
||||
For example:
|
||||
|
||||
>>> raise HelpError(topic='newfeature')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
HelpError: no command nor help topic 'newfeature'
|
||||
"""
|
||||
|
||||
errno = 4101
|
||||
format = _('no command nor help topic %(topic)r')
|
||||
|
||||
|
||||
class LDAPError(ExecutionError):
|
||||
"""
|
||||
**4200** Base class for LDAP execution errors (*4200 - 4299*).
|
||||
"""
|
||||
|
||||
errno = 4200
|
||||
|
||||
|
||||
|
||||
##############################################################################
|
||||
# 5000 - 5999: Generic errors
|
||||
|
||||
@@ -97,17 +97,28 @@ class Command(plugable.Plugin):
|
||||
XML-RPC and the executed an the nearest IPA server.
|
||||
"""
|
||||
params = self.args_options_2_params(*args, **options)
|
||||
self.info(
|
||||
'%s(%s)', self.name, ', '.join(self.__repr_iter(params))
|
||||
)
|
||||
params = self.normalize(**params)
|
||||
params = self.convert(**params)
|
||||
params.update(self.get_default(**params))
|
||||
self.validate(**params)
|
||||
(args, options) = self.params_2_args_options(**params)
|
||||
# FIXME: don't log passords!
|
||||
self.info(make_repr(self.name, *args, **options))
|
||||
result = self.run(*args, **options)
|
||||
self.debug('%s result: %r', self.name, result)
|
||||
self.debug('result from %s(): %r', self.name, result)
|
||||
return result
|
||||
|
||||
def __repr_iter(self, params):
|
||||
for arg in self.args():
|
||||
value = params.get(arg.name, None)
|
||||
yield '%r' % (arg.safe_value(value),)
|
||||
for option in self.options():
|
||||
if option.name not in params:
|
||||
continue
|
||||
value = params[option.name]
|
||||
yield '%s=%r' % (option.name, option.safe_value(value))
|
||||
|
||||
def args_options_2_params(self, *args, **options):
|
||||
"""
|
||||
Merge (args, options) into params.
|
||||
@@ -245,10 +256,7 @@ class Command(plugable.Plugin):
|
||||
"""
|
||||
for param in self.params():
|
||||
value = kw.get(param.name, None)
|
||||
if value is not None:
|
||||
param.validate(value)
|
||||
elif param.required:
|
||||
raise errors.RequirementError(param.name)
|
||||
param.validate(value)
|
||||
|
||||
def run(self, *args, **options):
|
||||
"""
|
||||
|
||||
@@ -353,6 +353,11 @@ class Param(ReadOnly):
|
||||
self.validate(value)
|
||||
return value
|
||||
|
||||
def safe_value(self, value):
|
||||
if isinstance(self, Password) and value is not None:
|
||||
return u'********'
|
||||
return value
|
||||
|
||||
def clone(self, **overrides):
|
||||
"""
|
||||
Return a new `Param` instance similar to this one.
|
||||
|
||||
@@ -22,7 +22,7 @@ Misc frontend plugins.
|
||||
"""
|
||||
|
||||
import re
|
||||
from ipalib import api, LocalOrRemote, Bytes
|
||||
from ipalib import api, LocalOrRemote
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,11 +48,7 @@ class xmlserver(Backend):
|
||||
self.debug('Received RPC call to %r', method)
|
||||
if method not in self.Command:
|
||||
raise CommandError(name=method)
|
||||
self.info('params = %r', params)
|
||||
(args, options) = params_2_args_options(params)
|
||||
self.info('args = %r', args)
|
||||
self.info('options = %r', options)
|
||||
self.debug(make_repr(method, *args, **options))
|
||||
result = self.Command[method](*args, **options)
|
||||
return (result,) # Must wrap XML-RPC response in a tuple singleton
|
||||
|
||||
|
||||
@@ -285,10 +285,8 @@ class test_Command(ClassChecker):
|
||||
# Check with a missing required arg
|
||||
fail = dict(okay)
|
||||
fail.pop('option1')
|
||||
e = raises(errors.RequirementError, sub.validate, **fail)
|
||||
e = raises(errors2.RequirementError, sub.validate, **fail)
|
||||
assert e.name == 'option1'
|
||||
assert e.value is None
|
||||
assert e.index is None
|
||||
|
||||
def test_execute(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user