Improve documentation
This commit adds a lot of documentation including block diagramms for message flows.
This commit is contained in:
parent
09cfc6a373
commit
5dc3549896
11 changed files with 853 additions and 87 deletions
|
@ -1,6 +1,10 @@
|
|||
"""
|
||||
This module contains the Django admin classes of the :py:mod:`osusers` app.
|
||||
|
||||
The module starts Celery_ tasks.
|
||||
|
||||
.. _Celery: http://www.celeryproject.org/
|
||||
|
||||
"""
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -341,6 +345,30 @@ class SshPublicKeyAdmin(admin.ModelAdmin):
|
|||
:param request: the current HTTP request
|
||||
:param queryset: Django ORM queryset representing the selected ssh keys
|
||||
|
||||
This method starts a Celery_ task to update the list of authorized keys
|
||||
for each affected user.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this method"
|
||||
];
|
||||
B [ label = "set file ssh authorized_keys",
|
||||
description = ":py:func:`set_file_ssh_authorized_keys()
|
||||
<fileservertasks.tasks.set_file_ssh_authorized_keys>`
|
||||
called with username and a list of keys, returning the path
|
||||
of the ssh authorized_keys file",
|
||||
color = "LightGreen",
|
||||
stacked
|
||||
];
|
||||
}
|
||||
|
||||
"""
|
||||
users = set([
|
||||
item['user'] for item in
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
"""
|
||||
This module contains the signal handlers of the :py:mod:`osusers` app.
|
||||
|
||||
The module starts Celery_ tasks.
|
||||
|
||||
.. _Celery: http://www.celeryproject.org/
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
|
@ -14,17 +18,17 @@ from django.dispatch import receiver
|
|||
|
||||
from fileservertasks.tasks import (
|
||||
delete_file_mail_userdir,
|
||||
delete_file_sftp_userdir,
|
||||
delete_file_sftp_userdir_chained,
|
||||
set_file_ssh_authorized_keys,
|
||||
setup_file_mail_userdir,
|
||||
setup_file_sftp_userdir,
|
||||
setup_file_mail_userdir_chained,
|
||||
setup_file_sftp_userdir_chained,
|
||||
)
|
||||
from ldaptasks.tasks import (
|
||||
add_ldap_user_to_group,
|
||||
create_ldap_group,
|
||||
create_ldap_user,
|
||||
delete_ldap_group,
|
||||
delete_ldap_user,
|
||||
delete_ldap_user_chained,
|
||||
remove_ldap_user_from_group,
|
||||
set_ldap_user_password,
|
||||
)
|
||||
|
@ -44,6 +48,33 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
@receiver(password_set, sender=User)
|
||||
def handle_user_password_set(sender, instance, password, **kwargs):
|
||||
"""
|
||||
Handles password changes on :py:class:`User <osusers.models.User>`
|
||||
instances.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: User instance
|
||||
:param str password: the new password
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler" ];
|
||||
B [ label = "set ldap user password", color = "Wheat",
|
||||
description = ":py:func:`set_ldap_user_password()
|
||||
<ldaptasks.tasks.set_ldap_user_password>` called with
|
||||
username and password, returning :py:const:`True` if the
|
||||
password has been set" ];
|
||||
}
|
||||
"""
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_user_password_set',
|
||||
set_ldap_user_password.s(instance.username, password))
|
||||
|
@ -52,15 +83,35 @@ def handle_user_password_set(sender, instance, password, **kwargs):
|
|||
taskresult.task_id)
|
||||
|
||||
|
||||
# @receiver(post_save)
|
||||
# def handle_post_save(sender, **kwargs):
|
||||
# _LOGGER.debug(
|
||||
# 'handling post_save signal for %s with args %s',
|
||||
# sender, kwargs)
|
||||
|
||||
|
||||
@receiver(post_save, sender=Group)
|
||||
def handle_group_created(sender, instance, created, **kwargs):
|
||||
"""
|
||||
Handles post creation actions on :py:class:`Group <osusers.models.Group>`
|
||||
instances.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: Group instance
|
||||
:param bool created: whether the instance has just been created
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler" ];
|
||||
B [ label = "create ldap group", color = "Wheat",
|
||||
description = ":py:func:`create_ldap_group()
|
||||
<ldaptasks.tasks.create_ldap_group>` called with groupname,
|
||||
gid and description, returning group DN" ];
|
||||
}
|
||||
|
||||
"""
|
||||
if created:
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_group_created',
|
||||
|
@ -75,13 +126,52 @@ def handle_group_created(sender, instance, created, **kwargs):
|
|||
|
||||
@receiver(post_save, sender=User)
|
||||
def handle_user_created(sender, instance, created, **kwargs):
|
||||
"""
|
||||
Handles post creation actions on :py:class:`User <osusers.models.User>`
|
||||
instances.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: User instance
|
||||
:param bool created: whether the instance has just bean created
|
||||
|
||||
This signal handler starts a chain of Celery_ tasks.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B -> C -> D;
|
||||
B -> C [folded];
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler" ];
|
||||
B [ label = "create ldap user", color = "Wheat",
|
||||
description = ":py:func:`create_ldap_user()
|
||||
<ldaptasks.tasks.create_ldap_user>` called with username, uid,
|
||||
gid, gecos, homeidr, shell, :py:const:`None`, returning
|
||||
username" ];
|
||||
C [ label = "setup file sftp userdir", color = "LightGreen",
|
||||
description = ":py:func:`setup_file_sftp_userdir_chained()
|
||||
<fileservertasks.tasks.setup_file_sftp_userdir_chained>`
|
||||
called with the result of create ldap user task, returning a
|
||||
dictionary containing username and sftp_directory"];
|
||||
D [ label = "setup file mail userdir", color = "LightGreen",
|
||||
description = ":py:func:`setup_file_mail_userdir_chained()
|
||||
<fileservertasks.tasks.setup_file_mail_userdir_chained>` called
|
||||
with result of setup file sftp userdir task, returning
|
||||
dictionary containing username, sftp_directory and
|
||||
mail_directory" ];
|
||||
}
|
||||
|
||||
"""
|
||||
if created:
|
||||
chain = create_ldap_user.s(
|
||||
instance.username, instance.uid, instance.group.gid,
|
||||
instance.gecos, instance.homedir, instance.shell, None
|
||||
) | setup_file_sftp_userdir.s(
|
||||
instance.username
|
||||
) | setup_file_mail_userdir.s(instance.username)
|
||||
) | setup_file_sftp_userdir_chained.s() | (
|
||||
setup_file_mail_userdir_chained.s())
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_user_created', chain)
|
||||
_LOGGER.info(
|
||||
|
@ -93,6 +183,34 @@ def handle_user_created(sender, instance, created, **kwargs):
|
|||
|
||||
@receiver(post_save, sender=AdditionalGroup)
|
||||
def handle_user_added_to_group(sender, instance, created, **kwargs):
|
||||
"""
|
||||
Handles post creation actions on :py:class:`AdditionalGroup
|
||||
<osusers.models.AdditionalGroup>` instances.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: AdditionalGroup instance
|
||||
:param bool created: whether the instance has just bean created
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler" ];
|
||||
B [ label = "add ldap user to group", color = "Wheat",
|
||||
description = ":py:func:`add_ldap_user_to_group()
|
||||
<ldaptasks.tasks.add_ldap_user_to_group>` called with username
|
||||
and groupname, returning :py:const:`True` if the user has been
|
||||
added to the group" ];
|
||||
}
|
||||
|
||||
"""
|
||||
if created:
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_user_added_to_group',
|
||||
|
@ -106,6 +224,33 @@ def handle_user_added_to_group(sender, instance, created, **kwargs):
|
|||
@receiver(post_save, sender=SshPublicKey)
|
||||
@receiver(post_delete, sender=SshPublicKey)
|
||||
def handle_ssh_keys_changed(sender, instance, **kwargs):
|
||||
"""
|
||||
Handles changes to :py:class:`SshPublicKey <osuses.models.SshPublicKey>`
|
||||
instances related to a user.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: SshPublicKey instance
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler" ];
|
||||
B [ label = "set file ssh authorized_keys", color = "LightGreen",
|
||||
description = ":py:func:`set_file_ssh_authorized_keys()
|
||||
<fileservertasks.tasks.set_file_ssh_authorized_keys>` called
|
||||
with username and the corresponding list of keys, returning the
|
||||
path of the ssh_authorized_keys_file" ];
|
||||
}
|
||||
|
||||
"""
|
||||
sig = set_file_ssh_authorized_keys.s(
|
||||
instance.user.username, [
|
||||
str(key) for key in
|
||||
|
@ -126,6 +271,33 @@ def handle_ssh_keys_changed(sender, instance, **kwargs):
|
|||
|
||||
@receiver(post_delete, sender=Group)
|
||||
def handle_group_deleted(sender, instance, **kwargs):
|
||||
"""
|
||||
Handles cleanup actions to be done after deletion of a :py:class:`Group
|
||||
<osusers.models.Group>` instance.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: Group instance
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler"
|
||||
];
|
||||
B [ label = "delete ldap group", color = "Wheat",
|
||||
description = ":py:func:`delete_ldap_group()
|
||||
<ldaptasks.tasks.delete_ldap_group>` called with groupname,
|
||||
returning :py:const:`True` if the group has been deleted" ];
|
||||
}
|
||||
|
||||
"""
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_group_deleted',
|
||||
delete_ldap_group.s(instance.groupname))
|
||||
|
@ -136,11 +308,49 @@ def handle_group_deleted(sender, instance, **kwargs):
|
|||
|
||||
@receiver(post_delete, sender=User)
|
||||
def handle_user_deleted(sender, instance, **kwargs):
|
||||
"""
|
||||
Handles cleanup actions to be done after deletion of a :py:class:`User
|
||||
<osusers.models.User>` instance.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: User instance
|
||||
|
||||
This signal handler starts a chain of Celery_ tasks.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B -> C -> D;
|
||||
B -> C [folded];
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler"
|
||||
];
|
||||
B [ label = "delete file mail userdir", color = "LightGreen",
|
||||
description = ":py:func:`delete_file_mail_userdir()
|
||||
<fileservertasks.tasks.delete_file_mail_userdir>` called with
|
||||
username, returning a dictionary containing the username and
|
||||
the deleted mail_directory" ];
|
||||
C [ label = "delete file sftp userdir", color = "LightGreen",
|
||||
description = ":py:func:`delete_file_sftp_userdir_chained()
|
||||
<fileservertasks.tasks.delete_file_sftp_userdir_chained>`
|
||||
called with the result of delete mail userdir, returning
|
||||
dictionary containing username, deleted mail_directory and
|
||||
deleted sftp_directory" ];
|
||||
D [ label = "delete ldap user", color = "Wheat",
|
||||
description = ":py:func:`delete_ldap_user_chained()
|
||||
<ldaptasks.tasks.delete_ldap_user_chained>` called with the
|
||||
result of delete file sftp userdir and adding the deleted user
|
||||
DN to the result" ];
|
||||
}
|
||||
|
||||
"""
|
||||
chain = delete_file_mail_userdir.s(
|
||||
instance.username
|
||||
) | delete_file_sftp_userdir.s(
|
||||
instance.username
|
||||
) | delete_ldap_user.s(instance.username)
|
||||
) | delete_file_sftp_userdir_chained.s() | delete_ldap_user_chained.s()
|
||||
_LOGGER.debug('chain signature %s', chain)
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_user_deleted', chain)
|
||||
|
@ -151,6 +361,37 @@ def handle_user_deleted(sender, instance, **kwargs):
|
|||
|
||||
@receiver(post_delete, sender=AdditionalGroup)
|
||||
def handle_user_removed_from_group(sender, instance, **kwargs):
|
||||
"""
|
||||
Handles cleanup actions to be done after removing a user from a group by
|
||||
deleting the :py:class:`AdditionalGroup <osusers.models.AdditionalGroup>`
|
||||
instance.
|
||||
|
||||
:param sender: sender of the signal
|
||||
:param instance: AdditionalGroup instance
|
||||
|
||||
This signal handler starts a Celery_ task.
|
||||
|
||||
.. blockdiag::
|
||||
:desctable:
|
||||
|
||||
blockdiag {
|
||||
node_width = 200;
|
||||
|
||||
A -> B;
|
||||
|
||||
A [ label = "", shape = beginpoint,
|
||||
description = "this signal handler"
|
||||
];
|
||||
B [ label = "remove ldap user from group", color = "Wheat",
|
||||
description = ":py:func:`remove_ldap_user_from_group()
|
||||
<ldaptasks.tasks.remove_ldap_user_from_group>` called with
|
||||
username and groupname, returning :py:const:`True` if the user
|
||||
has been a member of the group and has been removed from the
|
||||
group"
|
||||
];
|
||||
}
|
||||
|
||||
"""
|
||||
taskresult = TaskResult.objects.create_task_result(
|
||||
'handle_user_removed_from_group',
|
||||
remove_ldap_user_from_group.s(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue