Add docs and clarify

This commit is contained in:
sfigato 2020-11-27 19:41:09 +01:00
parent ac0ab02d6e
commit 95bc52ebd8
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

View File

@ -124,6 +124,13 @@ class Entry(object):
class OrganizationalUnit(object): class OrganizationalUnit(object):
"""
Mixin that represents an OrganizationalUnit. It provides the methods to interact
with the LDAP db _and_ to supervise its `Member`s.
To properly use it, one must specify the `ou` and `child_class` class attributes
when inheriting.
"""
object_class = ["organizationalUnit", "top"] object_class = ["organizationalUnit", "top"]
def __init__(self, client, **kwargs): def __init__(self, client, **kwargs):
@ -190,7 +197,17 @@ class OrganizationalUnit(object):
raise PhiCannotExecute("Cannot delete an OU and delete_cascade is not set") raise PhiCannotExecute("Cannot delete an OU and delete_cascade is not set")
def hydrate(obj, data): def _hydrate(obj, data):
"""
Iterate over the structure of the given `data`. Using the key name, filtering
only on the values that the given `obj` accepts (`obj.ldap_attributes`),
appropriately set the corresponding value in the given `obj`. In particular:
- append to lists
- handle password setting
- set scalars
This is called `_hydrate` because its aim is to fill a structure (the `obj`)
with substance.
"""
for k, v in data.items(): for k, v in data.items():
if k in obj.ldap_attributes: if k in obj.ldap_attributes:
if isinstance(v, list) and not isinstance(v, LDAPValueList): if isinstance(v, list) and not isinstance(v, LDAPValueList):
@ -204,13 +221,20 @@ def hydrate(obj, data):
class Member(object): class Member(object):
"""
Mixin that represents a generic member of an `OrganizationalUnit`.
It provides the methods to interact with the LDAP db.
To properly use, `ou`, `object_class` and `ldap_attributes` class attributes must
be specified when inheriting.
"""
def __init__(self, client, name, **kwargs): def __init__(self, client, name, **kwargs):
self.client = client self.client = client
self.base_dn = client.base_dn self.base_dn = client.base_dn
self.name = name self.name = name
self._entry = LDAPEntry(self.dn) self._entry = LDAPEntry(self.dn)
if kwargs: if kwargs:
hydrate(self, kwargs) _hydrate(self, kwargs)
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, type(self)): if isinstance(other, type(self)):
@ -254,5 +278,5 @@ class Member(object):
async def sync(self): async def sync(self):
res = await self._get() res = await self._get()
hydrate(self, res) _hydrate(self, res)
return self return self