-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_example.py
More file actions
200 lines (173 loc) · 6.32 KB
/
config_example.py
File metadata and controls
200 lines (173 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Configuration example for data_masking.py v2.5.1
Demonstrates all available configuration options using dataclasses.
No external dependencies required — uses only Python standard library.
Author: Vladyslav V. Prodan
Contact: github.com/click0
Phone: +38(099)6053340
Version: 2.5.1
License: BSD 3-Clause "New" or "Revised" License
Year: 2025-2026
"""
from dataclasses import dataclass, field, asdict
from typing import List, Dict, Optional
# ============================================================================
# DATACLASS DEFINITIONS
# ============================================================================
@dataclass
class SystemConfig:
"""Системні налаштування."""
version: str = "v2.5.1"
hash_algorithm: str = "blake2b"
hash_digest_size: int = 8
encoding: str = "utf-8"
preserve_case: bool = True
backup_enabled: bool = True
backup_suffix: str = ".bak"
max_file_size_mb: int = 50
temp_dir: str = ""
debug_mode: bool = False
strict_mode: bool = False
@dataclass
class SecurityConfig:
"""Налаштування безпеки та шифрування."""
encrypt_output: bool = False
password_env_var: str = "DATA_MASKING_PASSWORD"
password_generation: dict = field(default_factory=lambda: {
"enabled": True,
"length": 24,
"use_special_chars": True,
"algorithm": "secrets",
"min_uppercase": 2,
"min_lowercase": 2,
"min_digits": 2,
"min_special": 2,
})
encryption_algorithm: str = "AES-128-CBC"
key_derivation: str = "scrypt"
scrypt_n: int = 2**14
scrypt_r: int = 8
scrypt_p: int = 1
salt_length: int = 16
auto_generate_password: bool = True
password_file: str = ""
secure_delete_temp: bool = True
@dataclass
class MaskingRulesConfig:
"""Налаштування правил маскування."""
enable_ranks: bool = True
enable_names: bool = True
enable_surnames: bool = True
enable_patronymics: bool = True
enable_ipn: bool = True
enable_passport: bool = True
enable_military_id: bool = True
enable_dates: bool = True
enable_date_text: bool = True
enable_units: bool = True
enable_brigades: bool = True
enable_orders: bool = True
enable_br_numbers: bool = True
enable_document_numbers: bool = True
preserve_case: bool = True
preserve_gender: bool = True
consistent_mapping: bool = True
instance_tracking: bool = True
context_aware: bool = True
rank_line_break_fix: bool = True
custom_patterns: List[str] = field(default_factory=list)
@dataclass
class ValidationConfig:
"""Налаштування валідації."""
validate_ipn_checksum: bool = True
validate_date_range: bool = True
min_date_year: int = 1900
max_date_year: int = 2030
validate_rank_dictionary: bool = True
strict_pib_format: bool = False
allow_abbreviated_patronymic: bool = True
max_name_length: int = 50
min_name_length: int = 2
@dataclass
class RouterRulesConfig:
"""Налаштування правил маршрутизації (порядок обробки)."""
default_action: str = "mask"
processing_order: List[str] = field(default_factory=lambda: [
"date_text",
"date",
"ipn",
"passport_id",
"military_id",
"order_number",
"brigade_number",
"rank",
"pib",
"military_unit",
])
skip_types: List[str] = field(default_factory=list)
only_types: List[str] = field(default_factory=list)
priority_overrides: Dict[str, int] = field(default_factory=dict)
@dataclass
class LoggingConfig:
"""Налаштування логування."""
enabled: bool = True
level: str = "INFO"
file: Optional[str] = None
format: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
max_log_size_mb: int = 10
log_rotation_count: int = 5
log_to_console: bool = True
log_to_file: bool = False
log_sensitive_data: bool = False
log_performance: bool = False
log_statistics: bool = True
@dataclass
class Config:
"""Головна конфігурація системи маскування даних.
Об'єднує всі секції конфігурації в єдину структуру.
"""
system: SystemConfig = field(default_factory=SystemConfig)
security: SecurityConfig = field(default_factory=SecurityConfig)
masking_rules: MaskingRulesConfig = field(default_factory=MaskingRulesConfig)
validation: ValidationConfig = field(default_factory=ValidationConfig)
router_rules: RouterRulesConfig = field(default_factory=RouterRulesConfig)
logging: LoggingConfig = field(default_factory=LoggingConfig)
def to_dict(self) -> dict:
"""Конвертує конфігурацію у словник.
Returns:
dict: Словникове представлення всіх параметрів конфігурації.
"""
return asdict(self)
# ============================================================================
# MAIN — друкує всі значення конфігурації
# ============================================================================
if __name__ == "__main__":
config = Config()
data = config.to_dict()
print("=" * 70)
print(" Data Masking Configuration Example v2.5.1")
print("=" * 70)
for section_name, section_data in data.items():
print(f"\n--- {section_name} ---")
if isinstance(section_data, dict):
for key, value in section_data.items():
if isinstance(value, dict):
print(f" {key}:")
for sub_key, sub_value in value.items():
print(f" {sub_key}: {sub_value}")
elif isinstance(value, list):
print(f" {key}:")
if value:
for item in value:
print(f" - {item}")
else:
print(" (empty)")
else:
print(f" {key}: {value}")
else:
print(f" {section_data}")
print("\n" + "=" * 70)
print(" Кінець конфігурації")
print("=" * 70)