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: object

Represents 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. If True return the whole list of values.
class flask_open_directory.model.model.BaseModel(**kwargs)[source]

Bases: flask_open_directory.model.model_abc.ModelABC

Implementation 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 Attribute for the given key, which can be the python attribute or the ldap entry key.

Returns None if not found

Return type:Optional[Attribute]
classmethod ldap_attribute_map()[source]

Returns the mapping between python attributes and ldap entry keys.

The python attribute name is the key and ldap entry key is the value in the mapping.

Return type:Dict[str, str]
ldap_values

Stores the actual values for the Attribute. These are the values returned when accessing an Attribute instance set on a Model.

Return type:Dict[str, Iterable[str]]

flask_open_directory.model.model_abc module

class flask_open_directory.model.model_abc.ModelABC[source]

Bases: object

An 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 super mechanism.

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, key for the value in the mapping, or None if not found.

You can use the default implementation from the super mechanism 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.Entry

The default implementation requires that a subclass accepts kwargs for all attributes in it’s __init__ method.

Parameters:entry (Entry) – An ldap3.Entry to 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 values from the ldap_attribute_map().

You can use the default implementation from the super mechanism 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_dn as ‘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 super mechanism 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

Module contents

class flask_open_directory.model.ModelABC[source]

Bases: object

An 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 super mechanism.

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, key for the value in the mapping, or None if not found.

You can use the default implementation from the super mechanism 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.Entry

The default implementation requires that a subclass accepts kwargs for all attributes in it’s __init__ method.

Parameters:entry (Entry) – An ldap3.Entry to 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 values from the ldap_attribute_map().

You can use the default implementation from the super mechanism 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_dn as ‘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 super mechanism 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
class flask_open_directory.model.BaseModel(**kwargs)[source]

Bases: flask_open_directory.model.model_abc.ModelABC

Implementation 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 Attribute for the given key, which can be the python attribute or the ldap entry key.

Returns None if not found

Return type:Optional[Attribute]
classmethod ldap_attribute_map()[source]

Returns the mapping between python attributes and ldap entry keys.

The python attribute name is the key and ldap entry key is the value in the mapping.

Return type:Dict[str, str]
ldap_values

Stores the actual values for the Attribute. These are the values returned when accessing an Attribute instance set on a Model.

Return type:Dict[str, Iterable[str]]
class flask_open_directory.model.Attribute(ldap_key, allow_multiple=False)[source]

Bases: object

Represents 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. If True return the whole list of values.
class flask_open_directory.model.User(**kwargs)[source]

Bases: flask_open_directory.model.model.BaseModel

Represents a user in the open directory

See also

BaseModel for 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.BaseModel

Represents a group in the open directory

See also

BaseModel for 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