cwyodmodules 0.3.77__py3-none-any.whl → 0.3.78__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,258 +1,416 @@
1
- """
2
- Azure Project Management Configuration Template
1
+ """Azure Project Management Configuration Template.
2
+
3
+ This module provides standardized configuration for Azure logging, identity management,
4
+ and Key Vault access across projects. It creates singleton instances that can be
5
+ imported and used throughout your application.
3
6
 
4
- This template provides standardized configuration for Azure logging and identity
5
- management across projects. It creates singleton instances of AzureLogger and
6
- AzureIdentity that can be imported and used throughout your application.
7
+ The configuration is driven by environment variables with sensible defaults, allowing
8
+ for flexible deployment across different environments (local development, staging,
9
+ production) without code changes.
10
+
11
+ Features:
12
+ - Automatic service detection (app vs function app)
13
+ - Configurable logging with Application Insights integration
14
+ - Azure identity management with token caching
15
+ - Key Vault integration for secrets, keys, and certificates
16
+ - Docker environment detection
17
+ - Local development environment setup
7
18
 
8
19
  Usage:
9
- from mgmt_config import logger, identity
20
+ Basic usage::
21
+
22
+ from mgmt_config import logger, identity
23
+
24
+ logger.info("Application started")
25
+ credential = identity.get_credential()
26
+
27
+ With Key Vault::
28
+
29
+ from mgmt_config import keyvault
30
+
31
+ if keyvault:
32
+ secret_value = keyvault.get_secret("my-secret")
33
+
34
+ Environment Variables:
35
+ Service Configuration:
36
+ REFLECTION_NAME: Service name for identification
37
+ REFLECTION_KIND: Service type (app, functionapp, etc.)
38
+ SERVICE_VERSION: Version of the service (default: "1.0.0")
39
+
40
+ Logging Configuration:
41
+ LOGGER_ENABLE_CONSOLE: Enable console logging (default: "true")
42
+ APPLICATIONINSIGHTS_CONNECTION_STRING: App Insights connection string
10
43
 
11
- logger.info("Application started")
12
- credential = identity.get_credential()
44
+ Identity Configuration:
45
+ IDENTITY_ENABLE_TOKEN_CACHE: Enable token caching (default: "true")
46
+ IDENTITY_ALLOW_UNENCRYPTED_STORAGE: Allow unencrypted token storage (default: "true")
47
+
48
+ Key Vault Configuration:
49
+ key_vault_uri: Primary Key Vault URL
50
+ head_key_vault_uri: Secondary Key Vault URL
51
+ KEYVAULT_ENABLE_SECRETS: Enable secrets client (default: "true")
52
+ KEYVAULT_ENABLE_KEYS: Enable keys client (default: "false")
53
+ KEYVAULT_ENABLE_CERTIFICATES: Enable certificates client (default: "false")
54
+
55
+ Examples:
56
+ Local Development:
57
+ Set REFLECTION_NAME and ensure .env file exists for local settings.
58
+
59
+ Azure Function App:
60
+ Set REFLECTION_KIND="functionapp" and REFLECTION_NAME to your function app name.
61
+
62
+ Web Application:
63
+ Set REFLECTION_KIND="app" (or leave default) and configure App Insights.
13
64
  """
14
65
 
15
66
  import os
16
- from typing import Optional, Dict, Any
17
- from azpaddypy.mgmt.logging import create_app_logger, create_function_logger
67
+ from typing import Any, Dict, Optional
68
+
18
69
  from azpaddypy.mgmt.identity import create_azure_identity
19
- from azpaddypy.resources.keyvault import create_azure_keyvault
20
70
  from azpaddypy.mgmt.local_env_manager import create_local_env_manager
21
-
22
- # Alias for import in other packages
71
+ from azpaddypy.mgmt.logging import create_app_logger, create_function_logger
72
+ from azpaddypy.resources.keyvault import create_azure_keyvault
23
73
 
24
74
  # =============================================================================
25
75
  # SERVICE CONFIGURATION
26
76
  # =============================================================================
27
77
 
28
- # Service identity - customize these for your project
29
- REFLECTION_NAME = os.getenv("REFLECTION_NAME")
30
- REFLECTION_KIND = os.getenv("REFLECTION_KIND")
31
- SERVICE_NAME = REFLECTION_NAME or str(__name__)
32
- SERVICE_VERSION = os.getenv("SERVICE_VERSION", "1.0.0")
33
-
34
- def is_running_in_docker():
78
+ def _get_service_configuration() -> tuple[str, str, str]:
79
+ """Get service configuration from environment variables.
80
+
81
+ Returns:
82
+ A tuple containing (service_name, service_version, service_kind).
83
+
84
+ Note:
85
+ REFLECTION_KIND has commas replaced with hyphens for compatibility.
35
86
  """
36
- Checks if the current process is running inside a Docker container.
87
+ reflection_name = os.getenv("REFLECTION_NAME")
88
+ reflection_kind = os.getenv("REFLECTION_KIND", "").replace(",", "-")
89
+ service_name = reflection_name or str(__name__)
90
+ service_version = os.getenv("SERVICE_VERSION", "1.0.0")
91
+
92
+ return service_name, service_version, reflection_kind
93
+
94
+
95
+ SERVICE_NAME, SERVICE_VERSION, REFLECTION_KIND = _get_service_configuration()
96
+
97
+ # =============================================================================
98
+ # DOCKER ENVIRONMENT DETECTION
99
+ # =============================================================================
100
+
101
+ def is_running_in_docker() -> bool:
102
+ """Check if the current process is running inside a Docker container.
103
+
104
+ This function uses multiple detection methods to reliably identify
105
+ Docker environments across different container runtimes and orchestrators.
37
106
 
