From f58ff2921defef330d53e08e427a82ced7585c88 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 13 Oct 2009 11:28:00 -0600 Subject: Giant webui patch take 2 --- ipalib/cli.py | 2 +- ipalib/constants.py | 18 +++++++++++++--- ipalib/errors.py | 11 ++++++++++ ipalib/frontend.py | 1 + ipalib/parameters.py | 51 ++++++++++++++++++++++++++++++++++++++++++---- ipalib/plugable.py | 2 +- ipalib/plugins/kerberos.py | 9 ++------ ipalib/plugins/misc.py | 5 +++-- ipalib/plugins/user.py | 9 ++++---- 9 files changed, 85 insertions(+), 23 deletions(-) (limited to 'ipalib') diff --git a/ipalib/cli.py b/ipalib/cli.py index da689de6..e4700010 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -836,7 +836,7 @@ cli_plugins = ( def run(api): error = None try: - argv = api.bootstrap_with_global_options(context='cli') + (options, argv) = api.bootstrap_with_global_options(context='cli') for klass in cli_plugins: api.register(klass) api.load_plugins() diff --git a/ipalib/constants.py b/ipalib/constants.py index 9aff5e26..72b02b0a 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -99,11 +99,23 @@ DEFAULT_CONFIG = ( ('container_virtual', 'cn=virtual operations'), # Ports, hosts, and URIs: - ('lite_xmlrpc_port', 8888), - ('lite_webui_port', 9999), - ('xmlrpc_uri', 'http://localhost:8888'), + # FIXME: let's renamed xmlrpc_uri to rpc_xml_uri + ('xmlrpc_uri', 'http://localhost:8888/ipa/xml'), + ('rpc_json_uri', 'http://localhost:8888/ipa/json'), ('ldap_uri', 'ldap://localhost:389'), + # Web Application mount points + ('mount_ipa', '/ipa/'), + ('mount_xmlserver', 'xml'), + ('mount_jsonserver', 'json'), + ('mount_webui', 'ui/'), + ('mount_webui_assets', '_/'), + + # WebUI stuff: + ('webui_prod', True), + ('webui_assets_dir', None), + ('webui_assets_dburi', None), + # Debugging: ('verbose', False), ('debug', False), diff --git a/ipalib/errors.py b/ipalib/errors.py index cec80fb4..fb82062a 100644 --- a/ipalib/errors.py +++ b/ipalib/errors.py @@ -112,6 +112,7 @@ class PrivateError(StandardError): def __init__(self, **kw): self.msg = self.format % kw + self.kw = kw for (key, value) in kw.iteritems(): assert not hasattr(self, key), 'conflicting kwarg %s.%s = %r' % ( self.__class__.__name__, key, value, @@ -244,6 +245,7 @@ class PublicError(StandardError): format = None def __init__(self, format=None, message=None, **kw): + self.kw = kw name = self.__class__.__name__ if self.format is not None and format is not None: raise ValueError( @@ -407,6 +409,15 @@ class ServerNetworkError(PublicError): format = _('error on server %(server)r: %(error)s') +class JSONError(PublicError): + """ + **909** Raised when server recieved a malformed JSON-RPC request. + """ + + errno = 909 + format = _('Invalid JSON-RPC request: %(error)s') + + ############################################################################## # 1000 - 1999: Authentication errors diff --git a/ipalib/frontend.py b/ipalib/frontend.py index cf2dbb56..622c4276 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -375,6 +375,7 @@ class Command(HasParam): options = None params = None output_for_cli = None + obj = None def __call__(self, *args, **options): """ diff --git a/ipalib/parameters.py b/ipalib/parameters.py index ef440c72..bf6588ba 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -132,6 +132,13 @@ class DefaultFrom(ReadOnly): ) lock(self) + def __repr__(self): + args = (self.callback.__name__,) + tuple(repr(k) for k in self.keys) + return '%s(%s)' % ( + self.__class__.__name__, + ', '.join(args) + ) + def __call__(self, **kw): """ Call the callback if all keys are present. @@ -376,7 +383,12 @@ class Param(ReadOnly): for rule in self.rules: yield rule.__name__ for key in sorted(self.__kw): - yield '%s=%r' % (key, self.__kw[key]) + value = self.__kw[key] + if callable(value) and hasattr(value, '__name__'): + value = value.__name__ + else: + value = repr(value) + yield '%s=%s' % (key, value) def __call__(self, value, **kw): """ @@ -389,6 +401,16 @@ class Param(ReadOnly): self.validate(value) return value + def kw(self): + """ + Iterate through ``(key,value)`` for all kwargs passed to constructor. + """ + for key in sorted(self.__kw): + value = self.__kw[key] + if callable(value) and hasattr(value, '__name__'): + value = value.__name__ + yield (key, value) + def use_in_context(self, env): """ Return ``True`` if this parameter should be used in ``env.context``. @@ -770,6 +792,27 @@ class Bool(Param): type = bool type_error = _('must be True or False') + # FIXME: This my quick hack to get some UI stuff working, change these defaults + # --jderose 2009-08-28 + kwargs = Param.kwargs + ( + ('truths', frozenset, frozenset([1, u'1', u'True'])), + ('falsehoods', frozenset, frozenset([0, u'0', u'False'])), + ) + + def _convert_scalar(self, value, index=None): + """ + Convert a single scalar value. + """ + if type(value) is self.type: + return value + if value in self.truths: + return True + if value in self.falsehoods: + return False + raise ConversionError(name=self.name, index=index, + error=ugettext(self.type_error), + ) + class Flag(Bool): """ @@ -1220,7 +1263,7 @@ class GeneralizedTime(Str): mm = int(t[2:4]) if mm < 0 or mm > 59: raise ValueError('MM out of range') - + def _check_dotw(self, t): if t.isnumeric(): value = int(t) @@ -1266,7 +1309,7 @@ class GeneralizedTime(Str): raise ValueError('month number non-numeric') value = int(t) if value < 1 or value > 12: - raise ValueError('month number out of range') + raise ValueError('month number out of range') def _check_interval(self, t, check_func): intervals = t.split(',') @@ -1364,7 +1407,7 @@ class GeneralizedTime(Str): raise ValidationError( name=self.cli_name, errors='incomplete time value' ) - return None + return None def create_param(spec): diff --git a/ipalib/plugable.py b/ipalib/plugable.py index d94ff752..dceb41f0 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -524,7 +524,7 @@ class API(DictProxy): if context is not None: overrides['context'] = context self.bootstrap(**overrides) - return args + return (options, args) def load_plugins(self): """ diff --git a/ipalib/plugins/kerberos.py b/ipalib/plugins/kerberos.py index 5c048719..babedd81 100644 --- a/ipalib/plugins/kerberos.py +++ b/ipalib/plugins/kerberos.py @@ -28,12 +28,7 @@ from ipalib import api from ipalib.backend import Backend import krbV - -# FIXME: Is it safe to assume the Kerberos library is using UTF-8 for the -# principal and realm? If not, how do we query the Kerberos library to find -# the encoding it's using? ENCODING = 'UTF-8' -FS_ENCODING = (sys.getfilesystemencoding() or sys.getdefaultencoding()) class krb(Backend): @@ -61,7 +56,7 @@ class krb(Backend): """ Return the ``krbV.CCache`` for the ``ccname`` credential ccache. """ - return krbV.CCache(ccname.encode(FS_ENCODING)) + return krbV.CCache(ccname) def __get_principal(self, ccname): """ @@ -78,7 +73,7 @@ class krb(Backend): This cannot return anything meaningful if used in the server as a request is processed. """ - return self.__default_ccache().name.decode(FS_ENCODING) + return self.__default_ccache().name def default_principal(self): """ diff --git a/ipalib/plugins/misc.py b/ipalib/plugins/misc.py index 2dcc6554..8bf9d81f 100644 --- a/ipalib/plugins/misc.py +++ b/ipalib/plugins/misc.py @@ -45,20 +45,21 @@ class env(LocalOrRemote): keys.add(key) elif query in self.env: keys.add(query) - return sorted(keys) + return keys def execute(self, variables, **options): if variables is None: keys = self.env else: keys = self.__find_keys(variables) - return tuple( + return dict( (key, self.env[key]) for key in keys ) def output_for_cli(self, textui, result, variables, **options): if len(result) == 0: return + result = tuple((k, result[k]) for k in sorted(result)) if len(result) == 1: textui.print_keyval(result) return diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index 256ff9ca..64353130 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -70,15 +70,15 @@ class user(LDAPObject): takes_params = ( Str('givenname', cli_name='first', - doc='first name', + doc='First name', ), Str('sn', cli_name='last', - doc='last name', + doc='Last name', ), Str('uid', cli_name='user', - doc='login name', + doc='Login name', primary_key=True, default_from=lambda givenname, sn: givenname[0] + sn, normalizer=lambda value: value.lower(), @@ -90,7 +90,7 @@ class user(LDAPObject): ), Str('homedirectory?', cli_name='homedir', - doc='home directory', + doc='Home directory', default_from=lambda uid: '/home/%s' % uid, ), Str('loginshell?', @@ -251,4 +251,3 @@ class user_unlock(LDAPQuery): textui.print_dashed('Unlocked user "%s".' % keys[-1]) api.register(user_unlock) - -- cgit