2014-12-27 22:44:27 +01:00
|
|
|
"""
|
2015-01-19 21:44:57 +01:00
|
|
|
This module defines task stubs for the tasks implemented in the gvaldap Celery
|
|
|
|
worker.
|
2014-12-27 22:44:27 +01:00
|
|
|
|
|
|
|
"""
|
2014-05-25 23:35:14 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2014-05-30 18:39:51 +02:00
|
|
|
def create_ldap_group(groupname, gid, descr):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
|
|
|
This task creates an :py:class:`LDAP group <ldapentities.models.LdapGroup>`
|
|
|
|
if it does not exist yet.
|
|
|
|
|
|
|
|
If a group with the given name exists its group id and description
|
|
|
|
attributes are updated.
|
|
|
|
|
|
|
|
:param str groupname: the group name
|
|
|
|
:param int gid: the group id
|
|
|
|
:param str descr: description text for the group
|
|
|
|
:return: the distinguished name of the group
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2014-05-25 23:35:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2014-05-30 18:39:51 +02:00
|
|
|
def create_ldap_user(username, uid, gid, gecos, homedir, shell, password):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
|
|
|
This task creates an :py:class:`LDAP user <ldapentities.models.LdapUser>`
|
|
|
|
if it does not exist yet.
|
|
|
|
|
|
|
|
The task is rejected if the primary group of the user is not defined.
|
|
|
|
|
|
|
|
The user's fields are updated if the user already exists.
|
|
|
|
|
|
|
|
:param str username: the user name
|
|
|
|
:param int uid: the user id
|
|
|
|
:param int gid: the user's primary group's id
|
|
|
|
:param str gecos: the text for the GECOS field
|
|
|
|
:param str homedir: the user's home directory
|
|
|
|
:param str shell: the user's login shell
|
|
|
|
:param str or None password: the clear text password, if :py:const:`None`
|
|
|
|
is passed the password is not touched
|
|
|
|
:raises celery.exceptions.Reject: if the specified primary group does not
|
|
|
|
exist
|
|
|
|
:return: the distinguished name of the user
|
|
|
|
:rtype: str
|
|
|
|
|
|
|
|
"""
|
2014-05-30 17:10:22 +02:00
|
|
|
|
|
|
|
|
2015-01-19 22:43:29 +01:00
|
|
|
@shared_task
|
2015-01-31 23:55:53 +01:00
|
|
|
def set_ldap_user_password(username, password):
|
2015-01-19 22:43:29 +01:00
|
|
|
"""
|
|
|
|
This task sets the password of an existing :py:class:`LDAP user
|
|
|
|
<ldapentities.models.LdapUser>`.
|
|
|
|
|
|
|
|
:param str username: the user name
|
|
|
|
:param str password: teh clear text password
|
|
|
|
:return: :py:const:`True` if the password has been set, :py:const:`False`
|
|
|
|
if the user does not exist.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2014-05-30 17:10:22 +02:00
|
|
|
@shared_task
|
|
|
|
def add_ldap_user_to_group(username, groupname):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
|
|
|
This task adds the specified user to the given group.
|
|
|
|
|
|
|
|
This task does nothing if the user is already member of the group.
|
|
|
|
|
|
|
|
:param str username: the user name
|
|
|
|
:param str groupname: the group name
|
|
|
|
:raises celery.exceptions.Retry: if the user does not exist yet,
|
|
|
|
:py:func:`create_ldap_user` should be called before
|
|
|
|
:return: True if the user has been added to the group otherwise False
|
|
|
|
:rtype: boolean
|
|
|
|
|
|
|
|
"""
|
2014-05-30 17:10:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def remove_ldap_user_from_group(username, groupname):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
|
|
|
This task removes the given user from the given group.
|
|
|
|
|
|
|
|
:param str username: the user name
|
|
|
|
:param str groupname: the group name
|
|
|
|
:return: True if the user has been removed, False otherwise
|
|
|
|
:rtype: boolean
|
|
|
|
|
|
|
|
"""
|
2014-05-30 17:10:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2014-05-30 18:39:51 +02:00
|
|
|
def delete_ldap_user(username):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
|
|
|
This task deletes the given user.
|
|
|
|
|
|
|
|
:param str username: the user name
|
|
|
|
:return: True if the user has been deleted, False otherwise
|
|
|
|
:rtype: boolean
|
|
|
|
|
|
|
|
"""
|
2014-05-30 17:10:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2014-05-30 17:18:42 +02:00
|
|
|
def delete_ldap_group_if_empty(groupname):
|
2014-12-27 22:44:27 +01:00
|
|
|
"""
|
2014-12-29 15:22:52 +01:00
|
|
|
This task deletes the given group if it is empty.
|
|
|
|
|
|
|
|
:param str groupname: the group name
|
|
|
|
:return: True if the user has been deleted, False otherwise
|
|
|
|
:rtype: boolean
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def delete_ldap_group(groupname):
|
|
|
|
"""
|
|
|
|
This taks deletes the given group.
|
2014-12-27 22:44:27 +01:00
|
|
|
|
|
|
|
:param str groupname: the group name
|
|
|
|
:return: True if the user has been deleted, False otherwise
|
|
|
|
:rtype: boolean
|
|
|
|
|
|
|
|
"""
|