Newer
Older
"""Generic backend User and Group, to be implemented by all backends."""
# vim: foldmethod=indent : tw=100
# pylint: disable=invalid-name, superfluous-parens
# pylint: disable=logging-fstring-interpolation, logging-not-lazy, logging-format-interpolation
# pylint: disable=raise-missing-from, missing-docstring, too-few-public-methods
"""Manages the user object on the service."""
"""
Arguments:
userinfo -- (type: UserInfo)
"""
def exists(self):
"""Return whether the user exists on the service.
If this returns True, calling `create` should have no effect or raise an error.
"""
return bool()

Diana Gudu
committed
def name_taken(self, name):
"""Return whether a given username is already taken by another user on the service.

Diana Gudu
committed
Should return True if the name is not available for this user (even if it is available
for other users for some reason)
"""
return bool()
def create(self):
"""Create the user on the service.
If the user already exists, do nothing or raise an error
"""
pass

Diana Gudu
committed
@abstractmethod
def create_tostring(self):
"""String representation of commands needed to deploy a new user.
Returns:
str: backend specific string containing user creation command(s)
"""
pass
# def create_fromstring(self, create_cmd: str):
# """Create a new user from string representation of commands needed to deploy a new user.
# Optional, only needed if the backend supports it.
#
# Arguments:
# create_cmd str: backend specific string containing user creation command(s)
# """
# pass
def update(self):
"""Update all relevant information about the user on the service.

Diana Gudu
committed
If the user doesn't exists, behaviour is undefined.
def delete(self):
"""Delete the user on the service.
If the user doesn't exists, do nothing or raise an error.
"""
pass

Diana Gudu
committed
def mod(self, supplementary_groups=None):

Diana Gudu
committed
After this operation, the user will only be part of the provided groups.

Diana Gudu
committed
If the user doesn't exists, behaviour is undefined.

Diana Gudu
committed
supplementary_groups -- A list of groups the user must be part of (type: list(Group))
Returns:
two lists of groups: the groups the user was added to and the groups the user was removed from
"""
pass

Diana Gudu
committed
@abstractmethod
def mod_tostring(self, supplementary_groups=None):
"""String representation of commands needed to modify a user to be added and removed from given groups.
Arguments:
supplementary_groups (list[Group], optional): the list of groups the user must be part of. Defaults to None.
Returns:
str: backend specific string containing all user modifications
"""
pass
# def mod_fromstring(self, mod_cmd: str):
# """Modify a user using string representation of commands needed to add & remove user to groups.
# Optional, only needed if the backend supports it.
#
# Arguments:
# mod_cmd str: backend specific string containing all user modification command(s)
# """
# pass
def get_groups(self):
"""Get a list of names of all service groups that the user belongs to.
If the user doesn't exist, behaviour is undefined.
def install_ssh_keys(self):
"""Install users SSH keys on the service.
No other SSH keys should be active after calling this function.
If the user doesn't exists, behaviour is undefined.
"""
pass
def uninstall_ssh_keys(self):
"""Uninstall the users SSH keys on the service.
This must uninstall all SSH keys installed with `install_ssh_keys`. It may uninstall SSH
keys installed by other means.
If the user doesn't exists, behaviour is undefined.
"""
pass

Diana Gudu
committed
def get_username(self):
"""Return local username on the service.
If the user doesn't exists, behaviour is undefined.
"""
pass

Diana Gudu
committed
def set_username(self, username):
"""Set local username on the service."""
pass
def get_primary_group(self):
"""Check if a user exists based on unique_id and return the primary group name."""
pass
def is_suspended(self):
"""Optional, only if the backend supports it.
Return whether the user was suspended (e.g. due to a security incident)"""
return False
def is_limited(self):
"""Optional, only if the backend supports it.
Return whether the user has limited access"""
return False
def suspend(self):
"""Optional, only if the backend supports it.
Suspends the user such that no access to the service is possible"""
pass
def resume(self):
"""Optional, only if the backend supports it.
Restores the suspended user"""
pass
def limit(self):
"""Optional, only if the backend supports it.
Limits the user's capabilities on the service (e.g. read-only access)"""
pass
def unlimit(self):
"""Optional, only if the backend supports it.
Restores a user with limited access to full capabilities"""
pass
"""Manages the group object on the service."""
def __init__(self, name):
"""
Arguments:
name -- The name of the group
"""
pass
def exists(self):
"""Return whether the group already exists."""
pass
def create(self):
"""Create the group on the service.
If the group already exists, behaviour is undefined.
"""
pass