|
1 | | -"""Centralized configuration for django-postgres-anonymizer""" |
| 1 | +"""Simple configuration helpers for django-postgres-anonymizer""" |
2 | 2 |
|
3 | 3 | from django.conf import settings |
4 | 4 |
|
5 | 5 |
|
6 | | -class AnonConfig: |
7 | | - """Centralized configuration class for all anonymization settings""" |
| 6 | +def get_setting(key: str, default=None): |
| 7 | + """Get a setting from POSTGRES_ANON configuration with default fallback""" |
| 8 | + return getattr(settings, "POSTGRES_ANON", {}).get(key, default) |
8 | 9 |
|
9 | | - def __init__(self): |
10 | | - # Get the settings dict or use defaults |
11 | | - config = getattr(settings, "POSTGRES_ANON", {}) |
12 | 10 |
|
13 | | - # Set defaults |
14 | | - self._config = { |
15 | | - "DEFAULT_MASKED_ROLE": "masked_reader", |
16 | | - "MASKED_GROUP": "view_masked_data", |
17 | | - "ANONYMIZED_DATA_ROLE": "masked_reader", |
18 | | - "ENABLED": False, |
19 | | - "AUTO_APPLY_RULES": False, |
20 | | - "VALIDATE_FUNCTIONS": True, |
21 | | - "ALLOW_CUSTOM_FUNCTIONS": False, |
22 | | - "ENABLE_LOGGING": True, |
23 | | - } |
| 11 | +# Default values (moved from constants.py to keep config self-contained) |
| 12 | +DEFAULTS = { |
| 13 | + "DEFAULT_MASKED_ROLE": "masked_reader", |
| 14 | + "MASKED_GROUP": "view_masked_data", |
| 15 | + "ANONYMIZED_DATA_ROLE": "masked_reader", |
| 16 | + "ENABLED": False, |
| 17 | + "AUTO_APPLY_RULES": False, |
| 18 | + "VALIDATE_FUNCTIONS": True, |
| 19 | + "ALLOW_CUSTOM_FUNCTIONS": False, |
| 20 | + "ENABLE_LOGGING": True, |
| 21 | +} |
24 | 22 |
|
25 | | - # Override with user settings |
26 | | - self._config.update(config) |
27 | 23 |
|
28 | | - @property |
29 | | - def default_masked_role(self) -> str: |
30 | | - """Default role name for anonymized access""" |
31 | | - return self._config["DEFAULT_MASKED_ROLE"] |
32 | | - |
33 | | - @property |
34 | | - def masked_group(self) -> str: |
35 | | - """Group name for users who should see masked data""" |
36 | | - return self._config["MASKED_GROUP"] |
37 | | - |
38 | | - @property |
39 | | - def anonymized_data_role(self) -> str: |
40 | | - """Role for anonymized data context manager""" |
41 | | - return self._config["ANONYMIZED_DATA_ROLE"] |
42 | | - |
43 | | - @property |
44 | | - def enabled(self) -> bool: |
45 | | - """Whether anonymization is enabled""" |
46 | | - return self._config["ENABLED"] |
47 | | - |
48 | | - @property |
49 | | - def auto_apply_rules(self) -> bool: |
50 | | - """Whether to automatically apply rules when created""" |
51 | | - return self._config["AUTO_APPLY_RULES"] |
52 | | - |
53 | | - @property |
54 | | - def validate_functions(self) -> bool: |
55 | | - """Whether to validate anonymization functions""" |
56 | | - return self._config["VALIDATE_FUNCTIONS"] |
57 | | - |
58 | | - @property |
59 | | - def allow_custom_functions(self) -> bool: |
60 | | - """Whether to allow custom anonymization functions""" |
61 | | - return self._config["ALLOW_CUSTOM_FUNCTIONS"] |
62 | | - |
63 | | - @property |
64 | | - def enable_logging(self) -> bool: |
65 | | - """Whether to enable audit logging""" |
66 | | - return self._config["ENABLE_LOGGING"] |
67 | | - |
68 | | - |
69 | | -# Global configuration instance |
70 | | -anon_config = AnonConfig() |
| 24 | +def get_anon_setting(key: str): |
| 25 | + """Get anonymization setting with built-in default""" |
| 26 | + return get_setting(key, DEFAULTS.get(key)) |
0 commit comments