cdk-factory 0.15.11__py3-none-any.whl → 0.15.12__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.
Potentially problematic release.
This version of cdk-factory might be problematic. Click here for more details.
- cdk_factory/configurations/resources/rds.py +96 -4
- cdk_factory/pipeline/pipeline_factory.py +1 -0
- cdk_factory/stack/stack_factory.py +34 -0
- cdk_factory/version.py +1 -1
- cdk_factory/workload/workload_factory.py +1 -0
- {cdk_factory-0.15.11.dist-info → cdk_factory-0.15.12.dist-info}/METADATA +1 -1
- {cdk_factory-0.15.11.dist-info → cdk_factory-0.15.12.dist-info}/RECORD +10 -10
- {cdk_factory-0.15.11.dist-info → cdk_factory-0.15.12.dist-info}/WHEEL +0 -0
- {cdk_factory-0.15.11.dist-info → cdk_factory-0.15.12.dist-info}/entry_points.txt +0 -0
- {cdk_factory-0.15.11.dist-info → cdk_factory-0.15.12.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,9 +4,13 @@ Maintainers: Eric Wilson
|
|
|
4
4
|
MIT License. See Project Root for license information.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
import re
|
|
7
8
|
from typing import Any, Dict, List, Optional
|
|
9
|
+
from aws_lambda_powertools import Logger
|
|
8
10
|
from cdk_factory.configurations.enhanced_base_config import EnhancedBaseConfig
|
|
9
11
|
|
|
12
|
+
logger = Logger(service="RdsConfig")
|
|
13
|
+
|
|
10
14
|
|
|
11
15
|
class RdsConfig(EnhancedBaseConfig):
|
|
12
16
|
"""
|
|
@@ -44,13 +48,15 @@ class RdsConfig(EnhancedBaseConfig):
|
|
|
44
48
|
|
|
45
49
|
@property
|
|
46
50
|
def database_name(self) -> str:
|
|
47
|
-
"""Name of the database to create"""
|
|
48
|
-
|
|
51
|
+
"""Name of the database to create (sanitized for RDS requirements)"""
|
|
52
|
+
raw_name = self.__config.get("database_name", "appdb")
|
|
53
|
+
return self._sanitize_database_name(raw_name)
|
|
49
54
|
|
|
50
55
|
@property
|
|
51
56
|
def username(self) -> str:
|
|
52
|
-
"""Master username for the database"""
|
|
53
|
-
|
|
57
|
+
"""Master username for the database (sanitized for RDS requirements)"""
|
|
58
|
+
raw_username = self.__config.get("username", "appuser")
|
|
59
|
+
return self._sanitize_username(raw_username)
|
|
54
60
|
|
|
55
61
|
@property
|
|
56
62
|
def secret_name(self) -> str:
|
|
@@ -146,3 +152,89 @@ class RdsConfig(EnhancedBaseConfig):
|
|
|
146
152
|
if "ssm" in self.__config and "exports" in self.__config["ssm"]:
|
|
147
153
|
return self.__config["ssm"]["exports"]
|
|
148
154
|
return self.__config.get("ssm_exports", {})
|
|
155
|
+
|
|
156
|
+
def _sanitize_database_name(self, name: str) -> str:
|
|
157
|
+
"""
|
|
158
|
+
Sanitize database name to meet RDS requirements:
|
|
159
|
+
- Must begin with a letter (a-z, A-Z)
|
|
160
|
+
- Can contain alphanumeric characters and underscores
|
|
161
|
+
- Max 64 characters
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
name: Raw database name from config
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Sanitized database name
|
|
168
|
+
|
|
169
|
+
Raises:
|
|
170
|
+
ValueError: If name starts with a number or is empty after sanitization
|
|
171
|
+
"""
|
|
172
|
+
if not name:
|
|
173
|
+
raise ValueError("Database name cannot be empty")
|
|
174
|
+
|
|
175
|
+
# Replace hyphens with underscores, remove other invalid chars
|
|
176
|
+
sanitized = name.replace('-', '_')
|
|
177
|
+
sanitized = re.sub(r'[^a-zA-Z0-9_]', '', sanitized)
|
|
178
|
+
|
|
179
|
+
if not sanitized:
|
|
180
|
+
raise ValueError(f"Database name '{name}' contains no valid characters")
|
|
181
|
+
|
|
182
|
+
# Check if it starts with a number
|
|
183
|
+
if sanitized[0].isdigit():
|
|
184
|
+
raise ValueError(
|
|
185
|
+
f"Database name '{name}' (sanitized to '{sanitized}') cannot start with a number. "
|
|
186
|
+
f"Please ensure the database name begins with a letter."
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Truncate to 64 characters if needed
|
|
190
|
+
if len(sanitized) > 64:
|
|
191
|
+
sanitized = sanitized[:64]
|
|
192
|
+
|
|
193
|
+
# Log if sanitization changed the name
|
|
194
|
+
if sanitized != name:
|
|
195
|
+
logger.info(f"Sanitized database name from '{name}' to '{sanitized}'")
|
|
196
|
+
|
|
197
|
+
return sanitized
|
|
198
|
+
|
|
199
|
+
def _sanitize_username(self, username: str) -> str:
|
|
200
|
+
"""
|
|
201
|
+
Sanitize username to meet RDS requirements:
|
|
202
|
+
- Must begin with a letter (a-z, A-Z)
|
|
203
|
+
- Can contain alphanumeric characters and underscores
|
|
204
|
+
- Max 16 characters for MySQL
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
username: Raw username from config
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
Sanitized username
|
|
211
|
+
|
|
212
|
+
Raises:
|
|
213
|
+
ValueError: If username is invalid
|
|
214
|
+
"""
|
|
215
|
+
if not username:
|
|
216
|
+
raise ValueError("Username cannot be empty")
|
|
217
|
+
|
|
218
|
+
# Replace hyphens with underscores, remove other invalid chars
|
|
219
|
+
sanitized = username.replace('-', '_')
|
|
220
|
+
sanitized = re.sub(r'[^a-zA-Z0-9_]', '', sanitized)
|
|
221
|
+
|
|
222
|
+
if not sanitized:
|
|
223
|
+
raise ValueError(f"Username '{username}' contains no valid characters")
|
|
224
|
+
|
|
225
|
+
# Check if it starts with a number
|
|
226
|
+
if sanitized[0].isdigit():
|
|
227
|
+
raise ValueError(
|
|
228
|
+
f"Username '{username}' (sanitized to '{sanitized}') cannot start with a number. "
|
|
229
|
+
f"Please ensure the username begins with a letter."
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
# Truncate to 16 characters for MySQL (other engines may vary)
|
|
233
|
+
if len(sanitized) > 16:
|
|
234
|
+
sanitized = sanitized[:16]
|
|
235
|
+
|
|
236
|
+
# Log if sanitization changed the username
|
|
237
|
+
if sanitized != username:
|
|
238
|
+
logger.info(f"Sanitized username from '{username}' to '{sanitized}'")
|
|
239
|
+
|
|
240
|
+
return sanitized
|
|
@@ -11,10 +11,28 @@ from cdk_factory.interfaces.istack import IStack
|
|
|
11
11
|
from cdk_factory.stack.stack_module_loader import ModuleLoader
|
|
12
12
|
from cdk_factory.stack.stack_module_registry import modules
|
|
13
13
|
from cdk_factory.configurations.deployment import DeploymentConfig
|
|
14
|
+
from cdk_factory.configurations.stack import StackConfig
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class StackFactory:
|
|
17
18
|
"""Stack Factory"""
|
|
19
|
+
|
|
20
|
+
# Default descriptions by module type
|
|
21
|
+
DEFAULT_DESCRIPTIONS = {
|
|
22
|
+
"vpc_stack": "VPC infrastructure with public and private subnets across multiple availability zones",
|
|
23
|
+
"security_group_stack": "Security groups for network access control",
|
|
24
|
+
"security_group_full_stack": "Security groups for ALB, ECS, RDS, and monitoring",
|
|
25
|
+
"rds_stack": "Managed relational database instance with automated backups",
|
|
26
|
+
"s3_bucket_stack": "S3 bucket for object storage",
|
|
27
|
+
"media_bucket_stack": "S3 bucket for media asset storage with CDN integration",
|
|
28
|
+
"static_website_stack": "Static website hosted on S3 with CloudFront distribution",
|
|
29
|
+
"ecs_service_stack": "ECS service with auto-scaling and load balancing",
|
|
30
|
+
"lambda_stack": "Lambda function for serverless compute",
|
|
31
|
+
"api_gateway_stack": "API Gateway for REST API endpoints",
|
|
32
|
+
"cloudfront_stack": "CloudFront CDN distribution",
|
|
33
|
+
"monitoring_stack": "CloudWatch monitoring, alarms, and dashboards",
|
|
34
|
+
"ecr_stack": "Elastic Container Registry for Docker images",
|
|
35
|
+
}
|
|
18
36
|
|
|
19
37
|
def __init__(self):
|
|
20
38
|
ml: ModuleLoader = ModuleLoader()
|
|
@@ -27,6 +45,7 @@ class StackFactory:
|
|
|
27
45
|
scope,
|
|
28
46
|
id: str, # pylint: disable=redefined-builtin
|
|
29
47
|
deployment: Optional[DeploymentConfig] = None,
|
|
48
|
+
stack_config: Optional[StackConfig] = None,
|
|
30
49
|
add_env_context: bool = True,
|
|
31
50
|
**kwargs,
|
|
32
51
|
) -> IStack:
|
|
@@ -40,6 +59,12 @@ class StackFactory:
|
|
|
40
59
|
if deployment and add_env_context:
|
|
41
60
|
env_kwargs = self._get_environment_kwargs(deployment)
|
|
42
61
|
kwargs.update(env_kwargs)
|
|
62
|
+
|
|
63
|
+
# Add description if not already provided in kwargs
|
|
64
|
+
if "description" not in kwargs:
|
|
65
|
+
description = self._get_stack_description(module_name, stack_config)
|
|
66
|
+
if description:
|
|
67
|
+
kwargs["description"] = description
|
|
43
68
|
|
|
44
69
|
module = stack_class(scope=scope, id=id, **kwargs)
|
|
45
70
|
|
|
@@ -52,3 +77,12 @@ class StackFactory:
|
|
|
52
77
|
region=deployment.region
|
|
53
78
|
)
|
|
54
79
|
return {"env": env}
|
|
80
|
+
|
|
81
|
+
def _get_stack_description(self, module_name: str, stack_config: Optional[StackConfig] = None) -> Optional[str]:
|
|
82
|
+
"""Get stack description from config or default"""
|
|
83
|
+
# First check if stack_config has a description
|
|
84
|
+
if stack_config and stack_config.description:
|
|
85
|
+
return stack_config.description
|
|
86
|
+
|
|
87
|
+
# Otherwise use default description based on module type
|
|
88
|
+
return self.DEFAULT_DESCRIPTIONS.get(module_name)
|
cdk_factory/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.15.
|
|
1
|
+
__version__ = "0.15.12"
|
|
@@ -2,7 +2,7 @@ cdk_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
cdk_factory/app.py,sha256=RnX0-pwdTAPAdKJK_j13Zl8anf9zYKBwboR0KA8K8xM,10346
|
|
3
3
|
cdk_factory/cdk.json,sha256=SKZKhJ2PBpFH78j-F8S3VDYW-lf76--Q2I3ON-ZIQfw,3106
|
|
4
4
|
cdk_factory/cli.py,sha256=FGbCTS5dYCNsfp-etshzvFlGDCjC28r6rtzYbe7KoHI,6407
|
|
5
|
-
cdk_factory/version.py,sha256=
|
|
5
|
+
cdk_factory/version.py,sha256=uhKEhmOyw-8a1XvaAZVr11Ygw-f1noUzBbHqYnFKzHE,24
|
|
6
6
|
cdk_factory/builds/README.md,sha256=9BBWd7bXpyKdMU_g2UljhQwrC9i5O_Tvkb6oPvndoZk,90
|
|
7
7
|
cdk_factory/commands/command_loader.py,sha256=QbLquuP_AdxtlxlDy-2IWCQ6D-7qa58aphnDPtp_uTs,3744
|
|
8
8
|
cdk_factory/configurations/base_config.py,sha256=JKjhNsy0RCUZy1s8n5D_aXXI-upR9izaLtCTfKYiV9k,9624
|
|
@@ -38,7 +38,7 @@ cdk_factory/configurations/resources/lambda_layers.py,sha256=gVeP_-LC3Eq0lkPaG_J
|
|
|
38
38
|
cdk_factory/configurations/resources/lambda_triggers.py,sha256=MD7cdMNKEulNBhtMLIFnWJuJ5R-yyIqa0LHUgbSQerA,834
|
|
39
39
|
cdk_factory/configurations/resources/load_balancer.py,sha256=idpKdvkkCM7J9J2pNjMBOY1DNaFR1tk1tFjTg76bvrY,5267
|
|
40
40
|
cdk_factory/configurations/resources/monitoring.py,sha256=zsfDMa7yph33Ql8iP7lIqqLAyixh-Mesi0imtZJFdcE,2310
|
|
41
|
-
cdk_factory/configurations/resources/rds.py,sha256=
|
|
41
|
+
cdk_factory/configurations/resources/rds.py,sha256=IQyi5UFf3LEWgkp71XHkjdedqW-PWS2UvpjXJpp7df0,8557
|
|
42
42
|
cdk_factory/configurations/resources/resource_mapping.py,sha256=cwv3n63RJ6E59ErsmSTdkW4i-g8huhHtKI0ExbRhJxA,2182
|
|
43
43
|
cdk_factory/configurations/resources/resource_naming.py,sha256=VE9S2cpzp11qqPL2z1sX79wXH0o1SntO2OG74nEmWC8,5508
|
|
44
44
|
cdk_factory/configurations/resources/resource_types.py,sha256=1WQHyDoErb-M-tETZZzyLDtbq_jdC85-I403dM48pgE,2317
|
|
@@ -68,12 +68,12 @@ cdk_factory/interfaces/ssm_parameter_mixin.py,sha256=uA2j8HmAOpuEA9ynRj51s0WjUHM
|
|
|
68
68
|
cdk_factory/lambdas/health_handler.py,sha256=dd40ykKMxWCFEIyp2ZdQvAGNjw_ylI9CSm1N24Hp2ME,196
|
|
69
69
|
cdk_factory/lambdas/edge/ip_gate/handler.py,sha256=YrXO42gEhJoBTaH6jS7EWqjHe9t5Fpt4WLgY8vjtou0,10474
|
|
70
70
|
cdk_factory/pipeline/path_utils.py,sha256=fvWdrcb4onmpIu1APkHLhXg8zWfK74HcW3Ra2ynxfXM,2586
|
|
71
|
-
cdk_factory/pipeline/pipeline_factory.py,sha256=
|
|
71
|
+
cdk_factory/pipeline/pipeline_factory.py,sha256=tY-uaJa_51CnWHb4KEvYMT-pZ_7cWy5DNnTfXHWUoHY,17295
|
|
72
72
|
cdk_factory/pipeline/stage.py,sha256=Be7ExMB9A-linRM18IQDOzQ-cP_I2_ThRNzlT4FIrUg,437
|
|
73
73
|
cdk_factory/pipeline/security/policies.py,sha256=H3-S6nipz3UtF9Pc5eJYr4-aREUTCaJWMjOUyd6Rdv4,4406
|
|
74
74
|
cdk_factory/pipeline/security/roles.py,sha256=ZB_O5H_BXgotvVspS2kVad9EMcY-a_-vU7Nm1_Z5MB8,4985
|
|
75
75
|
cdk_factory/stack/istack.py,sha256=-n0FTLvG7uvLxkyqRGjqFTguZeTRuXwFxGzcAIqbsj8,174
|
|
76
|
-
cdk_factory/stack/stack_factory.py,sha256=
|
|
76
|
+
cdk_factory/stack/stack_factory.py,sha256=PfFzKxfM_5JPhK33_acEvpT4gll_AFCqZP7-lPifbJk,3649
|
|
77
77
|
cdk_factory/stack/stack_module_loader.py,sha256=EA7ceb8qyktzkYgPYaixQdPJsi8FwTsMU-NrgtXwXcw,1144
|
|
78
78
|
cdk_factory/stack/stack_module_registry.py,sha256=J14-A75VZESzRQa8p-Fepdap7Z8T7mradTu3sVzuBx8,378
|
|
79
79
|
cdk_factory/stack/stack_modules.py,sha256=kgEK-j0smZPozVwTCfM1g1V17EyTBT0TXAQZq4vZz0o,784
|
|
@@ -128,9 +128,9 @@ cdk_factory/utilities/json_loading_utility.py,sha256=YRgzA1I-B_HwZm1eWJTeQ1JLkeb
|
|
|
128
128
|
cdk_factory/utilities/lambda_function_utilities.py,sha256=S1GvBsY_q2cyUiaud3HORJMnLhI5cRi31fbeaktY-_Q,15826
|
|
129
129
|
cdk_factory/utilities/os_execute.py,sha256=5Op0LY_8Y-pUm04y1k8MTpNrmQvcLmQHPQITEP7EuSU,1019
|
|
130
130
|
cdk_factory/utils/api_gateway_utilities.py,sha256=If7Xu5s_UxmuV-kL3JkXxPLBdSVUKoLtohm0IUFoiV8,4378
|
|
131
|
-
cdk_factory/workload/workload_factory.py,sha256=
|
|
132
|
-
cdk_factory-0.15.
|
|
133
|
-
cdk_factory-0.15.
|
|
134
|
-
cdk_factory-0.15.
|
|
135
|
-
cdk_factory-0.15.
|
|
136
|
-
cdk_factory-0.15.
|
|
131
|
+
cdk_factory/workload/workload_factory.py,sha256=yDI3cRhVI5ELNDcJPLpk9UY54Uind1xQoV3spzT4z7E,6068
|
|
132
|
+
cdk_factory-0.15.12.dist-info/METADATA,sha256=krTwolq-UXam3vFCtadV1i4DPAOsprJnhuNlsRWacik,2452
|
|
133
|
+
cdk_factory-0.15.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
134
|
+
cdk_factory-0.15.12.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
|
|
135
|
+
cdk_factory-0.15.12.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
|
|
136
|
+
cdk_factory-0.15.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|