udm_rest_client package¶
Submodules¶
udm_rest_client.base module¶
Base classes for (simplified) UDM modules and objects.
- class udm_rest_client.base.BaseModule(name: str, connection: Any, api_version: int)¶
Bases:
object
Base class for UDM module classes. UDM modules are basically UDM object factories.
Usage:
Get module using:
user_mod = UDM().get('users/user')
Create fresh, not yet saved BaseObject:
new_user = user_mod.new()
Load an existing object:
group = group_mod.get('cn=test,cn=groups,dc=example,dc=com') group = group_mod.get_by_id('Domain Users')
Search and load existing objects:
dc_slaves = dc_slave_mod.search(filter_s='cn=s10*') campus_groups = group_mod.search(base='ou=campus,dc=example,dc=com')
Load existing object(s) without
open()
‘ing them:user_mod.meta.auto_open = False user = user_mod.get(dn) user.props.groups == []
- get(dn: str) BaseObject ¶
Load UDM object from LDAP.
- Parameters:
dn (str) – DN of the object to load.
- Returns:
an existing
BaseObject
instance.- Return type:
- Raises:
univention.udm.exceptions.NoObject – if no object is found at dn
univention.udm.exceptions.WrongObjectType – if the object found at dn is not of type
self.name
- meta = BaseModuleMetadata(supported_api_versions=(), suitable_for=[], used_api_version=None)¶
- new(superordinate: Optional[Union[str, BaseObject]] = None) BaseObject ¶
Create a new, unsaved
BaseObject
object.- Parameters:
superordinate (str or GenericObject) – DN or UDM object this one references as its superordinate (required by some modules)
- Returns:
a new, unsaved BaseObject object
- Return type:
- search(filter_s: str = '', base: str = '', scope: str = 'sub') Iterator[BaseObject] ¶
Get all UDM objects from LDAP that match the given filter.
- Parameters:
filter_s (str) – LDAP filter (only object selector like uid=foo required, objectClasses will be set by the UDM module)
base (str) – LDAP search base.
scope (str) – LDAP search scope, e.g. base or sub or one.
- Returns:
iterator of
BaseObject
objects- Return type:
Iterator(BaseObject)
- class udm_rest_client.base.BaseModuleMeta(name, bases, attrs)¶
Bases:
type
This is not a subclass of
univention.udm.plugins.Plugin
, like in the originalunivention.udm.base.ModuleMeta
, because we don’t need to load module specific code in the client.- udm_meta_class¶
alias of
BaseModuleMetadata
- class udm_rest_client.base.BaseModuleMetadata(meta: BaseModule.Meta)¶
Bases:
object
Base class for UDM module meta data.
- auto_open = True¶
- auto_reload = True¶
- property identifying_property: str¶
UDM property of which the mapped LDAP attribute is used as first component in a DN, e.g. username (LDAP attribute uid) or name (LDAP attribute cn).
- instance(udm_module: BaseModule, api_version: int) BaseModuleMetadata ¶
- lookup_filter(filter_s: Optional[str] = None) str ¶
Filter the UDM module uses to find its corresponding LDAP objects.
This can be used in two ways:
get the filter to find all objects:
myfilter_s = obj.meta.lookup_filter()
get the filter to find a subset of the corresponding LDAP objects (filter_s will be combined with & to the filter for all objects):
`myfilter = obj.meta.lookup_filter('(|(givenName=A*)(givenName=B*))')`
- Parameters:
filter_s (str) – optional LDAP filter expression
- Returns:
an LDAP filter string
- Return type:
str
- property mapping: LdapMapping¶
UDM properties to LDAP attributes mapping and vice versa.
- Returns:
a namedtuple containing two mappings: a) from UDM property to LDAP attribute and b) from LDAP attribute to UDM property
- Return type:
- class udm_rest_client.base.BaseObject¶
Bases:
object
Base class for UDM object classes.
Usage:
Creation of instances is always done through
BaseModule.new()
,BaseModule.get()
orBaseModule.search()
.Modify an object:
user.props.firstname = 'Peter' user.props.lastname = 'Pan' user.save()
Move an object:
user.position = 'cn=users,ou=Company,dc=example,dc=com' user.save()
Delete an object:
obj.delete()
After saving a
BaseObject
, it isreload()
‘ed automatically because UDM hooks and listener modules often add, modify or remove properties when saving to LDAP. As this involves LDAP, it can be disabled if the object is not used afterwards and performance is an issue:user_mod.meta.auto_reload = False
- delete() None ¶
Remove the object from the LDAP database.
- Returns:
None
- reload() BaseObject ¶
Refresh object from LDAP.
- Returns:
self
- Return type:
- save() BaseObject ¶
Save object to LDAP.
- Returns:
self
- Return type:
- Raises:
univention.udm.exceptions.MoveError – when a move operation fails
- udm_prop_class¶
alias of
BaseObjectProperties
- class udm_rest_client.base.BaseObjectProperties(udm_obj: BaseObject)¶
Bases:
Mapping
,Iterable
Container for UDM properties.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- update(other: Optional[BaseObjectProperties] = None, **kwargs) None ¶
- values() an object providing a view on D's values ¶
udm_rest_client.base_http module¶
Base classes for (simplified) UDM modules and objects using the UDM REST API (instead of the low level Python UDM API).
- exception udm_rest_client.base_http.BadSettingsWarning[source]¶
Bases:
UdmRestClientWarning
- class udm_rest_client.base_http.DnPropertyEncoder(property_name: str, dn: str, session: Session, udm_module_name: Optional[str] = None)[source]¶
Bases:
object
Given a DN, return a string object with the DN and an additional member
obj
.obj
is a property that, when accessed, will return the UDM object the DN refers to. The property has to be await ‘ed.
- exception udm_rest_client.base_http.InsecureRequestWarning[source]¶
Bases:
UdmRestClientWarning
- class udm_rest_client.base_http.Session(username: str, password: str, url: str, max_client_tasks: int = 10, request_id: Optional[str] = None, request_id_header: str = 'X-Request-ID', language: Optional[str] = None, **kwargs)[source]¶
Bases:
object
- async call_openapi(udm_module_name: str, operation: str, dn: Optional[str] = None, api_model_obj: Optional[Union[ApiModel, Dict[str, Any]]] = None, language: Optional[str] = None, **kwargs) Tuple[Union[ApiModel, List[ApiModel]], int, Dict[str, str]] [source]¶
- async make_request(method: str, url: str, language: Optional[str] = None, **kwargs) Dict[str, Any] [source]¶
- property session: ClientSession¶
- exception udm_rest_client.base_http.StaleObjectWarning[source]¶
Bases:
UdmRestClientWarning
- class udm_rest_client.base_http.UdmModule(name: str, session: Session)[source]¶
Bases:
BaseModule
Base class for UDM_HTTP module classes. UDM modules are basically UDM object factories.
Usage:
Get module using:
user_mod = UDM().get('users/user')
1 Create fresh, not yet saved UdmObject:
new_user = user_mod.new()
2 Load an existing object:
group = group_mod.get('cn=test,cn=groups,dc=example,dc=com') group = group_mod.get_by_id('Domain Users')
3 Search and load existing objects:
dc_slaves = dc_slave_mod.search(filter_s='cn=s10*') campus_groups = group_mod.search(base='ou=campus,dc=example,dc=com')
Load existing object(s) without open() ‘ing them:
user_mod.meta.auto_open = False user = user_mod.get(dn) user.props.groups == []
- async get(dn: str, language: Optional[str] = None) UdmObject [source]¶
Load UDM object from LDAP.
- Parameters:
dn (str) – DN of the object to load
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
an existing
udm_rest_client.BaseHttpObject
object- Return type:
- Raises:
udm_rest_client.NoObject – if no object is found at dn
udm_rest_client.WrongObjectType – if the object found at dn is not of type
self.name
- meta = UdmModuleMetadata(supported_api_versions=[0, 1, 2], suitable_for=['*/*'], used_api_version=None)¶
- async new(superordinate: Optional[str] = None, language: Optional[str] = None) UdmObject [source]¶
Create a new, unsaved BaseHttpObject object.
- Parameters:
superordinate (str or GenericObject) – DN or UDM object this one references as its superordinate (required by some modules)
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
a new, unsaved
udm_rest_client.UdmObject
object- Return type:
- async search(filter_s: str = '', base: str = '', scope: str = 'sub', language: Optional[str] = None) AsyncIterator[UdmObject] [source]¶
Get all UDM objects from LDAP that match the given filter.
- Parameters:
filter_s (str) – LDAP filter (only object selector like uid=foo required, objectClasses will be set by the UDM module)
base (str) – base dn for search
scope (str) – one of base, one, sub or children
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
iterator of
UdmObject
objects- Return type:
Iterator(udm_rest_client.UdmObject)
- class udm_rest_client.base_http.UdmModuleMeta(name, bases, attrs)[source]¶
Bases:
BaseModuleMeta
- udm_meta_class¶
alias of
UdmModuleMetadata
- class udm_rest_client.base_http.UdmModuleMetadata(meta: BaseModule.Meta)[source]¶
Bases:
BaseModuleMetadata
Base class for module meta data. Nothing here in the REST client
- property identifying_property: str¶
UDM Property of which the mapped LDAP attribute is used as first component in a DN, e.g. username (LDAP attribute uid) or name (LDAP attribute cn).
- lookup_filter(filter_s: Optional[str] = None) str [source]¶
Filter the UDM module uses to find its corresponding LDAP objects.
This can be used in two ways:
- get the filter to find all objects:
myfilter_s = obj.meta.lookup_filter()
- get the filter to find a subset of the corresponding LDAP objects
(filter_s will be combined with & to the filter for all objects): myfilter = obj.meta.lookup_filter(‘(|(givenName=A*)(givenName=B*))’)
- Parameters:
filter_s (str) – optional LDAP filter expression
- Returns:
an LDAP filter string
- Return type:
str
- property mapping: LdapMapping¶
UDM properties to LDAP attributes mapping and vice versa.
- Returns:
a namedtuple containing two mappings: a) from UDM property to LDAP attribute and b) from LDAP attribute to UDM property
- Return type:
- class udm_rest_client.base_http.UdmObject[source]¶
Bases:
BaseObject
Base class for UDM_HTTP object classes.
Usage:
Creation of instances
udm_rest_client.UdmObject
is always done through aBaseHttpModul
instances py:meth:new(), py:meth:get() or py:meth:search() methods.Modify an object:
user.props.firstname = 'Peter' user.props.lastname = 'Pan' user.save()
Move an object:
user.position = 'cn=users,ou=Company,dc=example,dc=com' user.save()
Delete an object:
obj.delete()
After saving a
udm_rest_client.UdmObject
, it isreload()
‘ed automatically because UDM hooks and listener modules often add, modify or remove properties when saving to LDAP. As this involves LDAP, it can be disabled if the object is not used afterwards and performance is an issue:user_mod.meta.auto_reload = False
- async delete(language=None) None [source]¶
Remove the object from the LDAP database.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
None
- async reload(language: Optional[str] = None) UdmObject [source]¶
Refresh object from LDAP.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
self
- Return type:
- async save(language: Optional[str] = None) UdmObject [source]¶
Save object to LDAP (via UDM REST API).
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
self
- Return type:
- Raises:
ApiException – when the operation fails
- udm_prop_class¶
alias of
UdmObjectProperties
- class udm_rest_client.base_http.UdmObjectProperties(udm_obj: BaseObject)[source]¶
Bases:
BaseObjectProperties
Container for UDM properties.
udm_rest_client.exceptions module¶
- exception udm_rest_client.exceptions.APICommunicationError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when something goes wrong communicating.
- exception udm_rest_client.exceptions.ConfigurationError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
- exception udm_rest_client.exceptions.CreateError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when an error occurred when creating an object.
- exception udm_rest_client.exceptions.DeletedError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None)[source]¶
Bases:
UdmError
- exception udm_rest_client.exceptions.MethodNotSupportedError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised if the API client does not support a method.
- exception udm_rest_client.exceptions.ModifyError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised if an error occurred when modifying an object.
- exception udm_rest_client.exceptions.MoveError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised if an error occurred when moving an object.
- exception udm_rest_client.exceptions.MultipleObjects(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when more than one UDM object was found when there should be at most one.
- exception udm_rest_client.exceptions.NoObject(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when a UDM object could not be found at a DN.
- exception udm_rest_client.exceptions.NotYetSavedError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when a client tries to delete or reload a UDM object that is not yet saved.
- msg: str = 'Object has not been created/loaded yet.'¶
- exception udm_rest_client.exceptions.UdmError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
Exception
Base class of Exceptions raised by (simplified) UDM modules.
- msg: str = ''¶
udm_rest_client.udm module¶
UDM REST API Client library
Python library to interact with the Univention UDM REST API, implementing the interface of the simple Python UDM API [1].
The API consists of UDM modules and UDM object. UDM modules are factories for UDM objects. UDM objects manipulate LDAP objects on the UCS server.
Usage:
async with UDM("myuser", "s3cr3t", "https://FQ.DN/univention/udm/") as udm:
user_mod = udm.get('users/user')
obj = user_mod.get(dn)
obj.props.firstname = 'foo' # modify property
obj.position = 'cn=users,cn=example,dc=com' # move LDAP object
obj.save() # apply changes and reload object from LDAP
obj = user_mod.get(dn)
obj.delete() # delete object
async for obj in udm.get('users/user').search('uid=a*'):
print(obj.props.firstname, obj.props.lastname)
[1] https://docs.software-univention.de/developer-reference-4.4.html#udm:rest_api
- class udm_rest_client.udm.UDM(username: str, password: str, url: str, max_client_tasks: int = 10, request_id: Optional[str] = None, request_id_header: str = 'X-Request-ID', language: Optional[str] = None, **kwargs)[source]¶
Bases:
object
Factory for creating
udm_rest_client.UdmModule
objects:from udm_rest_client import UDM async def func(): async with UDM("myuser", "s3cr3t", "https://FQ.DN/univention/udm/") as udm: group_mod = udm.get('groups/group') obj = await group_mod.get(dn) # obj is of type udm_rest_client.base_http.UdmObject
HTTP(S) sessions will be closed upon existing the asynchronous context manager. It is recommended to make as many operations as possible in the same session.
- property api_version¶
Here only for backwards compatibility.
- get(name: str) UdmModule [source]¶
Context manager of type
udm_rest_client.UdmModule
to work with UDM objects of type name (e.g. users/user). Exiting the context manager automatically closes theaiohttp.ClientSession
. Usage example:async with udm.get("users/user") as user_mod: user_obj = await user_mod.get($DN)
- Parameters:
name (str) – UDM module name (e.g. users/user)
- Returns:
instance of
udm_rest_client.UdmModule
- Return type:
- async modules_list(language: Optional[str] = None) Sequence[str] [source]¶
Get the list of UDM modules the server knows.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
list of UDM module names
- Return type:
list(str)
- async obj_by_dn(dn: str, language: Optional[str] = None) UdmObject [source]¶
Load a UDM object without knowing the UDM module type.
- Parameters:
dn (str) – DN of the object to load
- Returns:
udm_rest_client.UdmObject
instance- Return type:
- Raises:
univention.udm.exceptions.NoObject – if no object is found at dn
univention.udm.exceptions.ImportError – if the Python module for the specific UDM module type could not be loaded
- set_language(language: str) None [source]¶
Set the language used in the “Accept-Language” header for each request in the current session.
- Parameters:
language (str) – Language used in the “Accept-Language” header
- Returns:
None
- async unknown_modules(language: Optional[str] = None) Sequence[str] [source]¶
Get the list of UDM modules the server knows, but this client doesn’t.
Unknown UDM modules cannot be used with this client library. When the list is non-empty, the package openapi-client-udm must be rebuilt to use them.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
list of UDM modules known by the server but not this client
- Return type:
list(str)
- version(api_version: int) UDM [source]¶
This is not about versions of the UDM REST API. This is here only to provide better drop-in functionality when using this lib instead of the UDM Python API on a UCS system. It is not required to use this method.
- Parameters:
api_version (int) – ignored
- Returns:
self
- Return type:
Module contents¶
Top-level package for Python UDM REST Client.
- exception udm_rest_client.APICommunicationError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when something goes wrong communicating.
- exception udm_rest_client.ConfigurationError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
- exception udm_rest_client.CreateError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when an error occurred when creating an object.
- exception udm_rest_client.DeletedError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None)[source]¶
Bases:
UdmError
- exception udm_rest_client.ModifyError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised if an error occurred when modifying an object.
- exception udm_rest_client.MoveError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised if an error occurred when moving an object.
- exception udm_rest_client.MultipleObjects(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when more than one UDM object was found when there should be at most one.
- exception udm_rest_client.NoObject(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when a UDM object could not be found at a DN.
- exception udm_rest_client.NotYetSavedError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
UdmError
Raised when a client tries to delete or reload a UDM object that is not yet saved.
- msg: str = 'Object has not been created/loaded yet.'¶
- class udm_rest_client.UDM(username: str, password: str, url: str, max_client_tasks: int = 10, request_id: Optional[str] = None, request_id_header: str = 'X-Request-ID', language: Optional[str] = None, **kwargs)[source]¶
Bases:
object
Factory for creating
udm_rest_client.UdmModule
objects:from udm_rest_client import UDM async def func(): async with UDM("myuser", "s3cr3t", "https://FQ.DN/univention/udm/") as udm: group_mod = udm.get('groups/group') obj = await group_mod.get(dn) # obj is of type udm_rest_client.base_http.UdmObject
HTTP(S) sessions will be closed upon existing the asynchronous context manager. It is recommended to make as many operations as possible in the same session.
- property api_version¶
Here only for backwards compatibility.
- get(name: str) UdmModule [source]¶
Context manager of type
udm_rest_client.UdmModule
to work with UDM objects of type name (e.g. users/user). Exiting the context manager automatically closes theaiohttp.ClientSession
. Usage example:async with udm.get("users/user") as user_mod: user_obj = await user_mod.get($DN)
- Parameters:
name (str) – UDM module name (e.g. users/user)
- Returns:
instance of
udm_rest_client.UdmModule
- Return type:
- async modules_list(language: Optional[str] = None) Sequence[str] [source]¶
Get the list of UDM modules the server knows.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
list of UDM module names
- Return type:
list(str)
- async obj_by_dn(dn: str, language: Optional[str] = None) UdmObject [source]¶
Load a UDM object without knowing the UDM module type.
- Parameters:
dn (str) – DN of the object to load
- Returns:
udm_rest_client.UdmObject
instance- Return type:
- Raises:
univention.udm.exceptions.NoObject – if no object is found at dn
univention.udm.exceptions.ImportError – if the Python module for the specific UDM module type could not be loaded
- set_language(language: str) None [source]¶
Set the language used in the “Accept-Language” header for each request in the current session.
- Parameters:
language (str) – Language used in the “Accept-Language” header
- Returns:
None
- async unknown_modules(language: Optional[str] = None) Sequence[str] [source]¶
Get the list of UDM modules the server knows, but this client doesn’t.
Unknown UDM modules cannot be used with this client library. When the list is non-empty, the package openapi-client-udm must be rebuilt to use them.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
list of UDM modules known by the server but not this client
- Return type:
list(str)
- version(api_version: int) UDM [source]¶
This is not about versions of the UDM REST API. This is here only to provide better drop-in functionality when using this lib instead of the UDM Python API on a UCS system. It is not required to use this method.
- Parameters:
api_version (int) – ignored
- Returns:
self
- Return type:
- exception udm_rest_client.UdmError(msg: Optional[str] = None, dn: Optional[str] = None, module_name: Optional[str] = None, error: Optional[dict] = None, status: Optional[int] = None, reason: Optional[str] = None)[source]¶
Bases:
Exception
Base class of Exceptions raised by (simplified) UDM modules.
- msg: str = ''¶
- class udm_rest_client.UdmModule(name: str, session: Session)[source]¶
Bases:
BaseModule
Base class for UDM_HTTP module classes. UDM modules are basically UDM object factories.
Usage:
Get module using:
user_mod = UDM().get('users/user')
1 Create fresh, not yet saved UdmObject:
new_user = user_mod.new()
2 Load an existing object:
group = group_mod.get('cn=test,cn=groups,dc=example,dc=com') group = group_mod.get_by_id('Domain Users')
3 Search and load existing objects:
dc_slaves = dc_slave_mod.search(filter_s='cn=s10*') campus_groups = group_mod.search(base='ou=campus,dc=example,dc=com')
Load existing object(s) without open() ‘ing them:
user_mod.meta.auto_open = False user = user_mod.get(dn) user.props.groups == []
- async get(dn: str, language: Optional[str] = None) UdmObject [source]¶
Load UDM object from LDAP.
- Parameters:
dn (str) – DN of the object to load
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
an existing
udm_rest_client.BaseHttpObject
object- Return type:
- Raises:
udm_rest_client.NoObject – if no object is found at dn
udm_rest_client.WrongObjectType – if the object found at dn is not of type
self.name
- meta = UdmModuleMetadata(supported_api_versions=[0, 1, 2], suitable_for=['*/*'], used_api_version=None)¶
- async new(superordinate: Optional[str] = None, language: Optional[str] = None) UdmObject [source]¶
Create a new, unsaved BaseHttpObject object.
- Parameters:
superordinate (str or GenericObject) – DN or UDM object this one references as its superordinate (required by some modules)
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
a new, unsaved
udm_rest_client.UdmObject
object- Return type:
- async search(filter_s: str = '', base: str = '', scope: str = 'sub', language: Optional[str] = None) AsyncIterator[UdmObject] [source]¶
Get all UDM objects from LDAP that match the given filter.
- Parameters:
filter_s (str) – LDAP filter (only object selector like uid=foo required, objectClasses will be set by the UDM module)
base (str) – base dn for search
scope (str) – one of base, one, sub or children
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
iterator of
UdmObject
objects- Return type:
Iterator(udm_rest_client.UdmObject)
- class udm_rest_client.UdmObject[source]¶
Bases:
BaseObject
Base class for UDM_HTTP object classes.
Usage:
Creation of instances
udm_rest_client.UdmObject
is always done through aBaseHttpModul
instances py:meth:new(), py:meth:get() or py:meth:search() methods.Modify an object:
user.props.firstname = 'Peter' user.props.lastname = 'Pan' user.save()
Move an object:
user.position = 'cn=users,ou=Company,dc=example,dc=com' user.save()
Delete an object:
obj.delete()
After saving a
udm_rest_client.UdmObject
, it isreload()
‘ed automatically because UDM hooks and listener modules often add, modify or remove properties when saving to LDAP. As this involves LDAP, it can be disabled if the object is not used afterwards and performance is an issue:user_mod.meta.auto_reload = False
- async delete(language=None) None [source]¶
Remove the object from the LDAP database.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
None
- async reload(language: Optional[str] = None) UdmObject [source]¶
Refresh object from LDAP.
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
self
- Return type:
- async save(language: Optional[str] = None) UdmObject [source]¶
Save object to LDAP (via UDM REST API).
- Parameters:
language (str) – Language used in the “Accept-Language” header for this request (optional)
- Returns:
self
- Return type:
- Raises:
ApiException – when the operation fails
- udm_prop_class¶
alias of
UdmObjectProperties