flask_open_directory.model package¶
Submodules¶
flask_open_directory.model.model module¶
-
class
flask_open_directory.model.model.Attribute(ldap_key, allow_multiple=False)[source]¶ Bases:
objectRepresents an LDAP entry attribute. It maps the ldap entry key to an attribute on a Model.
Parameters: - ldap_key – The ldap entry key for the attribute.
- allow_multiple – If
False(default) then any lists only return the first item. IfTruereturn the whole list of values.
-
class
flask_open_directory.model.model.BaseModel(**kwargs)[source]¶ Bases:
flask_open_directory.model.model_abc.ModelABCImplementation of
ModelABC. Used to map ldap entry keys to python attributes.Parameters: kwargs – Values to set for the attributes of an instance. These can be passed in with the python attribute name as the key or the ldap entry name as the key and the values will be stored and accessible appropriately.
Example: >>> class User(BaseModel): ... id = Attribute('apple-generateduid') >>> user = User(id='123') >>> user.id == '123' True >>> user2 = User(**{'apple-generateduid': '456'}) >>> user2.id == '456' True
-
classmethod
attribute_for_key(key)[source]¶ Return
Attributefor the given key, which can be the python attribute or the ldap entry key.Returns
Noneif not foundReturn type: Optional[Attribute]
-
classmethod
flask_open_directory.model.model_abc module¶
-
class
flask_open_directory.model.model_abc.ModelABC[source]¶ Bases:
objectAn abstract class with some default implementations for a model, which maps the
OpenDirectory (ldap attributes)to a python object.Any of the methods that have a default implementation can be accessed on a derived subclass via the
supermechanism.-
classmethod
attribute_name_for(ldap_key)[source]¶ Retrieve the python model object’s attribute name for a given ldap entry key.
This default implementation checks the
ldap_attribute_map(), returning,keyfor thevaluein the mapping, orNoneif not found.You can use the default implementation from the
supermechanism in your subclass.Parameters: ldap_key ( str) – The ldap entry key.Return type: Union[None,str]
-
classmethod
from_entry(entry)[source]¶ Return an instance of the class from an
ldap3.EntryThe default implementation requires that a subclass accepts
kwargsfor all attributes in it’s__init__method.Parameters: entry ( Entry) – Anldap3.Entryto convert to this python model.Return type: An instance of the python model.
-
classmethod
ldap_attribute_map()[source]¶ Return a mapping of <model attribute: ldap key> values.
This does not have a default implementation, and must be implemented on the subclass.
Return type: Dict[str,str]
-
classmethod
ldap_keys()[source]¶ Return all the ldap keys
This default implementation returns the
valuesfrom theldap_attribute_map().You can use the default implementation from the
supermechanism in your subclass.Return type: Tuple[str]
-
classmethod
query_cn()[source]¶ Return the query cn to be used in queries. This value will get added to the
base_dnas ‘cn=<this value>,<base_dn>’ for queries.The default implementation returns the lower case version of the class name and appends an ‘s’.
You can use the default implementation from the
supermechanism in your subclass.Example:
# given a base dn of 'dc=example,dc=com' >>> class User(ModelABC): pass >>> open_directory = OpenDirectory() >>> query = Query(open_directory=open_directory, model=User) >>> query.search_base 'cn=users,dc=example,dc=com'
Return type: str
-
classmethod
Module contents¶
-
class
flask_open_directory.model.ModelABC[source]¶ Bases:
objectAn abstract class with some default implementations for a model, which maps the
OpenDirectory (ldap attributes)to a python object.Any of the methods that have a default implementation can be accessed on a derived subclass via the
supermechanism.-
classmethod
attribute_name_for(ldap_key)[source]¶ Retrieve the python model object’s attribute name for a given ldap entry key.
This default implementation checks the
ldap_attribute_map(), returning,keyfor thevaluein the mapping, orNoneif not found.You can use the default implementation from the
supermechanism in your subclass.Parameters: ldap_key ( str) – The ldap entry key.Return type: Union[None,str]
-
classmethod
from_entry(entry)[source]¶ Return an instance of the class from an
ldap3.EntryThe default implementation requires that a subclass accepts
kwargsfor all attributes in it’s__init__method.Parameters: entry ( Entry) – Anldap3.Entryto convert to this python model.Return type: An instance of the python model.
-
classmethod
ldap_attribute_map()[source]¶ Return a mapping of <model attribute: ldap key> values.
This does not have a default implementation, and must be implemented on the subclass.
Return type: Dict[str,str]
-
classmethod
ldap_keys()[source]¶ Return all the ldap keys
This default implementation returns the
valuesfrom theldap_attribute_map().You can use the default implementation from the
supermechanism in your subclass.Return type: Tuple[str]
-
classmethod
query_cn()[source]¶ Return the query cn to be used in queries. This value will get added to the
base_dnas ‘cn=<this value>,<base_dn>’ for queries.The default implementation returns the lower case version of the class name and appends an ‘s’.
You can use the default implementation from the
supermechanism in your subclass.Example:
# given a base dn of 'dc=example,dc=com' >>> class User(ModelABC): pass >>> open_directory = OpenDirectory() >>> query = Query(open_directory=open_directory, model=User) >>> query.search_base 'cn=users,dc=example,dc=com'
Return type: str
-
classmethod
-
class
flask_open_directory.model.BaseModel(**kwargs)[source]¶ Bases:
flask_open_directory.model.model_abc.ModelABCImplementation of
ModelABC. Used to map ldap entry keys to python attributes.Parameters: kwargs – Values to set for the attributes of an instance. These can be passed in with the python attribute name as the key or the ldap entry name as the key and the values will be stored and accessible appropriately.
Example: >>> class User(BaseModel): ... id = Attribute('apple-generateduid') >>> user = User(id='123') >>> user.id == '123' True >>> user2 = User(**{'apple-generateduid': '456'}) >>> user2.id == '456' True
-
classmethod
attribute_for_key(key)[source]¶ Return
Attributefor the given key, which can be the python attribute or the ldap entry key.Returns
Noneif not foundReturn type: Optional[Attribute]
-
classmethod
-
class
flask_open_directory.model.Attribute(ldap_key, allow_multiple=False)[source]¶ Bases:
objectRepresents an LDAP entry attribute. It maps the ldap entry key to an attribute on a Model.
Parameters: - ldap_key – The ldap entry key for the attribute.
- allow_multiple – If
False(default) then any lists only return the first item. IfTruereturn the whole list of values.
-
class
flask_open_directory.model.User(**kwargs)[source]¶ Bases:
flask_open_directory.model.model.BaseModelRepresents a user in the open directory
See also
BaseModelfor inherited methods.-
email= Attribute('mail', allow_multiple=True)¶ The email address(s) (mail) for a user.
-
full_name= Attribute('cn', allow_multiple=False)¶ The full name (cn) for the user
-
id= Attribute('apple-generateduid', allow_multiple=False)¶ The id (apple-generateduid) for a user.
-
username= Attribute('uid', allow_multiple=False)¶ The username (uid/short-name) for a user
-
-
class
flask_open_directory.model.Group(**kwargs)[source]¶ Bases:
flask_open_directory.model.model.BaseModelRepresents a group in the open directory
See also
BaseModelfor inherited methods.-
full_name= Attribute('apple-group-realname', allow_multiple=False)¶ The group full name (apple-group-realname) for the group
-
group_name= Attribute('cn', allow_multiple=False)¶ The group name (cn) for the group
-
has_user(user)[source]¶ Check if a user is part of the group.
Parameters: user ( str) – Either the username (uid) or id (apple-generateduid) of a user.Return type: bool
-
id= Attribute('apple-generateduid', allow_multiple=False)¶ The id (apple-generateduid) for the group
-
member_ids= Attribute('apple-group-memberguid', allow_multiple=True)¶ The user(s) id’s (apple-group-memberguid) of the group
-
users= Attribute('memberUid', allow_multiple=True)¶ The usernames (memberUid) that are members of the group
-