pyceo/ceo_common/interfaces/ILDAPService.py

81 lines
2.4 KiB
Python
Raw Normal View History

2021-08-03 10:09:07 -04:00
from typing import List, Union
2021-07-19 01:47:39 -04:00
from zope.interface import Interface
from .IUser import IUser
from .IGroup import IGroup
class ILDAPService(Interface):
"""An interface to the LDAP database."""
2021-08-15 01:04:49 -04:00
def uid_to_dn(self, uid: str) -> str:
"""Get the LDAP DN for the user with this UID."""
def group_cn_to_dn(self, cn: str) -> str:
"""Get the LDAP DN for the group with this CN."""
2021-07-19 01:47:39 -04:00
def get_user(username: str) -> IUser:
"""Retrieve the user with the given username."""
2021-08-15 01:04:49 -04:00
def add_user(user: IUser):
2021-07-19 01:47:39 -04:00
"""
2021-07-23 20:08:22 -04:00
Add the user to the database.
2021-07-19 01:47:39 -04:00
A new UID and GID will be generated and returned in the new user.
"""
2021-07-24 17:09:10 -04:00
def remove_user(user: IUser):
"""Remove this user from the database."""
2021-07-19 01:47:39 -04:00
def get_group(cn: str, is_club: bool = False) -> IGroup:
"""Retrieve the group with the given cn (Unix group name)."""
2021-08-15 01:04:49 -04:00
def add_group(group: IGroup):
2021-07-19 01:47:39 -04:00
"""
2021-07-23 20:08:22 -04:00
Add the group to the database.
2021-07-19 01:47:39 -04:00
The GID will not be changed and must be valid.
"""
2021-07-24 17:09:10 -04:00
def remove_group(group: IGroup):
"""Remove this group from the database."""
2021-08-15 01:04:49 -04:00
def entry_ctx_for_user(user: IUser):
"""
Get a context manager which yields an ldap3.WritableEntry
for this user.
"""
2021-07-19 01:47:39 -04:00
2021-08-15 01:04:49 -04:00
def entry_ctx_for_group(group: IGroup):
"""
Get a context manager which yields an ldap3.WritableEntry
for this group.
"""
2021-07-23 20:08:22 -04:00
def add_sudo_role(uid: str):
"""Create a sudo role for the club with this UID."""
2021-07-24 17:09:10 -04:00
def remove_sudo_role(uid: str):
"""Remove the sudo role for this club from the database."""
2021-08-03 10:09:07 -04:00
def update_programs(
dry_run: bool = False,
members: Union[List[str], None] = None,
):
"""
Sync the 'program' attribute in CSC LDAP with UW LDAP.
If `dry_run` is set to True, then a list of members whose programs
*would* be changed is returned along with their old and new programs:
```
[
('user1', 'old_program1', 'new_program1'),
('user2', 'old_program2', 'new_program2'),
...
]
```
If `members` is set to a list of usernames, then only
those members will (possibly) have their programs updated.
On success, a list of members whose programs *were* changed will
be returned along with their new programs, in the same format
described above.
"""