cwyodmodules 0.3.77__tar.gz → 0.3.79__tar.gz

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.
Files changed (124) hide show
  1. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/PKG-INFO +2 -2
  2. cwyodmodules-0.3.79/cwyodmodules/mgmt_config.py +423 -0
  3. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules.egg-info/PKG-INFO +2 -2
  4. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules.egg-info/requires.txt +1 -1
  5. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/pyproject.toml +2 -2
  6. cwyodmodules-0.3.77/cwyodmodules/mgmt_config.py +0 -258
  7. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/LICENSE +0 -0
  8. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/README.md +0 -0
  9. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/__init__.py +0 -0
  10. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/api/__init__.py +0 -0
  11. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/api/chat_history.py +0 -0
  12. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/__init__.py +0 -0
  13. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/__init__.py +0 -0
  14. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/auth_utils.py +0 -0
  15. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/cosmosdb.py +0 -0
  16. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/database_client_base.py +0 -0
  17. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/database_factory.py +0 -0
  18. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/postgresdbservice.py +0 -0
  19. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/chat_history/sample_user.py +0 -0
  20. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/common/__init__.py +0 -0
  21. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/common/answer.py +0 -0
  22. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/common/source_document.py +0 -0
  23. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/__init__.py +0 -0
  24. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/chunking_strategy.py +0 -0
  25. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/document_chunking_base.py +0 -0
  26. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/fixed_size_overlap.py +0 -0
  27. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/layout.py +0 -0
  28. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/page.py +0 -0
  29. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/paragraph.py +0 -0
  30. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_chunking/strategies.py +0 -0
  31. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/__init__.py +0 -0
  32. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/document_loading_base.py +0 -0
  33. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/layout.py +0 -0
  34. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/read.py +0 -0
  35. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/strategies.py +0 -0
  36. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/web.py +0 -0
  37. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/document_loading/word_document.py +0 -0
  38. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/__init__.py +0 -0
  39. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_blob_storage_client.py +0 -0
  40. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_computer_vision_client.py +0 -0
  41. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_form_recognizer_helper.py +0 -0
  42. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_postgres_helper.py +0 -0
  43. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_postgres_helper_light_rag.py +0 -0
  44. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/azure_search_helper.py +0 -0
  45. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/agent_mode.py +0 -0
  46. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/assistant_strategy.py +0 -0
  47. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/config_helper.py +0 -0
  48. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/conversation_flow.py +0 -0
  49. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/database_type.py +0 -0
  50. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/default.json +0 -0
  51. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/default_contract_assistant_prompt.txt +0 -0
  52. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/default_employee_assistant_prompt.txt +0 -0
  53. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/config/embedding_config.py +0 -0
  54. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/document_chunking_helper.py +0 -0
  55. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/document_loading_helper.py +0 -0
  56. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/embedders/embedder_base.py +0 -0
  57. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/embedders/embedder_factory.py +0 -0
  58. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/embedders/integrated_vectorization_embedder.py +0 -0
  59. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/embedders/postgres_embedder.py +0 -0
  60. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/embedders/push_embedder.py +0 -0
  61. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/env_helper.py +0 -0
  62. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/lightrag_helper.py +0 -0
  63. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/llm_helper.py +0 -0
  64. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/helpers/orchestrator_helper.py +0 -0
  65. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/integrated_vectorization/azure_search_datasource.py +0 -0
  66. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/integrated_vectorization/azure_search_index.py +0 -0
  67. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/integrated_vectorization/azure_search_indexer.py +0 -0
  68. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/integrated_vectorization/azure_search_skillset.py +0 -0
  69. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/loggers/conversation_logger.py +0 -0
  70. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/__init__.py +0 -0
  71. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/lang_chain_agent.py +0 -0
  72. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/open_ai_functions.py +0 -0
  73. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/orchestration_strategy.py +0 -0
  74. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/orchestrator_base.py +0 -0
  75. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/prompt_flow.py +0 -0
  76. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/semantic_kernel_orchestrator.py +0 -0
  77. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/orchestrator/strategies.py +0 -0
  78. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/parser/__init__.py +0 -0
  79. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/parser/output_parser_tool.py +0 -0
  80. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/parser/parser_base.py +0 -0
  81. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/plugins/chat_plugin.py +0 -0
  82. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/plugins/outlook_calendar_plugin.py +0 -0
  83. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/plugins/post_answering_plugin.py +0 -0
  84. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/azure_search_handler.py +0 -0
  85. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/azure_search_handler_light_rag.py +0 -0
  86. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/integrated_vectorization_search_handler.py +0 -0
  87. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/lightrag_search_handler.py +0 -0
  88. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/postgres_search_handler.py +0 -0
  89. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/postgres_search_handler_light_rag.py +0 -0
  90. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/search.py +0 -0
  91. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/search/search_handler_base.py +0 -0
  92. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/__init__.py +0 -0
  93. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/answer_processing_base.py +0 -0
  94. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/answering_tool_base.py +0 -0
  95. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/content_safety_checker.py +0 -0
  96. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/post_prompt_tool.py +0 -0
  97. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/question_answer_tool.py +0 -0
  98. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/batch/utilities/tools/text_processing_tool.py +0 -0
  99. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/__init__.py +0 -0
  100. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/config.py +0 -0
  101. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/database/__init__.py +0 -0
  102. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/database/base.py +0 -0
  103. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/database/models.py +0 -0
  104. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/__init__.py +0 -0
  105. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/chunking.py +0 -0
  106. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/extraction.py +0 -0
  107. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/types.py +0 -0
  108. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/upsert.py +0 -0
  109. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/indexing/utils.py +0 -0
  110. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/llm/__init__.py +0 -0
  111. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/llm/llm.py +0 -0
  112. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/llm/prompt.py +0 -0
  113. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/main.py +0 -0
  114. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/query/__init__.py +0 -0
  115. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/query/generate.py +0 -0
  116. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/query/graph_search.py +0 -0
  117. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/query/types.py +0 -0
  118. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules/graphrag/query/vector_search.py +0 -0
  119. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules.egg-info/SOURCES.txt +0 -0
  120. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules.egg-info/dependency_links.txt +0 -0
  121. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/cwyodmodules.egg-info/top_level.txt +0 -0
  122. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/setup.cfg +0 -0
  123. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/tests/test_api.py +0 -0
  124. {cwyodmodules-0.3.77 → cwyodmodules-0.3.79}/tests/test_batch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cwyodmodules
