Loads the built-in TOML rules file from package resources. Substitutes the `__SHARED_PLACEHOLDERS__` sentinel inside any rule's exclude_pattern with the value of `[defaults].exclude_pattern_placeholder`, so the placeholder/dummy-secret regex lives in one place rather than being copy
(ai_scan: bool = False)
| 53 | return deepcopy(DEFAULT_CONFIG) |
| 54 | |
| 55 | def get_default_rules(ai_scan: bool = False) -> str: |
| 56 | """Loads the built-in TOML rules file from package resources. |
| 57 | |
| 58 | Substitutes the `__SHARED_PLACEHOLDERS__` sentinel inside any rule's |
| 59 | exclude_pattern with the value of `[defaults].exclude_pattern_placeholder`, |
| 60 | so the placeholder/dummy-secret regex lives in one place rather than being |
| 61 | copy-pasted across every format-specific rule. |
| 62 | """ |
| 63 | try: |
| 64 | base_rules = pkg_resources.files('pyspector.rules').joinpath('built-in-rules.toml').read_text(encoding='utf-8') |
| 65 | if ai_scan: |
| 66 | click.echo("[*] AI scanning enabled. Loading additional AI/LLM rules.") |
| 67 | ai_rules = pkg_resources.files('pyspector.rules').joinpath('built-in-rules-ai.toml').read_text(encoding='utf-8') |
| 68 | text = base_rules + "\n" + ai_rules |
| 69 | else: |
| 70 | text = base_rules |
| 71 | |
| 72 | # Inline shared placeholder regex into rule-level exclude_patterns |
| 73 | m = _PLACEHOLDER_KEY_RX.search(text) |
| 74 | if m and _PLACEHOLDER_SENTINEL in text: |
| 75 | text = text.replace(_PLACEHOLDER_SENTINEL, m.group(1)) |
| 76 | return text |
| 77 | except Exception as e: |
| 78 | raise FileNotFoundError(f"Could not load built-in-rules.toml from package data! Error: {e}") |
no outgoing calls