nui-python-shared-utils 1.3.0__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.
- nui_lambda_shared_utils/__init__.py +252 -0
- nui_lambda_shared_utils/base_client.py +323 -0
- nui_lambda_shared_utils/cli.py +225 -0
- nui_lambda_shared_utils/cloudwatch_metrics.py +367 -0
- nui_lambda_shared_utils/config.py +136 -0
- nui_lambda_shared_utils/db_client.py +623 -0
- nui_lambda_shared_utils/error_handler.py +372 -0
- nui_lambda_shared_utils/es_client.py +460 -0
- nui_lambda_shared_utils/es_query_builder.py +315 -0
- nui_lambda_shared_utils/jwt_auth.py +277 -0
- nui_lambda_shared_utils/lambda_helpers.py +84 -0
- nui_lambda_shared_utils/log_processors.py +172 -0
- nui_lambda_shared_utils/powertools_helpers.py +263 -0
- nui_lambda_shared_utils/secrets_helper.py +187 -0
- nui_lambda_shared_utils/slack_client.py +675 -0
- nui_lambda_shared_utils/slack_formatter.py +307 -0
- nui_lambda_shared_utils/slack_setup/__init__.py +14 -0
- nui_lambda_shared_utils/slack_setup/channel_creator.py +295 -0
- nui_lambda_shared_utils/slack_setup/channel_definitions.py +187 -0
- nui_lambda_shared_utils/slack_setup/setup_helpers.py +211 -0
- nui_lambda_shared_utils/timezone.py +117 -0
- nui_lambda_shared_utils/utils.py +291 -0
- nui_python_shared_utils-1.3.0.dist-info/METADATA +470 -0
- nui_python_shared_utils-1.3.0.dist-info/RECORD +28 -0
- nui_python_shared_utils-1.3.0.dist-info/WHEEL +5 -0
- nui_python_shared_utils-1.3.0.dist-info/entry_points.txt +2 -0
- nui_python_shared_utils-1.3.0.dist-info/licenses/LICENSE +21 -0
- nui_python_shared_utils-1.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration system for AWS Lambda shared utilities.
|
|
3
|
+
|
|
4
|
+
This module provides configurable defaults and environment-based overrides
|
|
5
|
+
to make the library suitable for different deployment environments.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
from typing import Dict, Optional, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Config:
|
|
13
|
+
"""Configuration class for AWS Lambda shared utilities with environment-based overrides."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
# Elasticsearch configuration
|
|
18
|
+
es_host: Optional[str] = None,
|
|
19
|
+
es_credentials_secret: Optional[str] = None,
|
|
20
|
+
# Database configuration
|
|
21
|
+
db_credentials_secret: Optional[str] = None,
|
|
22
|
+
# Slack configuration
|
|
23
|
+
slack_credentials_secret: Optional[str] = None,
|
|
24
|
+
# AWS configuration
|
|
25
|
+
aws_region: Optional[str] = None,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
Initialize configuration with optional overrides.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
es_host: Elasticsearch host (default: localhost:9200)
|
|
32
|
+
es_credentials_secret: AWS secret name for ES credentials
|
|
33
|
+
db_credentials_secret: AWS secret name for database credentials
|
|
34
|
+
slack_credentials_secret: AWS secret name for Slack credentials
|
|
35
|
+
aws_region: AWS region for secrets/services
|
|
36
|
+
"""
|
|
37
|
+
# Elasticsearch settings
|
|
38
|
+
if es_host is not None:
|
|
39
|
+
self.es_host = es_host
|
|
40
|
+
else:
|
|
41
|
+
self.es_host = os.environ.get("ES_HOST") or os.environ.get("ELASTICSEARCH_HOST") or "localhost:9200"
|
|
42
|
+
|
|
43
|
+
if es_credentials_secret is not None:
|
|
44
|
+
self.es_credentials_secret = es_credentials_secret
|
|
45
|
+
else:
|
|
46
|
+
self.es_credentials_secret = (
|
|
47
|
+
os.environ.get("ES_CREDENTIALS_SECRET")
|
|
48
|
+
or os.environ.get("ELASTICSEARCH_CREDENTIALS_SECRET")
|
|
49
|
+
or "elasticsearch-credentials"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Database settings
|
|
53
|
+
if db_credentials_secret is not None:
|
|
54
|
+
self.db_credentials_secret = db_credentials_secret
|
|
55
|
+
else:
|
|
56
|
+
self.db_credentials_secret = (
|
|
57
|
+
os.environ.get("DB_CREDENTIALS_SECRET")
|
|
58
|
+
or os.environ.get("DATABASE_CREDENTIALS_SECRET")
|
|
59
|
+
or "database-credentials"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Slack settings
|
|
63
|
+
if slack_credentials_secret is not None:
|
|
64
|
+
self.slack_credentials_secret = slack_credentials_secret
|
|
65
|
+
else:
|
|
66
|
+
self.slack_credentials_secret = os.environ.get("SLACK_CREDENTIALS_SECRET") or "slack-credentials"
|
|
67
|
+
|
|
68
|
+
# AWS settings
|
|
69
|
+
if aws_region is not None:
|
|
70
|
+
self.aws_region = aws_region
|
|
71
|
+
else:
|
|
72
|
+
self.aws_region = os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION") or "us-east-1"
|
|
73
|
+
|
|
74
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
75
|
+
"""Return configuration as dictionary for debugging/logging."""
|
|
76
|
+
return {
|
|
77
|
+
"es_host": self.es_host,
|
|
78
|
+
"es_credentials_secret": self.es_credentials_secret,
|
|
79
|
+
"db_credentials_secret": self.db_credentials_secret,
|
|
80
|
+
"slack_credentials_secret": self.slack_credentials_secret,
|
|
81
|
+
"aws_region": self.aws_region,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Global default configuration instance
|
|
86
|
+
_default_config = None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_config() -> Config:
|
|
90
|
+
"""Get the current global configuration instance."""
|
|
91
|
+
global _default_config
|
|
92
|
+
if _default_config is None:
|
|
93
|
+
_default_config = Config()
|
|
94
|
+
return _default_config
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def set_config(config: Config) -> None:
|
|
98
|
+
"""Set a new global configuration instance."""
|
|
99
|
+
global _default_config
|
|
100
|
+
_default_config = config
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def configure(**kwargs) -> Config:
|
|
104
|
+
"""
|
|
105
|
+
Configure the global configuration with keyword arguments.
|
|
106
|
+
|
|
107
|
+
This is a convenience function equivalent to:
|
|
108
|
+
set_config(Config(**kwargs))
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
The new configuration instance
|
|
112
|
+
"""
|
|
113
|
+
config = Config(**kwargs)
|
|
114
|
+
set_config(config)
|
|
115
|
+
return config
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Legacy compatibility - environment variable checking functions
|
|
119
|
+
def get_es_host() -> str:
|
|
120
|
+
"""Get Elasticsearch host from configuration (legacy compatibility)."""
|
|
121
|
+
return get_config().es_host
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def get_es_credentials_secret() -> str:
|
|
125
|
+
"""Get Elasticsearch credentials secret name (legacy compatibility)."""
|
|
126
|
+
return get_config().es_credentials_secret
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_db_credentials_secret() -> str:
|
|
130
|
+
"""Get database credentials secret name (legacy compatibility)."""
|
|
131
|
+
return get_config().db_credentials_secret
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def get_slack_credentials_secret() -> str:
|
|
135
|
+
"""Get Slack credentials secret name (legacy compatibility)."""
|
|
136
|
+
return get_config().slack_credentials_secret
|