Skip to content

Commit

Permalink
Add exists property to LDAPStorage.
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixx committed Dec 13, 2017
1 parent d336659 commit 709ece0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ History
1.0b7 (unreleased)
------------------

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

- Add ``objectSid`` and ``objectGUID`` from Active Directory schema to
``properties.BINARY_DEFAULTS``.
[rnix]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
License
=======

Copyright (c) 2006-2016, BlueDynamics Alliance, Austria, Germany, Switzerland
Copyright (c) 2006-2017, BlueDynamics Alliance, Austria, Germany, Switzerland
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ Every LDAP node has a DN and a RDN:
>>> root.rdn_attr
u'ou'
Check whether created node exists in the database::

.. code-block:: pycon
>>> root.exists
True
Directory entry has no children yet:

.. code-block:: pycon
Expand Down
16 changes: 16 additions & 0 deletions src/node/ext/ldap/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ def child_dn(self, key):
return u','.join([decode(key), decode(self._dn)])
return u','.join([decode(key), decode(self.name)])

@default
@property
def exists(self):
try:
res = self.ldap_session.search(
scope=BASE,
baseDN=self.DN.encode('utf-8'),
attrlist=['']
)
# this probably never happens
if len(res) != 1:
raise RuntimeError()
return True
except NO_SUCH_OBJECT:
return False

@default
def node_by_dn(self, dn, strict=False):
"""Return node from tree by DN.
Expand Down
9 changes: 9 additions & 0 deletions src/node/ext/ldap/_node.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ The non-unicode name got decoded::
>>> root.rdn_attr
u'dc'

Check exists::

>>> root.exists
True

>>> inexistent = LDAPNode('dc=other-domain,dc=com', props)
>>> inexistent.exists
False

LDAP attributes for DN are stored on ``attrs``::

>>> root.attrs
Expand Down

0 comments on commit 709ece0

Please sign in to comment.