creds.users

Users([oktypes]) A collection of users and methods to manage them.
User([name, passwd, uid, gid, gecos, …]) Representation of a user and their related credentials.
generate_add_user_command([proposed_user, …]) Generate command to add a user.
generate_modify_user_command([task, manage_home]) Generate command to modify existing user to become the proposed user.
generate_delete_user_command([username, …]) Generate command to delete a user.
get_user_by_uid([uid, users]) Return a list of users, from a supplied list, based on their uid.
compare_user([passed_user, user_list]) Check if supplied User instance exists in supplied Users list and, if so, return the differences.

class creds.users.User(name=None, passwd=None, uid=None, gid=None, gecos=None, home_dir=None, shell=None, public_keys=None, sudoers_entry=None)[source]

Representation of a user and their related credentials.

gecos

Force double quoted gecos.

Returns:The double quoted gecos.
Return type:str
to_dict()[source]

Return the user as a dict.

class creds.users.Users(oktypes=<class 'creds.users.User'>)[source]

A collection of users and methods to manage them.

check(value)[source]

Check types.

static construct_user_list(raw_users=None)[source]

Construct a list of User objects from a list of dicts.

describe_users(users_filter=None)[source]

Return a list of users matching a filter (if provided).

export(file_path=None, export_format=None)[source]

Write the users to a file.

classmethod from_dict(input_dict=None)[source]

Create collection from dictionary content.

classmethod from_json(file_path=None)[source]

Create collection from a JSON file.

static from_passwd(uid_min=None, uid_max=None)[source]

Create collection from locally discovered data, e.g. /etc/passwd.

classmethod from_yaml(file_path=None)[source]

Create collection from a YAML file.

insert(index, value)[source]

Insert an instance of User into the collection.

remove(username=None)[source]

Remove User instance based on supplied user name.

to_dict()[source]

Return a dict of the users.

creds.users.compare_user(passed_user=None, user_list=None)[source]

Check if supplied User instance exists in supplied Users list and, if so, return the differences.

Parameters:
  • passed_user (User) – the user instance to check for differences
  • user_list (Users) – the Users instance containing a list of Users instances
Returns:

Details of the matching user and a list of differences

Return type:

dict

creds.users.generate_add_user_command(proposed_user=None, manage_home=None)[source]

Generate command to add a user.

Parameters:
  • proposed_user (User) – User
  • manage_home – bool
Returns:

The command string split into shell-like syntax

Return type:

list

creds.users.generate_delete_user_command(username=None, manage_home=None)[source]

Generate command to delete a user.

Parameters:
  • username (str) – user name
  • manage_home (bool) – manage home directory
Returns:

The user delete command string split into shell-like syntax

Return type:

list

creds.users.generate_modify_user_command(task=None, manage_home=None)[source]

Generate command to modify existing user to become the proposed user.

Parameters:task (dict) – A proposed user and the differences between it and the existing user
Returns:The command string split into shell-like syntax
Return type:list
creds.users.get_user_by_uid(uid=None, users=None)[source]

Return a list of users, from a supplied list, based on their uid.

Parameters:
  • uid (id) – A user id
  • user_list (list) – An instance of Users
Returns:

a list of users matching the supplied uid

Return type:

list