-
Couldn't load subscription status.
- Fork 99
project_openldap: improve utils #825
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
base: main
Are you sure you want to change the base?
project_openldap: improve utils #825
Conversation
590d774 to
94bfee0
Compare
|
26311da to
33a69a2
Compare
|
This looks good Please can you also make the read connection read-only Current Generic - note |
7fdf9c4 to
37d8c52
Compare
37d8c52 to
5ddc6cd
Compare
| if len(conn.entries) == 0: | ||
| raise KeyError(dn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we can tell the difference between an empty group and a nonexistent group. One should throw KeyError, the other shouldn't. @ds-04 thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can search for attributes cn and memberuid, assert nonzero entry count, then return just memberuid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a decent way to check existence, but it requires another call:
In [38]: conn.search("cn=simonleary_umass_edu,ou=users,dc=unity,dc=rc,dc=umass,dc=edu", "(objectClass=*)", attributes=[], search_scope=BASE)
Out[38]: True
In [39]: conn.entries
Out[39]: [DN: cn=simonleary_umass_edu,ou=users,dc=unity,dc=rc,dc=umass,dc=edu - STATUS: Read - READ TIME: 2025-10-22T18:07:39.303686]
In [40]: conn.search("cn=foobar,ou=users,dc=unity,dc=rc,dc=umass,dc=edu", "(objectClass=*)", attributes=[], search_scope=BASE)
Out[40]: False
In [41]: conn.entries
Out[41]: []
Signed-off-by: Simon Leary <simon.leary42@proton.me>
5ddc6cd to
64779be
Compare
Changes
problems solved:
connection.resultconnection.result["result"]holds lots of possible failure codesldapsearch_*utils mask errors and returnNone, and there are no extra checks forNoneTypeErrorwhen thatNonemakes its way into future logicldap3from ensuring predictable results:also:
read_onlyoption when binding for read-only purposes (per @ds-04's suggestion)Thoughts
Because the error handling is stricter, it's possible that a site has existing problems which aren't being reported, which will now be reported. The "reading" functions (
ldapsearch_*) now raise exceptions where they used to returnNone, and they now raise excceptions (KeyErrororLDAPException) where they used to return empty results. I was unable to find a definitive answer on whether or not uncaught exceptions are allowed: please advise.Future work