"""Data-only scoring policy. No executable expressions or arbitrary regex rules.""" import copy import hashlib import json from pathlib import Path DEFAULT_POLICY = Path(__file__).resolve().parents[1] / 'assets' / 'scoring_policy.json' RULES = {'installed_workload_role', 'running_application_service', 'attributed_application_listener', 'observed_application_clients', 'configured_business_share', 'observed_smb_transport', 'observed_business_share_clients', 'configured_custom_schedule', 'verified_domain_controller'} def load_policy(source=None): if source is not None and not isinstance(source,(dict,str,Path)): raise ValueError('A scoring policy must be a JSON object or file path.') if isinstance(source, dict): policy = copy.deepcopy(source) else: path = Path(source) if source is not None else DEFAULT_POLICY try: if path.stat().st_size > 65536: raise ValueError('Scoring policy exceeds 64 KiB.') policy = json.loads(path.read_text(encoding='utf-8')) except (OSError, UnicodeError, json.JSONDecodeError, RecursionError): raise ValueError('Unable to read a valid UTF-8 scoring policy JSON file.') from None try: limits, weights = policy['thresholds'], policy['coverage_weights'] valid = ( set(policy) == {'model_version','name','scores','thresholds','coverage_weights','partial_check_credit'} and policy['model_version'] == '2.0' and isinstance(policy['name'],str) and 0= policy['thresholds'][name]: return name return 'informational'