ssg.cce module
Common functions for processing CCE (Common Configuration Enumeration) in SSG
- class ssg.cce.CCEFile(project_root=None)[source]
Bases:
objectA class to represent a CCE (Common Configuration Enumeration) file.
- project_root
The root directory of the project.
- Type:
str
- property absolute_path
- random_cce()[source]
Selects a random CCE (Common Configuration Enumeration) from the list of CCEs.
Reads the list of CCEs, shuffles them randomly, and returns the first CCE from the shuffled list after stripping any leading or trailing whitespace.
- Returns:
A randomly selected and stripped CCE.
- Return type:
str
- read_cces()[source]
Reads the CCEs (Common Configuration Enumeration) from a file and validates them.
This method opens the file specified by self.absolute_path, reads its contents line by line, and checks each line to ensure it is a valid CCE value. If an invalid CCE is detected, a RuntimeError is raised with an appropriate error message.
- Returns:
A list of valid CCE values read from the file.
- Return type:
list
- Raises:
RuntimeError – If an invalid CCE value is detected in the file.
- remove_cce_from_file(cce)[source]
Removes lines containing the specified CCE (Common Configuration Enumeration) from a file.
- Parameters:
cce (str) – The CCE identifier to be removed from the file.
The method reads the file, filters out lines containing the specified CCE, and writes the remaining lines back to the file.
- class ssg.cce.RedhatCCEFile(project_root=None)[source]
Bases:
CCEFileRedhatCCEFile is a subclass of CCEFile that represents a file containing Red Hat Common Configuration Enumeration (CCE) data.
- Properties:
- absolute_path (str): The absolute path to the Red Hat CCE file, which is located in the
“shared/references” directory within the project root and named “cce-redhat-avail.txt”.
- property absolute_path
- class ssg.cce.SLE12CCEFile(project_root=None)[source]
Bases:
CCEFileSLE12CCEFile is a subclass of CCEFile that represents a file containing SLE12 Common Configuration Enumeration (CCE) data.
This class provides a property to get the absolute path of the SLE12 CCE file.
- Properties:
- absolute_path (str): The absolute path to the SLE12 CCE file, which is located in the
“shared/references” directory.
- property absolute_path
- class ssg.cce.SLE15CCEFile(project_root=None)[source]
Bases:
CCEFileSLE15CCEFile is a subclass of CCEFile that represents a file containing SLE15 Common Configuration Enumeration (CCE) data.
This class provides a property to get the absolute path of the SLE12 CCE file.
- Properties:
- absolute_path (str): The absolute path to the SLE15 CCE file, which is located in the
“shared/references” directory.
- property absolute_path
- class ssg.cce.SLE16CCEFile(project_root=None)[source]
Bases:
CCEFileSLE16CCEFile is a subclass of CCEFile that represents a file containing SLE16 Common Configuration Enumeration (CCE) data.
This class provides a property to get the absolute path of the SLE12 CCE file.
- Properties:
- absolute_path (str): The absolute path to the SLE15 CCE file, which is located in the
“shared/references” directory.
- property absolute_path
- ssg.cce.is_cce_format_valid(cceid)[source]
Check if the given CCE ID is in a valid format.
A valid CCE ID must be in one of the following formats: - ‘CCE-XXXX-X’ - ‘CCE-XXXXX-X’
where each ‘X’ is a digit, and the final ‘X’ is a check-digit.
- Parameters:
cceid (str) – The CCE ID to validate.
- Returns:
True if the CCE ID is in a valid format, False otherwise.
- Return type:
bool
- ssg.cce.is_cce_value_valid(cceid)[source]
Validates a CCE (Common Configuration Enumeration) identifier using Luhn’s algorithm.
This function removes non-digit characters from the CCE identifier and then applies Luhn’s algorithm to determine if the identifier is valid.
- Parameters:
cceid (str) – The CCE identifier to validate.
- Returns:
True if the CCE identifier is valid, False otherwise.
- Return type:
bool
References
For context, see: https://github.com/ComplianceAsCode/content/issues/3044#issuecomment-420844095