|
17 | 17 | logger = logging.getLogger(__name__) |
18 | 18 | logger.setLevel(logging.INFO) |
19 | 19 |
|
20 | | -PCI_DSS_CRE_SIMILARITY_THRESHOLDS: tuple[float, ...] = tuple( |
21 | | - float(part.strip()) |
22 | | - for part in os.environ.get( |
23 | | - "PCI_DSS_CRE_SIMILARITY_THRESHOLDS", "0.55,0.45,0.35" |
24 | | - ).split(",") |
25 | | - if part.strip() |
| 20 | +_DEFAULT_PCI_DSS_CRE_SIMILARITY_THRESHOLDS = (0.55, 0.45, 0.35) |
| 21 | +_DEFAULT_PCI_BRIDGE_STANDARDS = ("NIST 800-53 v5", "ISO 27001", "ASVS", "CWE") |
| 22 | +_DEFAULT_PCI_BRIDGE_MIN_SIMILARITY = 0.4 |
| 23 | + |
| 24 | + |
| 25 | +def _parse_float_env(name: str, default: float) -> float: |
| 26 | + raw = os.environ.get(name, "").strip() |
| 27 | + if not raw: |
| 28 | + return default |
| 29 | + try: |
| 30 | + return float(raw) |
| 31 | + except ValueError: |
| 32 | + logger.warning("Invalid %s=%r; using default %s", name, raw, default) |
| 33 | + return default |
| 34 | + |
| 35 | + |
| 36 | +def _parse_float_tuple_env(name: str, default: tuple[float, ...]) -> tuple[float, ...]: |
| 37 | + raw = os.environ.get(name, "").strip() |
| 38 | + if not raw: |
| 39 | + return default |
| 40 | + try: |
| 41 | + values = tuple(float(part.strip()) for part in raw.split(",") if part.strip()) |
| 42 | + except ValueError: |
| 43 | + logger.warning("Invalid %s=%r; using defaults %s", name, raw, default) |
| 44 | + return default |
| 45 | + return values or default |
| 46 | + |
| 47 | + |
| 48 | +def _parse_str_tuple_env(name: str, default: tuple[str, ...]) -> tuple[str, ...]: |
| 49 | + raw = os.environ.get(name, "").strip() |
| 50 | + if not raw: |
| 51 | + return default |
| 52 | + values = tuple(part.strip() for part in raw.split(",") if part.strip()) |
| 53 | + return values or default |
| 54 | + |
| 55 | + |
| 56 | +PCI_DSS_CRE_SIMILARITY_THRESHOLDS = _parse_float_tuple_env( |
| 57 | + "PCI_DSS_CRE_SIMILARITY_THRESHOLDS", _DEFAULT_PCI_DSS_CRE_SIMILARITY_THRESHOLDS |
26 | 58 | ) |
27 | | -PCI_BRIDGE_STANDARDS: tuple[str, ...] = tuple( |
28 | | - part.strip() |
29 | | - for part in os.environ.get( |
30 | | - "PCI_DSS_BRIDGE_STANDARDS", |
31 | | - "NIST 800-53 v5,ISO 27001,ASVS,CWE", |
32 | | - ).split(",") |
33 | | - if part.strip() |
| 59 | +PCI_BRIDGE_STANDARDS = _parse_str_tuple_env( |
| 60 | + "PCI_DSS_BRIDGE_STANDARDS", _DEFAULT_PCI_BRIDGE_STANDARDS |
34 | 61 | ) |
35 | | -PCI_BRIDGE_MIN_SIMILARITY = float( |
36 | | - os.environ.get("PCI_DSS_BRIDGE_MIN_SIMILARITY", "0.4") |
| 62 | +PCI_BRIDGE_MIN_SIMILARITY = _parse_float_env( |
| 63 | + "PCI_DSS_BRIDGE_MIN_SIMILARITY", _DEFAULT_PCI_BRIDGE_MIN_SIMILARITY |
37 | 64 | ) |
38 | 65 |
|
39 | 66 |
|
@@ -119,9 +146,7 @@ def resolve_cre_for_pci_control( |
119 | 146 | return cre |
120 | 147 |
|
121 | 148 | for standard_name in PCI_BRIDGE_STANDARDS: |
122 | | - cre = best_cre_via_bridge_standard( |
123 | | - cache, control_embedding, standard_name |
124 | | - ) |
| 149 | + cre = best_cre_via_bridge_standard(cache, control_embedding, standard_name) |
125 | 150 | if cre: |
126 | 151 | return cre |
127 | 152 |
|
|
0 commit comments