38
107
  Returns:
39
- bool: True if running in Docker, False otherwise.
108
+ True if running in Docker/container, False otherwise.
109
+
110
+ Detection Methods:
111
+ 1. Check for /.dockerenv file (standard Docker indicator)
112
+ 2. Check /proc/1/cgroup for container-specific entries
113
+ 3. Handles various container runtimes (Docker, Kubernetes, etc.)
40
114
  """
41
- # Method 1: Check for /.dockerenv file
115
+ # Method 1: Check for Docker environment file
42
116
  if os.path.exists('/.dockerenv'):
43
117
  return True
44
118
 
45
- # Method 2: Check cgroup for "docker"
119
+ # Method 2: Check process control groups for container indicators
46
120
  try:
47
- with open('/proc/1/cgroup', 'rt') as f:
121
+ with open('/proc/1/cgroup', 'rt', encoding='utf-8') as f:
48
122
  cgroup_content = f.read()
49
- if 'docker' in cgroup_content or 'kubepods' in cgroup_content:
50
- return True
51
- except FileNotFoundError:
52
- # /proc/1/cgroup does not exist, not a Linux-like environment
53
- pass
54
- except Exception:
55
- # Handle other potential exceptions, e.g., permissions
123
+ return any(indicator in cgroup_content
124
+ for indicator in ['docker', 'kubepods', 'containerd'])
125
+ except (FileNotFoundError, PermissionError, OSError):
126
+ # /proc filesystem not available or accessible (e.g., Windows, macOS)
56
127
  pass
57
128
 
58
129
  return False
59
130
 
60
- running_in_docker = is_running_in_docker()
61
- print("is_running_in_docker: " + str(running_in_docker))
62
131
 
132
+ RUNNING_IN_DOCKER = is_running_in_docker()
133
+ print(f"is_running_in_docker: {RUNNING_IN_DOCKER}")
63
134
 
64
135
  # =============================================================================
65
- # LOGGING CONFIGURATION
136
+ # LOCAL DEVELOPMENT CONFIGURATION
66
137
  # =============================================================================
67
138
 
68
- # Enable console output (useful for local development)
69
- LOGGER_ENABLE_CONSOLE = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
139
+ def _get_local_settings() -> Dict[str, str]:
140
+ """Get local development settings based on environment.
141
+
142
+ Returns:
143
+ Dictionary of local development settings appropriate for the environment.
144
+
145
+ Note:
146
+ Docker environments get Azure service principal settings,
147
+ while local environments get Azure Storage Emulator settings.
148
+ """
149
+ if RUNNING_IN_DOCKER:
150
+ return {
151
+ "AZURE_CLIENT_ID": "aa73da4a-2888-4cb7-896e-5d51125f11f0",
152
+ "AZURE_TENANT_ID": "e5590d5d-336c-4cf5-b0ac-b79a598ec797",
153
+ "AZURE_CLIENT_SECRET": "IQ08Q~4uCfc4B~p2F95D2737GzYvvrtIjursFbCf"
154
+ }
155
+ else:
156
+ return {
157
+ "AzureWebJobsStorage": "UseDevelopmentStorage=true",
158
+ "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
159
+ "input_queue_connection__queueServiceUri": "UseDevelopmentStorage=true",
160
+ "AzureWebJobsStorage__accountName": "UseDevelopmentStorage=true",
161
+ "AzureWebJobsStorage__blobServiceUri": "UseDevelopmentStorage=true",
162
+ }
163
+
164
+
165
+ # Initialize local environment manager
166
+ local_env_manager = create_local_env_manager(
167
+ file_path=".env",
168
+ settings=_get_local_settings(),
169
+ override_json=True,
170
+ override_dotenv=True,
171
+ override_settings=True,
172
+ )
70
173
 
71
- # Application Insights connection string (optional, will use environment variable if not set)
72
- LOGGER_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
174
+ # =============================================================================
175
+ # LOGGING CONFIGURATION
176
+ # =============================================================================
73
177
 
74
- # Local development settings
75
- if running_in_docker:
76
- LOCAL_SETTINGS = {
77
- "AZURE_CLIENT_ID": "aa73da4a-2888-4cb7-896e-5d51125f11f0",
78
- "AZURE_TENANT_ID": "e5590d5d-336c-4cf5-b0ac-b79a598ec797",
79
- "AZURE_CLIENT_SECRET": "IQ08Q~4uCfc4B~p2F95D2737GzYvvrtIjursFbCf"
80
- }
81
- else:
82
- LOCAL_SETTINGS = {
83
- "AzureWebJobsStorage": "UseDevelopmentStorage=true",
84
- "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
85
- "input_queue_connection__queueServiceUri": "UseDevelopmentStorage=true",
86
- "AzureWebJobsStorage__accountName": "UseDevelopmentStorage=true",
87
- "AzureWebJobsStorage__blobServiceUri": "UseDevelopmentStorage=true",
178
+ def _get_logging_configuration() -> tuple[bool, Optional[str], Dict[str, Dict[str, bool]]]:
179
+ """Get logging configuration from environment variables.
180
+
181
+ Returns:
182
+ A tuple containing (console_enabled, connection_string, instrumentation_options).
183
+ """
184
+ console_enabled = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
185
+ connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
186
+
187
+ instrumentation_options = {
188
+ "azure_sdk": {"enabled": True},
189
+ "django": {"enabled": False},
190
+ "fastapi": {"enabled": False},
191
+ "flask": {"enabled": True},
192
+ "psycopg2": {"enabled": True},
193
+ "requests": {"enabled": True},
194
+ "urllib": {"enabled": True},
195
+ "urllib3": {"enabled": True},
88
196
  }
197
+
198
+ return console_enabled, connection_string, instrumentation_options
89
199
 
90
- # Configure which Azure SDK components to instrument
91
- LOGGER_INSTRUMENTATION_OPTIONS = {
92
- "azure_sdk": {"enabled": True},
93
- "django": {"enabled": False},
94
- "fastapi": {"enabled": False},
95
- "flask": {"enabled": True},
96
- "psycopg2": {"enabled": True},
97
- "requests": {"enabled": True},
98
- "urllib": {"enabled": True},
99
- "urllib3": {"enabled": True},
100
- }
200
+
201
+ LOGGER_ENABLE_CONSOLE, LOGGER_CONNECTION_STRING, LOGGER_INSTRUMENTATION_OPTIONS = _get_logging_configuration()
101
202
 
102
203
  # =============================================================================
103
204
  # IDENTITY CONFIGURATION
104
205
  # =============================================================================
105
206
 
106
- # Token caching settings
107
- IDENTITY_ENABLE_TOKEN_CACHE = os.getenv("IDENTITY_ENABLE_TOKEN_CACHE", "true").lower() == "true"
108
- IDENTITY_ALLOW_UNENCRYPTED_STORAGE = os.getenv("IDENTITY_ALLOW_UNENCRYPTED_STORAGE", "true").lower() == "true"
207
+ def _get_identity_configuration() -> tuple[bool, bool, Optional[Dict[str, Any]], Optional[str]]:
208
+ """Get identity configuration from environment variables.
209
+
210
+ Returns:
211
+ A tuple containing (token_cache_enabled, unencrypted_storage_allowed,
212
+ custom_options, connection_string).
213
+ """
214
+ token_cache_enabled = os.getenv("IDENTITY_ENABLE_TOKEN_CACHE", "true").lower() == "true"
215
+ unencrypted_storage_allowed = os.getenv("IDENTITY_ALLOW_UNENCRYPTED_STORAGE", "true").lower() == "true"
216
+ custom_options = None # Reserved for future custom credential configuration
217
+ connection_string = LOGGER_CONNECTION_STRING # Share with logger by default
218
+
219
+ return token_cache_enabled, unencrypted_storage_allowed, custom_options, connection_string
109
220
 
110
- # Custom credential options (None means use defaults)
111
- IDENTITY_CUSTOM_CREDENTIAL_OPTIONS: Optional[Dict[str, Any]] = None
112
221
 
113
- # Connection string for identity logging (uses same as logger by default)
114
- IDENTITY_CONNECTION_STRING = LOGGER_CONNECTION_STRING
222
+ (IDENTITY_ENABLE_TOKEN_CACHE,
223
+ IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
224
+ IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
225
+ IDENTITY_CONNECTION_STRING) = _get_identity_configuration()
115
226
 
116
227
  # =============================================================================
117
- # KEYVAULT CONFIGURATION
228
+ # KEY VAULT CONFIGURATION
118
229
  # =============================================================================
119
230
 
120
- # Enable specific Key Vault client types
121
- KEYVAULT_ENABLE_SECRETS = os.getenv("KEYVAULT_ENABLE_SECRETS", "true").lower() == "true"
122
- KEYVAULT_ENABLE_KEYS = os.getenv("KEYVAULT_ENABLE_KEYS", "false").lower() == "true"
123
- KEYVAULT_ENABLE_CERTIFICATES = os.getenv("KEYVAULT_ENABLE_CERTIFICATES", "false").lower() == "true"
231
+ def _get_keyvault_configuration() -> tuple[Optional[str], Optional[str], bool, bool, bool, Optional[str]]:
232
+ """Get Key Vault configuration from environment variables.
233
+
234
+ Returns:
235
+ A tuple containing (vault_url, head_vault_url, secrets_enabled,
236
+ keys_enabled, certificates_enabled, connection_string).
237
+ """
238
+ vault_url = os.getenv("key_vault_uri")
239
+ head_vault_url = os.getenv("head_key_vault_uri")
240
+ secrets_enabled = os.getenv("KEYVAULT_ENABLE_SECRETS", "true").lower() == "true"
241
+ keys_enabled = os.getenv("KEYVAULT_ENABLE_KEYS", "false").lower() == "true"
242
+ certificates_enabled = os.getenv("KEYVAULT_ENABLE_CERTIFICATES", "false").lower() == "true"
243
+ connection_string = LOGGER_CONNECTION_STRING # Share with logger by default
244
+
245
+ return vault_url, head_vault_url, secrets_enabled, keys_enabled, certificates_enabled, connection_string
246
+
124
247
 
125
- # Connection string for keyvault logging (uses same as logger by default)
126
- KEYVAULT_CONNECTION_STRING = LOGGER_CONNECTION_STRING
248
+ (KEYVAULT_URL,
249
+ HEAD_KEYVAULT_URL,
250
+ KEYVAULT_ENABLE_SECRETS,
251
+ KEYVAULT_ENABLE_KEYS,
252
+ KEYVAULT_ENABLE_CERTIFICATES,
253
+ KEYVAULT_CONNECTION_STRING) = _get_keyvault_configuration()
127
254
 
128
255
  # =============================================================================
129
- # INITIALIZE SERVICES
256
+ # SERVICE INITIALIZATION
130
257
  # =============================================================================
131
258
 
132
- # Create logger instance
133
- if "functionapp" in os.getenv("REFLECTION_KIND", "app"):
134
- logger = create_function_logger(
135
- function_app_name=REFLECTION_NAME,
136
- function_name=REFLECTION_KIND,
137
- service_version=SERVICE_VERSION,
138
- connection_string=LOGGER_CONNECTION_STRING,
139
- instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
140
- )
141
- logger.info("Function logger: " + str(REFLECTION_KIND) + " " + str(REFLECTION_NAME) + " initialized")
142
- else:
143
- logger = create_app_logger(
144
- service_name=SERVICE_NAME,
145
- service_version=SERVICE_VERSION,
146
- connection_string=LOGGER_CONNECTION_STRING,
147
- enable_console_logging=LOGGER_ENABLE_CONSOLE,
148
- instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
149
- )
150
- logger.info("App logger: " + str(REFLECTION_KIND) + " " + str(REFLECTION_NAME) + " initialized")
151
-
152
- # Create local development settings instance
153
- local_env_manager = create_local_env_manager(
154
- file_path=".env",
155
- settings=LOCAL_SETTINGS,
156
- logger=logger,
157
- override_json=True,
158
- override_dotenv=True,
159
- override_settings=True,
160
- )
161
-
162
- # Create identity instance with shared logger
163
- identity = create_azure_identity(
164
- service_name=SERVICE_NAME,
165
- service_version=SERVICE_VERSION,
166
- enable_token_cache=IDENTITY_ENABLE_TOKEN_CACHE,
167
- allow_unencrypted_storage=IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
168
- custom_credential_options=IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
169
- connection_string=IDENTITY_CONNECTION_STRING,
170
- logger=logger,
171
- )
259
+ def _create_logger():
260
+ """Create and configure the appropriate logger instance.
261
+
262
+ Returns:
263
+ Configured AzureLogger instance (either app or function logger).
264
+
265
+ Note:
266
+ Logger type is determined by REFLECTION_KIND environment variable.
267
+ Function apps get specialized function loggers with additional context.
268
+ """
269
+ if "functionapp" in REFLECTION_KIND:
270
+ logger_instance = create_function_logger(
271
+ function_app_name=SERVICE_NAME,
272
+ function_name=REFLECTION_KIND,
273
+ service_version=SERVICE_VERSION,
274
+ connection_string=LOGGER_CONNECTION_STRING,
275
+ instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
276
+ )
277
+ logger_instance.info(
278
+ f"Function logger initialized: {REFLECTION_KIND} {SERVICE_NAME}",
279
+ extra={"logger_type": "function", "function_name": REFLECTION_KIND}
280
+ )
281
+ else:
282
+ logger_instance = create_app_logger(
283
+ service_name=SERVICE_NAME,
284
+ service_version=SERVICE_VERSION,
285
+ connection_string=LOGGER_CONNECTION_STRING,
286
+ enable_console_logging=LOGGER_ENABLE_CONSOLE,
287
+ instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
288
+ )
289
+ logger_instance.info(
290
+ f"App logger initialized: {REFLECTION_KIND} {SERVICE_NAME}",
291
+ extra={"logger_type": "app", "service_kind": REFLECTION_KIND}
292
+ )
293
+
294
+ return logger_instance
172
295
 
173
- # Azure Key Vault URL (required for Key Vault operations)
174
- KEYVAULT_URL = os.getenv("key_vault_uri")
175
- HEAD_KEYVAULT_URL = os.getenv("head_key_vault_uri")
176
296
 
177
- # Create keyvault instance with shared logger and identity (if URL is configured)
178
- keyvault = None
179
- if KEYVAULT_URL:
180
- keyvault = create_azure_keyvault(
181
- vault_url=KEYVAULT_URL,
182
- azure_identity=identity,
297
+ def _create_identity_manager(logger_instance):
298
+ """Create and configure the Azure identity manager.
299
+
300
+ Args:
301
+ logger_instance: Shared logger instance for identity operations.
302
+
303
+ Returns:
304
+ Configured AzureIdentity instance.
305
+ """
306
+ return create_azure_identity(
183
307
  service_name=SERVICE_NAME,
184
308
  service_version=SERVICE_VERSION,
185
- logger=logger,
186
- connection_string=KEYVAULT_CONNECTION_STRING,
187
- enable_secrets=KEYVAULT_ENABLE_SECRETS,
188
- enable_keys=KEYVAULT_ENABLE_KEYS,
189
- enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
309
+ enable_token_cache=IDENTITY_ENABLE_TOKEN_CACHE,
310
+ allow_unencrypted_storage=IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
311
+ custom_credential_options=IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
312
+ connection_string=IDENTITY_CONNECTION_STRING,
313
+ logger=logger_instance,
190
314
  )
191
315
 
192
- head_keyvault = None
193
- if HEAD_KEYVAULT_URL:
194
- head_keyvault = create_azure_keyvault(
195
- vault_url=HEAD_KEYVAULT_URL,
196
- azure_identity=identity,
316
+
317
+ def _create_keyvault_client(vault_url: str, identity_instance, logger_instance):
318
+ """Create a Key Vault client for the specified vault.
319
+
320
+ Args:
321
+ vault_url: Azure Key Vault URL.
322
+ identity_instance: Shared identity manager.
323
+ logger_instance: Shared logger instance.
324
+
325
+ Returns:
326
+ Configured AzureKeyVault instance or None if creation fails.
327
+ """
328
+ if not vault_url:
329
+ return None
330
+
331
+ return create_azure_keyvault(
332
+ vault_url=vault_url,
333
+ azure_identity=identity_instance,
197
334
  service_name=SERVICE_NAME,
198
335
  service_version=SERVICE_VERSION,
199
- logger=logger,
336
+ logger=logger_instance,
200
337
  connection_string=KEYVAULT_CONNECTION_STRING,
201
338
  enable_secrets=KEYVAULT_ENABLE_SECRETS,
202
339
  enable_keys=KEYVAULT_ENABLE_KEYS,
203
340
  enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
204
341
  )
205
342
 
206
- # =============================================================================
207
- # VALIDATION & STARTUP
208
- # =============================================================================
209
343
 
210
- # Validate critical configuration
211
- if SERVICE_NAME == __name__:
212
- logger.warning(
213
- "SERVICE_NAME is not configured. Please set SERVICE_NAME environment variable or update this template.",
214
- extra={"configuration_issue": "service_name_not_set"}
215
- )
344
+ # Initialize core services
345
+ logger = _create_logger()
346
+ identity = _create_identity_manager(logger)
216
347
 
217
- if not LOGGER_CONNECTION_STRING:
218
- logger.info(
219
- "No Application Insights connection string configured. Telemetry will be disabled.",
220
- extra={"telemetry_status": "disabled"}
221
- )
348
+ # Initialize Key Vault clients (if URLs are configured)
349
+ keyvault = _create_keyvault_client(KEYVAULT_URL, identity, logger)
350
+ head_keyvault = _create_keyvault_client(HEAD_KEYVAULT_URL, identity, logger)
222
351
 
223
- if not KEYVAULT_URL:
224
- logger.info(
225
- "No Key Vault URL configured. Key Vault operations will be disabled.",
226
- extra={"keyvault_status": "disabled"}
227
- )
352
+ # =============================================================================
353
+ # CONFIGURATION VALIDATION & STARTUP LOGGING
354
+ # =============================================================================
228
355
 
229
- if not HEAD_KEYVAULT_URL:
356
+ def _validate_and_log_configuration():
357
+ """Validate configuration and log startup information.
358
+
359
+ This function performs validation checks and logs important configuration
360
+ status information for debugging and monitoring purposes.
361
+ """
362
+ # Validate critical configuration
363
+ if SERVICE_NAME == __name__:
364
+ logger.warning(
365
+ "SERVICE_NAME is using module name. Consider setting REFLECTION_NAME environment variable.",
366
+ extra={"configuration_issue": "service_name_not_set", "current_name": SERVICE_NAME}
367
+ )
368
+
369
+ # Log telemetry status
370
+ if not LOGGER_CONNECTION_STRING:
371
+ logger.info(
372
+ "No Application Insights connection string configured. Telemetry will be disabled.",
373
+ extra={"telemetry_status": "disabled"}
374
+ )
375
+
376
+ # Log Key Vault status
377
+ if not KEYVAULT_URL:
378
+ logger.info(
379
+ "No Key Vault URL configured. Key Vault operations will be disabled.",
380
+ extra={"keyvault_status": "disabled"}
381
+ )
382
+
383
+ if not HEAD_KEYVAULT_URL:
384
+ logger.info(
385
+ "No Head Key Vault URL configured. Head Key Vault operations will be disabled.",
386
+ extra={"head_keyvault_status": "disabled"}
387
+ )
388
+
389
+ # Log successful initialization with comprehensive metadata
230
390
  logger.info(
231
- "No Head Key Vault URL configured. Head Key Vault operations will be disabled.",
232
- extra={"head_keyvault_status": "disabled"}
391
+ f"Management configuration initialized for service '{SERVICE_NAME}' v{SERVICE_VERSION}",
392
+ extra={
393
+ "service_name": SERVICE_NAME,
394
+ "service_version": SERVICE_VERSION,
395
+ "console_logging": LOGGER_ENABLE_CONSOLE,
396
+ "token_cache_enabled": IDENTITY_ENABLE_TOKEN_CACHE,
397
+ "telemetry_enabled": bool(LOGGER_CONNECTION_STRING),
398
+ "keyvault_enabled": bool(KEYVAULT_URL),
399
+ "head_keyvault_enabled": bool(HEAD_KEYVAULT_URL),
400
+ "keyvault_secrets_enabled": KEYVAULT_ENABLE_SECRETS if KEYVAULT_URL else False,
401
+ "keyvault_keys_enabled": KEYVAULT_ENABLE_KEYS if KEYVAULT_URL else False,
402
+ "keyvault_certificates_enabled": KEYVAULT_ENABLE_CERTIFICATES if KEYVAULT_URL else False,
403
+ "running_in_docker": RUNNING_IN_DOCKER,
404
+ }
233
405
  )
234
406
 
235
- # Log successful initialization
236
- logger.info(
237
- f"Management configuration initialized for service '{SERVICE_NAME}' v{SERVICE_VERSION}",
238
- extra={
239
- "service_name": SERVICE_NAME,
240
- "service_version": SERVICE_VERSION,
241
- "console_logging": LOGGER_ENABLE_CONSOLE,
242
- "token_cache_enabled": IDENTITY_ENABLE_TOKEN_CACHE,
243
- "telemetry_enabled": bool(LOGGER_CONNECTION_STRING),
244
- "keyvault_enabled": bool(KEYVAULT_URL),
245
- "head_keyvault_enabled": bool(HEAD_KEYVAULT_URL),
246
- "keyvault_secrets_enabled": KEYVAULT_ENABLE_SECRETS if KEYVAULT_URL else False,
247
- "keyvault_keys_enabled": KEYVAULT_ENABLE_KEYS if KEYVAULT_URL else False,
248
- "keyvault_certificates_enabled": KEYVAULT_ENABLE_CERTIFICATES if KEYVAULT_URL else False,
249
- "running_in_docker": running_in_docker,
250
- }
251
- )
407
+
408
+ # Perform validation and startup logging
409
+ _validate_and_log_configuration()
252
410
 
253
411
  # =============================================================================
254
- # EXPORTS
412
+ # MODULE EXPORTS
255
413
  # =============================================================================
256
414
 
257
- # Export logger, identity, and keyvault for use in applications
415
+ # Export primary service instances for application use
258
416
  __all__ = ["logger", "local_env_manager", "identity", "keyvault", "head_keyvault"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cwyodmodules
3
- Version: 0.3.77
3
+ Version: 0.3.78
4
4
  Summary: Add your description here
5
5
  Author-email: Patrik <patrikhartl@gmail.com>
6
6
  Classifier: Operating System :: OS Independent
@@ -40,7 +40,7 @@ Requires-Dist: azure-search-documents==11.6.0b4
40
40
  Requires-Dist: semantic-kernel==1.3.0
41
41
  Requires-Dist: pydantic==2.7.4
42
42
  Requires-Dist: pandas>=2.2.3
43
- Requires-Dist: azpaddypy>=0.5.5
43
+ Requires-Dist: azpaddypy>=0.5.6
44
44
  Dynamic: license-file
45
45
 
46
46
  # paddypy
@@ -1,5 +1,5 @@
1
1
  cwyodmodules/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
2
- cwyodmodules/mgmt_config.py,sha256=5dzqIQDWv9X4Rk0UYlaPxMGyXHcw38LnanFxxfAEFn4,10185
2
+ cwyodmodules/mgmt_config.py,sha256=Q4mjZzhbTCzSsxahIvyFsfi4KXJjvvQnL5HLVr71nks,16776
3
3
  cwyodmodules/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  cwyodmodules/api/chat_history.py,sha256=bVXFmhTHIfEiHv_nBrfizO-cQRHhKgrdcZ07OD1b0Tw,20683
5
5
  cwyodmodules/batch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -109,8 +109,8 @@ cwyodmodules/graphrag/query/generate.py,sha256=BZiB6iw7PkIovw-CyYFogMHnDxK0Qu_4u
109
109
  cwyodmodules/graphrag/query/graph_search.py,sha256=95h3ecSWx4864XgKABtG0fh3Nk8HkqJVzoCrO8daJ-Y,7724
110
110
  cwyodmodules/graphrag/query/types.py,sha256=1Iq1dp4I4a56_cuFjOZ0NTgd0A2_MpVFznp_czgt6cI,617
111
111
  cwyodmodules/graphrag/query/vector_search.py,sha256=9Gwu9LPjtoAYUU8WKqCvbCHAIg3dpk71reoYd1scLnQ,1807
112
- cwyodmodules-0.3.77.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
113
- cwyodmodules-0.3.77.dist-info/METADATA,sha256=01PMVtALsE7-N-Jaa8jL-cslSVzkwtWgYO5K2K8VTio,2002
114
- cwyodmodules-0.3.77.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
115
- cwyodmodules-0.3.77.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
116
- cwyodmodules-0.3.77.dist-info/RECORD,,
112
+ cwyodmodules-0.3.78.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
113
+ cwyodmodules-0.3.78.dist-info/METADATA,sha256=O7_6qxnbZI3ZGyuo-81smZwiDHZlgCWea37ZfAfSRNA,2002
114
+ cwyodmodules-0.3.78.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
115
+ cwyodmodules-0.3.78.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
116
+ cwyodmodules-0.3.78.dist-info/RECORD,,