SCAutolib.models.file
This module contains classes that represent configuration files. Each class contains information and methods to manipulate specific config file except the parent (File) class that is supposed to operate on general config file.
- Basic operations on config files defined in this module:
- create
creates content of config file usually based on template. Note, that some child classes may also update content of config file if it already existed and backup original file.
- set
modify values of config files, add keys or sections if necessary
- save
save modified content to config file
- clean
remove config file; note that some child classes may also restore original config file if backup exists.
Classes
- class File(filepath, template=None)[source]
This class defines an interface for generic operations on config files
create: create content of config file based on template file
set: modify content of config files, add keys or sections if necessary
save: save config file
clean: remove config file
Note
Set method operates only on:
files compatible with ConfigParser (i.e. files containing sections)
simple config files without sections.
Other formats of config files are not supported.
Init of File
- Parameters:
filepath (str or pathlib.Path) – Path of config file
template (str) – Path of template file
- backup(name=None)[source]
Save original file to the backup directory with given name. If name is None, default name is
<filename>.<extension>.backup- Parameters:
name (str) – custom file name to be set for the file
- Returns:
path where the file is stored
- get(key, section=None, separator='=')[source]
Method processes and returns the value of the key in section. If the section is not provided (section=None), then file would be parsed line by line splitting the line on separator. First match wins and is returned.
If section is provided and the file can be parsed by the
ConfigParser, then this object would be used to look for the key.- Parameters:
- Raises:
SCAutolib.SCAutolibException – if the key is not found the non-ConfigParser file
configparser.NoSectionError – if the section is not found in ConfigParser-supported file
KeyError – if the key is not present in ConfigParser-supported file
- Returns:
value of the key in section (if set)
- set(key, value, section=None, separator='=')[source]
Modify value in config file. Modification is made through the ConfigParser object if it is defined. If not, then key value pair would be written to the file through normal
write()method with composed string in the following form<key><separator><value>Note
spaces around key has to be specified as a part of the
separatorparameter.- Parameters:
key (str) – value for this key will be updated
value (int or str or bool) – new value to be stored in [section][key] of config file
section (str) – section of config file that will be modified
separator (str) – Character to be used as a separator between key and value in files that are not supported by ConfigParser object.
- class OpensslCnf(filepath, conf_type, replace)[source]
This class provides information and methods to create and modify openssl cnf files.
Init of opensslCNF
- Parameters:
filepath (str or pathlib.Path) – Path of config file
conf_type (basestring) – Identifier of cnf file
replace (list) – list of strings that will replace specific strings from template
- class SSSDConf[source]
This class contains information and methods to create and modify /etc/sssd/sssd.conf file.
It is implemented as singleton, which allows to use class object
_default_parseras representation of content of sssd.conf file during runtime.Intended use is to create/update and save config file in first runtime and load content of config file to internal parser object in following runtimes.
Init of File
- Parameters:
filepath (str or pathlib.Path) – Path of config file
template (str) – Path of template file
- create()[source]
Populate internal parser object with content from existing config file and update it with values from config template. Back up original files.
- restore()[source]
Removes sssd.conf file in case it was created by this package or restore original sssd.conf in case the file was modified.
- class SoftHSM2Conf(filepath, card_dir)[source]
This class provide information and methods to create and modify softhsm2.conf file.
Init of SoftHSM2Conf
- Parameters:
- set(*args)[source]
- Raises:
NotImplementedError – if this method is called on SoftHSM2Conf.