3
- Version: 0.3.77
3
+ Version: 0.3.79
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.7
44
44
  Dynamic: license-file
45
45
 
46
46
  # paddypy
@@ -0,0 +1,423 @@
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.
6
+
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
18
+
19
+ Usage:
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
43
+
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.
64
+ """
65
+
66
+ import os
67
+ from typing import Any, Dict, Optional
68
+
69
+ from azpaddypy.mgmt.identity import create_azure_identity
70
+ from azpaddypy.mgmt.local_env_manager import create_local_env_manager
71
+ from azpaddypy.mgmt.logging import create_app_logger, create_function_logger
72
+ from azpaddypy.resources.keyvault import create_azure_keyvault
73
+
74
+
75
+ # =============================================================================
76
+ # DOCKER ENVIRONMENT DETECTION
77
+ # =============================================================================
78
+
79
+ def is_running_in_docker() -> bool:
80
+ """Check if the current process is running inside a Docker container.
81
+
82
+ This function uses multiple detection methods to reliably identify
83
+ Docker environments across different container runtimes and orchestrators.
84
+
85
+ Returns:
86
+ True if running in Docker/container, False otherwise.
87
+
88
+ Detection Methods:
89
+ 1. Check for /.dockerenv file (standard Docker indicator)
90
+ 2. Check /proc/1/cgroup for container-specific entries
91
+ 3. Handles various container runtimes (Docker, Kubernetes, etc.)
92
+ """
93
+ # Method 1: Check for Docker environment file
94
+ if os.path.exists('/.dockerenv'):
95
+ return True
96
+
97
+ # Method 2: Check process control groups for container indicators
98
+ try:
99
+ with open('/proc/1/cgroup', 'rt', encoding='utf-8') as f:
100
+ cgroup_content = f.read()
101
+ return any(indicator in cgroup_content
102
+ for indicator in ['docker', 'kubepods', 'containerd'])
103
+ except (FileNotFoundError, PermissionError, OSError):
104
+ # /proc filesystem not available or accessible (e.g., Windows, macOS)
105
+ pass
106
+
107
+ return False
108
+
109
+
110
+ RUNNING_IN_DOCKER = is_running_in_docker()
111
+ print(f"is_running_in_docker: {RUNNING_IN_DOCKER}")
112
+
113
+ # =============================================================================
114
+ # LOCAL DEVELOPMENT CONFIGURATION
115
+ # =============================================================================
116
+
117
+ def _get_local_settings() -> Dict[str, str]:
118
+ """Get local development settings based on environment.
119
+
120
+ Returns:
121
+ Dictionary of local development settings appropriate for the environment.
122
+
123
+ Note:
124
+ Docker environments get Azure service principal settings,
125
+ while local environments get Azure Storage Emulator settings.
126
+ """
127
+ if RUNNING_IN_DOCKER:
128
+ return {
129
+ "AZURE_CLIENT_ID": "aa73da4a-2888-4cb7-896e-5d51125f11f0",
130
+ "AZURE_TENANT_ID": "e5590d5d-336c-4cf5-b0ac-b79a598ec797",
131
+ "AZURE_CLIENT_SECRET": "IQ08Q~4uCfc4B~p2F95D2737GzYvvrtIjursFbCf"
132
+ }
133
+ else:
134
+ return {
135
+ "AzureWebJobsStorage": "UseDevelopmentStorage=true",
136
+ "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
137
+ "input_queue_connection__queueServiceUri": "UseDevelopmentStorage=true",
138
+ "AzureWebJobsStorage__accountName": "UseDevelopmentStorage=true",
139
+ "AzureWebJobsStorage__blobServiceUri": "UseDevelopmentStorage=true",
140
+ "AZURE_CLIENT_ID": "aa73da4a-2888-4cb7-896e-5d51125f11f0",
141
+ "AZURE_TENANT_ID": "e5590d5d-336c-4cf5-b0ac-b79a598ec797",
142
+ "AZURE_CLIENT_SECRET": "IQ08Q~4uCfc4B~p2F95D2737GzYvvrtIjursFbCf"
143
+ }
144
+
145
+ # Initialize local environment manager
146
+ local_env_manager = create_local_env_manager(
147
+ file_path=".env",
148
+ settings=_get_local_settings(),
149
+ override_json=True,
150
+ override_dotenv=True,
151
+ override_settings=True,
152
+ )
153
+
154
+ # =============================================================================
155
+ # SERVICE CONFIGURATION
156
+ # =============================================================================
157
+
158
+ def _get_service_configuration() -> tuple[str, str, str]:
159
+ """Get service configuration from environment variables.
160
+
161
+ Returns:
162
+ A tuple containing (service_name, service_version, service_kind).
163
+
164
+ Note:
165
+ REFLECTION_KIND has commas replaced with hyphens for compatibility.
166
+ """
167
+ reflection_name = os.getenv("REFLECTION_NAME")
168
+ reflection_kind = os.getenv("REFLECTION_KIND", "").replace(",", "-")
169
+ service_name = reflection_name or str(__name__)
170
+ service_version = os.getenv("SERVICE_VERSION", "1.0.0")
171
+
172
+ return service_name, service_version, reflection_kind
173
+
174
+
175
+ SERVICE_NAME, SERVICE_VERSION, REFLECTION_KIND = _get_service_configuration()
176
+
177
+ # =============================================================================
178
+ # LOGGING CONFIGURATION
179
+ # =============================================================================
180
+
181
+ def _get_logging_configuration() -> tuple[bool, Optional[str], Dict[str, Dict[str, bool]]]:
182
+ """Get logging configuration from environment variables.
183
+
184
+ Returns:
185
+ A tuple containing (console_enabled, connection_string, instrumentation_options).
186
+ """
187
+ console_enabled = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
188
+ connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
189
+ log_level = os.getenv("LOGGER_LOG_LEVEL", "INFO")
190
+ enable_console_logging = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
191
+
192
+ instrumentation_options = {
193
+ "azure_sdk": {"enabled": True},
194
+ "django": {"enabled": False},
195
+ "fastapi": {"enabled": False},
196
+ "flask": {"enabled": True},
197
+ "psycopg2": {"enabled": True},
198
+ "requests": {"enabled": True},
199
+ "urllib": {"enabled": True},
200
+ "urllib3": {"enabled": True},
201
+ }
202
+
203
+ return console_enabled, connection_string, instrumentation_options, log_level
204
+
205
+
206
+ LOGGER_ENABLE_CONSOLE, LOGGER_CONNECTION_STRING, LOGGER_INSTRUMENTATION_OPTIONS, LOGGER_LOG_LEVEL = _get_logging_configuration()
207
+
208
+ # =============================================================================
209
+ # IDENTITY CONFIGURATION
210
+ # =============================================================================
211
+
212
+ def _get_identity_configuration() -> tuple[bool, bool, Optional[Dict[str, Any]], Optional[str]]:
213
+ """Get identity configuration from environment variables.
214
+
215
+ Returns:
216
+ A tuple containing (token_cache_enabled, unencrypted_storage_allowed,
217
+ custom_options, connection_string).
218
+ """
219
+ token_cache_enabled = os.getenv("IDENTITY_ENABLE_TOKEN_CACHE", "true").lower() == "true"
220
+ unencrypted_storage_allowed = os.getenv("IDENTITY_ALLOW_UNENCRYPTED_STORAGE", "true").lower() == "true"
221
+ custom_options = None # Reserved for future custom credential configuration
222
+ connection_string = LOGGER_CONNECTION_STRING # Share with logger by default
223
+
224
+ return token_cache_enabled, unencrypted_storage_allowed, custom_options, connection_string
225
+
226
+
227
+ (IDENTITY_ENABLE_TOKEN_CACHE,
228
+ IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
229
+ IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
230
+ IDENTITY_CONNECTION_STRING) = _get_identity_configuration()
231
+
232
+ # =============================================================================
233
+ # KEY VAULT CONFIGURATION
234
+ # =============================================================================
235
+
236
+ def _get_keyvault_configuration() -> tuple[Optional[str], Optional[str], bool, bool, bool, Optional[str]]:
237
+ """Get Key Vault configuration from environment variables.
238
+
239
+ Returns:
240
+ A tuple containing (vault_url, head_vault_url, secrets_enabled,
241
+ keys_enabled, certificates_enabled, connection_string).
242
+ """
243
+ vault_url = os.getenv("key_vault_uri")
244
+ head_vault_url = os.getenv("head_key_vault_uri")
245
+ secrets_enabled = os.getenv("KEYVAULT_ENABLE_SECRETS", "true").lower() == "true"
246
+ keys_enabled = os.getenv("KEYVAULT_ENABLE_KEYS", "false").lower() == "true"
247
+ certificates_enabled = os.getenv("KEYVAULT_ENABLE_CERTIFICATES", "false").lower() == "true"
248
+ connection_string = LOGGER_CONNECTION_STRING # Share with logger by default
249
+
250
+ return vault_url, head_vault_url, secrets_enabled, keys_enabled, certificates_enabled, connection_string
251
+
252
+
253
+ (KEYVAULT_URL,
254
+ HEAD_KEYVAULT_URL,
255
+ KEYVAULT_ENABLE_SECRETS,
256
+ KEYVAULT_ENABLE_KEYS,
257
+ KEYVAULT_ENABLE_CERTIFICATES,
258
+ KEYVAULT_CONNECTION_STRING) = _get_keyvault_configuration()
259
+
260
+ # =============================================================================
261
+ # SERVICE INITIALIZATION
262
+ # =============================================================================
263
+
264
+ def _create_logger():
265
+ """Create and configure the appropriate logger instance.
266
+
267
+ Returns:
268
+ Configured AzureLogger instance (either app or function logger).
269
+
270
+ Note:
271
+ Logger type is determined by REFLECTION_KIND environment variable.
272
+ Function apps get specialized function loggers with additional context.
273
+ """
274
+ if "functionapp" in REFLECTION_KIND:
275
+ logger_instance = create_function_logger(
276
+ function_app_name=SERVICE_NAME,
277
+ function_name=REFLECTION_KIND,
278
+ service_version=SERVICE_VERSION,
279
+ connection_string=LOGGER_CONNECTION_STRING,
280
+ log_level=LOGGER_LOG_LEVEL,
281
+ instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
282
+ )
283
+ logger_instance.info(
284
+ f"Function logger initialized: {REFLECTION_KIND} {SERVICE_NAME}",
285
+ extra={"logger_type": "function", "function_name": REFLECTION_KIND}
286
+ )
287
+ else:
288
+ logger_instance = create_app_logger(
289
+ service_name=SERVICE_NAME,
290
+ service_version=SERVICE_VERSION,
291
+ connection_string=LOGGER_CONNECTION_STRING,
292
+ log_level=LOGGER_LOG_LEVEL,
293
+ enable_console_logging=LOGGER_ENABLE_CONSOLE,
294
+ instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
295
+ )
296
+ logger_instance.info(
297
+ f"App logger initialized: {REFLECTION_KIND} {SERVICE_NAME}",
298
+ extra={"logger_type": "app", "service_kind": REFLECTION_KIND}
299
+ )
300
+
301
+ return logger_instance
302
+
303
+
304
+ def _create_identity_manager(logger_instance):
305
+ """Create and configure the Azure identity manager.
306
+
307
+ Args:
308
+ logger_instance: Shared logger instance for identity operations.
309
+
310
+ Returns:
311
+ Configured AzureIdentity instance.
312
+ """
313
+ return create_azure_identity(
314
+ service_name=SERVICE_NAME,
315
+ service_version=SERVICE_VERSION,
316
+ enable_token_cache=IDENTITY_ENABLE_TOKEN_CACHE,
317
+ allow_unencrypted_storage=IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
318
+ custom_credential_options=IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
319
+ connection_string=IDENTITY_CONNECTION_STRING,
320
+ logger=logger_instance,
321
+ )
322
+
323
+
324
+ def _create_keyvault_client(vault_url: str, identity_instance, logger_instance):
325
+ """Create a Key Vault client for the specified vault.
326
+
327
+ Args:
328
+ vault_url: Azure Key Vault URL.
329
+ identity_instance: Shared identity manager.
330
+ logger_instance: Shared logger instance.
331
+
332
+ Returns:
333
+ Configured AzureKeyVault instance or None if creation fails.
334
+ """
335
+ if not vault_url:
336
+ return None
337
+
338
+ return create_azure_keyvault(
339
+ vault_url=vault_url,
340
+ azure_identity=identity_instance,
341
+ service_name=SERVICE_NAME,
342
+ service_version=SERVICE_VERSION,
343
+ logger=logger_instance,
344
+ connection_string=KEYVAULT_CONNECTION_STRING,
345
+ enable_secrets=KEYVAULT_ENABLE_SECRETS,
346
+ enable_keys=KEYVAULT_ENABLE_KEYS,
347
+ enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
348
+ )
349
+
350
+
351
+ # Initialize core services
352
+ logger = _create_logger()
353
+ identity = _create_identity_manager(logger)
354
+
355
+ # Initialize Key Vault clients (if URLs are configured)
356
+ keyvault = _create_keyvault_client(KEYVAULT_URL, identity, logger)
357
+ head_keyvault = _create_keyvault_client(HEAD_KEYVAULT_URL, identity, logger)
358
+
359
+ # =============================================================================
360
+ # CONFIGURATION VALIDATION & STARTUP LOGGING
361
+ # =============================================================================
362
+
363
+ def _validate_and_log_configuration():
364
+ """Validate configuration and log startup information.
365
+
366
+ This function performs validation checks and logs important configuration
367
+ status information for debugging and monitoring purposes.
368
+ """
369
+ # Validate critical configuration
370
+ if SERVICE_NAME == __name__:
371
+ logger.warning(
372
+ "SERVICE_NAME is using module name. Consider setting REFLECTION_NAME environment variable.",
373
+ extra={"configuration_issue": "service_name_not_set", "current_name": SERVICE_NAME}
374
+ )
375
+
376
+ # Log telemetry status
377
+ if not LOGGER_CONNECTION_STRING:
378
+ logger.info(
379
+ "No Application Insights connection string configured. Telemetry will be disabled.",
380
+ extra={"telemetry_status": "disabled"}
381
+ )
382
+
383
+ # Log Key Vault status
384
+ if not KEYVAULT_URL:
385
+ logger.info(
386
+ "No Key Vault URL configured. Key Vault operations will be disabled.",
387
+ extra={"keyvault_status": "disabled"}
388
+ )
389
+
390
+ if not HEAD_KEYVAULT_URL:
391
+ logger.info(
392
+ "No Head Key Vault URL configured. Head Key Vault operations will be disabled.",
393
+ extra={"head_keyvault_status": "disabled"}
394
+ )
395
+
396
+ # Log successful initialization with comprehensive metadata
397
+ logger.info(
398
+ f"Management configuration initialized for service '{SERVICE_NAME}' v{SERVICE_VERSION}",
399
+ extra={
400
+ "service_name": SERVICE_NAME,
401
+ "service_version": SERVICE_VERSION,
402
+ "console_logging": LOGGER_ENABLE_CONSOLE,
403
+ "token_cache_enabled": IDENTITY_ENABLE_TOKEN_CACHE,
404
+ "telemetry_enabled": bool(LOGGER_CONNECTION_STRING),
405
+ "keyvault_enabled": bool(KEYVAULT_URL),
406
+ "head_keyvault_enabled": bool(HEAD_KEYVAULT_URL),
407
+ "keyvault_secrets_enabled": KEYVAULT_ENABLE_SECRETS if KEYVAULT_URL else False,
408
+ "keyvault_keys_enabled": KEYVAULT_ENABLE_KEYS if KEYVAULT_URL else False,
409
+ "keyvault_certificates_enabled": KEYVAULT_ENABLE_CERTIFICATES if KEYVAULT_URL else False,
410
+ "running_in_docker": RUNNING_IN_DOCKER,
411
+ }
412
+ )
413
+
414
+
415
+ # Perform validation and startup logging
416
+ _validate_and_log_configuration()
417
+
418
+ # =============================================================================
419
+ # MODULE EXPORTS
420
+ # =============================================================================
421
+
422
+ # Export primary service instances for application use
423
+ __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.79
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.7
44
44
  Dynamic: license-file
45
45
 
46
46
  # paddypy
@@ -31,4 +31,4 @@ azure-search-documents==11.6.0b4
31
31
  semantic-kernel==1.3.0
32
32
  pydantic==2.7.4
33
33
  pandas>=2.2.3
34
- azpaddypy>=0.5.5
34
+ azpaddypy>=0.5.7
@@ -3,7 +3,7 @@ name = "cwyodmodules"
3
3
  authors = [
4
4
  { name="Patrik", email="patrikhartl@gmail.com" },
5
5
  ]
6
- version = '0.3.77'
6
+ version = '0.3.79'
7
7
  description = "Add your description here"
8
8
  readme = "README.md"
9
9
  requires-python = "==3.11.11"
@@ -44,7 +44,7 @@ dependencies = [
44
44
  "semantic-kernel==1.3.0",
45
45
  "pydantic==2.7.4",
46
46
  "pandas>=2.2.3",
47
- "azpaddypy>=0.5.5",
47
+ "azpaddypy>=0.5.7",
48
48
  ]
49
49
 
50
50
  [tool.uv]
@@ -1,258 +0,0 @@
1
- """
2
- Azure Project Management Configuration Template
3
-
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
-
8
- Usage:
9
- from mgmt_config import logger, identity
10
-
11
- logger.info("Application started")
12
- credential = identity.get_credential()
13
- """
14
-
15
- import os
16
- from typing import Optional, Dict, Any
17
- from azpaddypy.mgmt.logging import create_app_logger, create_function_logger
18
- from azpaddypy.mgmt.identity import create_azure_identity
19
- from azpaddypy.resources.keyvault import create_azure_keyvault
20
- from azpaddypy.mgmt.local_env_manager import create_local_env_manager
21
-
22
- # Alias for import in other packages
23
-
24
- # =============================================================================
25
- # SERVICE CONFIGURATION
26
- # =============================================================================
27
-
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():
35
- """
36
- Checks if the current process is running inside a Docker container.
37
-
38
- Returns:
39
- bool: True if running in Docker, False otherwise.
40
- """
41
- # Method 1: Check for /.dockerenv file
42
- if os.path.exists('/.dockerenv'):
43
- return True
44
-
45
- # Method 2: Check cgroup for "docker"
46
- try:
47
- with open('/proc/1/cgroup', 'rt') as f:
48
- 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
56
- pass
57
-
58
- return False
59
-
60
- running_in_docker = is_running_in_docker()
61
- print("is_running_in_docker: " + str(running_in_docker))
62
-
63
-
64
- # =============================================================================
65
- # LOGGING CONFIGURATION
66
- # =============================================================================
67
-
68
- # Enable console output (useful for local development)
69
- LOGGER_ENABLE_CONSOLE = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
70
-
71
- # Application Insights connection string (optional, will use environment variable if not set)
72
- LOGGER_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
73
-
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",
88
- }
89
-
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
- }
101
-
102
- # =============================================================================
103
- # IDENTITY CONFIGURATION
104
- # =============================================================================
105
-
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"
109
-
110
- # Custom credential options (None means use defaults)
111
- IDENTITY_CUSTOM_CREDENTIAL_OPTIONS: Optional[Dict[str, Any]] = None
112
-
113
- # Connection string for identity logging (uses same as logger by default)
114
- IDENTITY_CONNECTION_STRING = LOGGER_CONNECTION_STRING
115
-
116
- # =============================================================================
117
- # KEYVAULT CONFIGURATION
118
- # =============================================================================
119
-
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"
124
-
125
- # Connection string for keyvault logging (uses same as logger by default)
126
- KEYVAULT_CONNECTION_STRING = LOGGER_CONNECTION_STRING
127
-
128
- # =============================================================================
129
- # INITIALIZE SERVICES
130
- # =============================================================================
131
-
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
- )
172
-
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
-
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,
183
- service_name=SERVICE_NAME,
184
- 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,
190
- )
191
-
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,
197
- service_name=SERVICE_NAME,
198
- service_version=SERVICE_VERSION,
199
- logger=logger,
200
- connection_string=KEYVAULT_CONNECTION_STRING,
201
- enable_secrets=KEYVAULT_ENABLE_SECRETS,
202
- enable_keys=KEYVAULT_ENABLE_KEYS,
203
- enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
204
- )
205
-
206
- # =============================================================================
207
- # VALIDATION & STARTUP
208
- # =============================================================================
209
-
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
- )
216
-
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
- )
222
-
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
- )
228
-
229
- if not HEAD_KEYVAULT_URL:
230
- logger.info(
231
- "No Head Key Vault URL configured. Head Key Vault operations will be disabled.",
232
- extra={"head_keyvault_status": "disabled"}
233
- )
234
-
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
- )
252
-
253
- # =============================================================================
254
- # EXPORTS
255
- # =============================================================================
256
-
257
- # Export logger, identity, and keyvault for use in applications
258
- __all__ = ["logger", "local_env_manager", "identity", "keyvault", "head_keyvault"]
File without changes
File without changes
File without changes