ssg.rules module
Common functions for processing rules in SSG
- ssg.rules.applies_to_product(file_name, product)[source]
Determines if a given file applies to a specified product.
An OVAL or fix is considered applicable to a product if any of the following conditions are met: - The product parameter is Falsy (e.g., None, False, or an empty string). - The file_name is “shared”. - The file_name matches the product. - The product starts with the file_name.
Note that this function only filters based on the file name and does not consider the contents of the fix or check.
- Parameters:
file_name (str) – The name of the file to check.
product (str) – The product to check against.
- Returns:
True if the file applies to the product, False otherwise.
- Return type:
bool
- ssg.rules.find_rule_dirs(base_dir)[source]
Generator which yields all rule directories within a given base_dir, recursively.
- Parameters:
base_dir (str) – The base directory to start searching for rule directories.
- Yields:
str – The path to each rule directory found within the base directory.
- ssg.rules.find_rule_dirs_in_paths(base_dirs)[source]
Generator which yields all rule directories within a given directories list, recursively.
- Parameters:
base_dirs (list) – A list of base directories to search for rule directories.
- Yields:
str – Paths to rule directories found within the base directories.
- ssg.rules.get_rule_dir_id(path)[source]
Returns the base name of a rule directory.
This function takes a file path and returns the base name of the directory. It correctly handles being passed either the directory path or the YAML metadata file path (ending with ‘rule.yml’).
- Parameters:
path (str) – The file or directory path.
- Returns:
The base name of the rule directory.
- Return type:
str
- ssg.rules.get_rule_dir_ovals(dir_path, product=None)[source]
Gets a list of OVALs contained in a rule directory.
If product is None, returns all OVALs. Only returns OVALs which exist.
- Parameters:
dir_path (str) – The path to the rule directory.
product (str, optional) – The product name to filter OVALs. Defaults to None.
- Returns:
A list of paths to OVAL files in the specified directory, ordered by priority.
- Return type:
list
- ssg.rules.get_rule_dir_sces(dir_path, product=None)[source]
Get a list of SCEs contained in a rule directory.
Only returns SCEs which exist.
- Parameters:
dir_path (str) – The path to the rule directory.
product (str, optional) – The product name to filter SCEs. If None, returns all SCEs.
- Returns:
- A list of paths to applicable SCE files. If product is specified, returns SCEs
in the order of priority: - {product}.{ext} - shared.{ext}
- Return type:
list
- The function performs the following steps:
Checks if the provided directory is a valid rule directory.
Checks if the “sce” subdirectory exists within the rule directory.
Iterates over the files in the “sce” directory, filtering and prioritizing them based on the product.
Returns a list of applicable SCE file paths, with product-specific SCEs listed before shared SCEs.
- ssg.rules.get_rule_dir_yaml(dir_path)[source]
Constructs the path to the YAML metadata file for a given rule directory, regardless of if it exists.
- Parameters:
dir_path (str) – The path to the rule directory.
- Returns:
The path to the “rule.yml” file within the specified directory.
- Return type:
str
- ssg.rules.is_rule_dir(dir_path)[source]
Check if a given directory path is a valid rule directory.
A valid rule directory must: 1. Exist as a directory. 2. Contain a specific YAML file as determined by get_rule_dir_yaml().
- Parameters:
dir_path (str) – The path to the directory to check.
- Returns:
True if dir_path is a valid rule directory, False otherwise.
- Return type:
bool