diff options
Diffstat (limited to 'ipalib/plugins/baseldap.py')
-rw-r--r-- | ipalib/plugins/baseldap.py | 82 |
1 files changed, 23 insertions, 59 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 4b8699744..2b0ff2d73 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -21,16 +21,14 @@ Base classes for LDAP plugins. """ import re -import json from ipalib import crud, errors, uuid from ipalib import Method, Object -from ipalib import Flag, Int, List, Str +from ipalib import Flag, List, Str from ipalib.base import NameSpace from ipalib.cli import to_cli, from_cli from ipalib import output from ipalib.text import _ -from ipalib.util import json_serialize def validate_add_attribute(ugettext, attr): @@ -48,12 +46,11 @@ def get_attributes(attrs): """ Given a list of values in the form name=value, return a list of name. """ - if not attrs: - return [] attrlist=[] for attr in attrs: m = re.match("\s*(.*?)\s*=\s*(.*?)\s*$", attr) attrlist.append(str(m.group(1)).lower()) + return attrlist @@ -115,6 +112,7 @@ class LDAPObject(Object): entry_attrs.setdefault(new_attr, []).append( ldap_obj.get_primary_key_from_dn(member) ) + del entry_attrs[attr] def handle_not_found(self, *keys): raise errors.NotFound( @@ -123,20 +121,6 @@ class LDAPObject(Object): } ) - json_friendly_attributes = ( - 'parent_object', 'container_dn', 'object_name', 'object_name_plural', - 'object_class', 'object_class_config', 'default_attributes', 'label', - 'hidden_attributes', 'uuid_attribute', 'attribute_members', 'name', - 'takes_params', - ) - def __json__(self): - json_dict = dict( - (a, getattr(self, a)) for a in self.json_friendly_attributes - ) - json_dict['primary_key'] = self.primary_key.name - json_dict['methods'] = [m for m in self.methods] - return json_dict - # Options used by create and update. _attr_options = ( @@ -401,6 +385,7 @@ class LDAPUpdate(LDAPQuery, crud.Update): """ Update an LDAP entry. """ + takes_options = _attr_options def execute(self, *keys, **options): @@ -438,26 +423,26 @@ class LDAPUpdate(LDAPQuery, crud.Update): set. """ if 'addattr' in options: - setset = set(get_attributes(options.get('setattr', []))) - addset = set(get_attributes(options['addattr'])) - difflist = list(addset.difference(setset)) - if difflist: + try: + (dn, old_entry) = ldap.get_entry( + dn, attrs_list, normalize=self.obj.normalize_dn + ) + except errors.ExecutionError, e: try: - (dn, old_entry) = ldap.get_entry( - dn, difflist, normalize=self.obj.normalize_dn + (dn, old_entry) = self._call_exc_callbacks( + keys, options, e, ldap.get_entry, dn, attrs_list, + normalize=self.obj.normalize_dn ) - except errors.ExecutionError, e: - try: - (dn, old_entry) = self._call_exc_callbacks( - keys, options, e, ldap.get_entry, dn, attrs_list, - normalize=self.obj.normalize_dn - ) - except errors.NotFound: - self.obj.handle_not_found(*keys) - for a in old_entry: - if not isinstance(entry_attrs[a], (list, tuple)): - entry_attrs[a] = [entry_attrs[a]] - entry_attrs[a] += old_entry[a] + except errors.NotFound: + self.obj.handle_not_found(*keys) + attrlist = get_attributes(options['addattr']) + for attr in attrlist: + if attr in old_entry: + if type(entry_attrs[attr]) in (tuple,list): + entry_attrs[attr] = old_entry[attr] + entry_attrs[attr] + else: + old_entry[attr].append(entry_attrs[attr]) + entry_attrs[attr] = old_entry[attr] try: ldap.update_entry(dn, entry_attrs, normalize=self.obj.normalize_dn) @@ -809,25 +794,6 @@ class LDAPSearch(CallbackInterface, crud.Search): """ Retrieve all LDAP entries matching the given criteria. """ - takes_options = ( - Int('timelimit', - label=_('Time Limit'), - doc=_('Time limit of search in seconds (default 1)'), - flags=['no_dispaly'], - minvalue=0, - default=1, - autofill=True, - ), - Int('sizelimit', - label=_('Size Limit'), - doc=_('Maximum number of entries returned (default 3000)'), - flags=['no_dispaly'], - minvalue=0, - default=3000, - autofill=True, - ), - ) - def get_args(self): for key in self.obj.get_ancestor_primary_keys(): yield key @@ -891,9 +857,7 @@ class LDAPSearch(CallbackInterface, crud.Search): try: (entries, truncated) = ldap.find_entries( - filter, attrs_list, base_dn, scope=ldap.SCOPE_ONELEVEL, - time_limit=options.get('timelimit', 1), - size_limit=options.get('sizelimit', 3000) + filter, attrs_list, base_dn, scope=ldap.SCOPE_ONELEVEL ) except errors.ExecutionError, e: try: |