SCAutolib.utils
This module provides a collection of utility and helper functions utilized across the SCAutolib library. These functions are specifically designed to support various internal demands of the library, including system checks, package management, key/certificate handling, and data serialization. They are not intended as general-purpose utilities but as specialized aids tailored to SCAutolib’s operations.
Functions
- ca_factory(path=None, cnf=None, card_data=None, ca_name=None, create=False)[source]
A factory function to create or load Certificate Authority (CA) objects based on the provided parameters. It can initialize a new CA instance or load an existing one from a JSON dump file.
- Parameters:
path (pathlib.Path, optional) – The
pathlib.Pathobject to the CA’s root directory. This is used when creating a newLocalCAinstance.cnf (SCAutolib.models.file.OpensslCnf, optional) – An
OpensslCnfobject representing the OpenSSL configuration file for the CA. Used when creating a newLocalCA.card_data (dict, optional) – A dictionary containing various attributes of the card (e.g., PIN, cardholder, slot). This data is used when creating a new
CustomCAfor physical cards.ca_name (str, optional) – The name of the CA to load. This parameter is used when
createisFalseto identify the specific CA JSON dump file.create (bool) – If
True, a new CA object will be created (eitherLocalCAorCustomCA). IfFalse, an existing CA object will be loaded from a dump file.
- Returns:
An initialized CA object (either
LocalCA,CustomCA, orIPAServerCAinstance).- Return type:
- dump_to_json(obj)[source]
Serializes a given object into a JSON file, using the object’s
to_dict()method for serialization and itsdump_fileattribute to determine the output path. This is used to persist the state of SCAutolib’s internal objects (like users, CAs, and cards) across different runs.- Parameters:
obj (object) – The object to be serialized. It must have a
to_dict()method and adump_fileattribute.- Returns:
None
- ipa_factory()[source]
Creates and returns an
IPAServerCAobject. This function loads the IPA server CA configuration from its JSON dump file. It specifically asserts that the loaded CA is an instance ofIPAServerCA.- Returns:
An initialized
IPAServerCAobject.- Return type:
- Raises:
SCAutolibException – If the IPA server CA dump file is not found or if the loaded object is not a valid
IPAServerCAinstance.
- load_token(card_name=None, update_sssd=False)[source]
Loads a
Cardobject from a JSON dump file based on the provided card name. This function is primarily intended for use in pytest configurations to set up card objects for tests. Optionally, it can update the SSSD configuration file (sssd.conf) with ashadowutilsrule for the user of the loaded card.- Parameters:
- Returns:
The loaded
Cardobject- Return type:
- load_user(username, **kwargs)[source]
Loads a
Userobject from a JSON dump file corresponding to the given username. The file is expected to be located inLIB_DUMP_USERSdirectory.- Parameters:
- Returns:
The loaded
Userobject (eitherUserorIPAUserinstance).- Return type:
- Raises:
SCAutolibException – If the user’s JSON dump file does not exist.