Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signature of node.ext.ldap.ugm.LDAPPrincipals.search accordin… #36

Merged
merged 3 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ History
1.0b7 (unreleased)
------------------

- Fix signature of ``node.ext.ldap.ugm.LDAPPrincipals.search`` according to
``node.ext.ugm.interfaces.IPrincipals.search``. The implementation exposed
LDAP related arguments and has been renamed to ``raw_search``.
[rnix]

- Add ``exists`` property to ``LDAPStorage``.
[rnix]

Expand Down
29 changes: 26 additions & 3 deletions src/node/ext/ldap/ugm/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ def _unalias_dict(self, dct):
return unaliased_dct

@default
def search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False, or_keys=None,
or_values=None, page_size=None, cookie=None):
def raw_search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False, or_keys=None,
or_values=None, page_size=None, cookie=None):
search_attrlist = [self._key_attr]
if attrlist is not None and self._key_attr not in attrlist:
search_attrlist += attrlist
Expand Down Expand Up @@ -624,6 +624,29 @@ def search(self, criteria=None, attrlist=None,
return results, cookie
return results

@default
def search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False):
result = []
cookie = None
while True:
try:
chunk, cookie = self.raw_search(
criteria=criteria,
attrlist=attrlist,
exact_match=exact_match,
or_search=or_search,
page_size=self.context.ldap_session._props.page_size,
cookie=cookie
)
except ValueError as e:
logger.error(str(e))
return ret
result += chunk
if not cookie:
break
return result

@default
@locktree
def create(self, pid, **kw):
Expand Down
7 changes: 4 additions & 3 deletions src/node/ext/ldap/ugm/principals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ Search for users::
>>> users.search(criteria=dict(sn=schmidt.attrs['sn']), attrlist=['login'])
[(u'Schmidt', {'login': [u'user3']})]

Paginated search for users::
By default, search function is paginated. To control the LDAP search behavior
in more detail, ``raw_search`` can be used::

>>> results, cookie = users.search(page_size=3, cookie='')
>>> results, cookie = users.raw_search(page_size=3, cookie='')
>>> results
[u'Meier', u'M\xfcller', u'Schmidt']

>>> results, cookie = users.search(page_size=3, cookie=cookie)
>>> results, cookie = users.raw_search(page_size=3, cookie=cookie)
>>> results
[u'Umhauer']
>>> assert cookie == ''
Expand Down