SCAutolib.models.user
This module defines the User and IPAUser classes, which are designed to
represent and manage system and FreeIPA users within the SCAutolib framework.
These classes encapsulate user properties like username and password, and implement methods for common user management operations such as adding and deleting users from either the local system or a specified IPA server.
Classes
- class IPAUser(ipa_server, *args, **kwargs)[source]
Represents an IPA (Identity Management for Linux) user. This class extends the base
Userclass to include specific functionalities for managing users within an IPA server environment, primarily through thepython_freeipalibrary.Initializes an
IPAUserobject. IPA client should be configured first before creating an IPA user through this class. It requires anIPAServerCAobject to facilitate communication with the IPA server and inherits user attributes from the baseUserclass.- Parameters:
ipa_server (SCAutolib.models.CA.IPAServerCA) – An
IPAServerCAobject that provides the necessary IPA server hostname andClientMetaobject for interaction.username (str) – The username for the system user.
password (str) – The password for the system user.
- Returns:
None
- Return type:
None
- add_user()[source]
Adds the IPA user to the IPA server using the
python_freeipaclient. It sets a default password and then changes it to the specified password to avoid requiring a password change on first login.- Returns:
None
- Return type:
None
- Raises:
SCAutolibException – If the user already exists on the IPA server.
- delete_user()[source]
Deletes the IPA user from the IPA server using the
python_freeipaclient. If the user is not found on the server, the operation is silently ignored.- Returns:
None
- Return type:
None
- to_dict()[source]
Converts the
IPAUserobject’s attributes into a dictionary for JSON serialization. It calls the baseUser.to_dict()method and then removes internal_meta_clientand_ipa_hostnameattributes, which are not directly serializable.- Returns:
A dictionary representation of the IPA user object’s attributes.
- Return type:
- class User(username, password)[source]
Represents a general system user, typically a local user account on the machine where SCAutolib is running. It holds user properties like username and password, and provides methods to manage the user’s presence on the local system. User objects can be serialized to and loaded from JSON dump files for persistence across SCAutolib runs.
Initializes a
Userobject for a local system user.- Parameters:
- Returns:
None
- Return type:
None
- add_user()[source]
Adds the user to the local system using the
useraddsystem management command and sets their password viapasswd --stdin. It checks if the user already exists to prevent collisions.- Returns:
None
- Return type:
None
- Raises:
SCAutolibException – If the user already exists on the system.
- delete_user()[source]
Deletes the local user from the system using the
userdel -fcommand. It also removes the corresponding JSON dump file for the user.- Returns:
None
- Return type:
None
- static load(json_file, **kwargs)[source]
Loads user data from a specified JSON file and reconstructs the corresponding
UserorIPAUserobject. It determines the correct class to instantiate based on theuser_typefield in the JSON content.- Parameters:
json_file (pathlib.Path) – The
pathlib.Pathobject pointing to the JSON file from which to read the user’s data.kwargs (dict) – Additional keyword arguments that might be necessary to initialize the user object, particularly for
IPAUserwhich requires anipa_serverobject.
- Returns:
An initialized
UserorIPAUserobject loaded with data from the JSON file.- Return type:
- Raises:
SCAutolibException – If an unknown user type is encountered in the JSON data, or if
ipa_serveris not provided for an IPA user.