mscp.common_utils.validate_rules
Schema and folder-structure validators for rule YAML files.
Wires up the mscp admin validate subcommand. validate_yaml_file
walks the configured rules directory (plus any custom rules) and
validates each file against schema/mscp_rule.json;
validate_rule_folder_structure is an argparse type validator that
makes sure --rules_dir points at a properly organised tree.
get_rule_identifier is a small helper that prefers a rule file’s
id field, falling back to its filename stem.
Functions
Section titled “Functions”get_rule_identifier
Section titled “get_rule_identifier”get_rule_identifier(rule_file: Path) -> strReturn the rule’s canonical ID, preferring the YAML id field.
Falls back to the filename stem when the YAML doesn’t define one.
Args
rule_file(Path) — Path to a rule YAML file.
Returns
str— The rule’s identifier.
validate_yaml_file
Section titled “validate_yaml_file”validate_yaml_file(args: argparse.Namespace) -> NoneValidate every rule YAML against schema/mscp_rule.json.
Loads the schema, then iterates either args.rules_dir (if set)
or the default rules tree plus any custom rules. Prints / logs a
line per file: ✅ VALID, ❌ INVALID, or ⚠️ ERROR. Files
with duplicate rule identifiers are flagged with a warning.
Args
args(argparse.Namespace) — Parsed CLI arguments. Readsrules_dir(override) andall_validation(when true, successful files are also printed).
validate_rule_folder_structure
Section titled “validate_rule_folder_structure”validate_rule_folder_structure(path_str: str) -> PathArgparse ‘type’ validator:
- Ensures PATH exists and is a directory.
- Ensures root contains only subdirectories (no files).
- Ensures each subdir contains only YAML files and/or is empty.
- Disallows nested directories under subfolders (can be toggled).