cdk-factory 0.7.30__py3-none-any.whl → 0.7.31__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.

@@ -190,15 +190,23 @@ class CloudFrontDistributionConstruct(Construct):
190
190
  cloudfront_config = self.stack_config.dictionary.get("cloudfront", {})
191
191
  enable_url_rewrite = cloudfront_config.get("enable_url_rewrite", False)
192
192
 
193
- if enable_url_rewrite:
193
+ # CloudFront only allows ONE function per event type
194
+ # If both URL rewrite and host restrictions are needed, combine them
195
+ if enable_url_rewrite and self.restrict_to_known_hosts and self.aliases:
196
+ function_associations.append(
197
+ cloudfront.FunctionAssociation(
198
+ function=self.__get_combined_function(hosts=self.aliases),
199
+ event_type=cloudfront.FunctionEventType.VIEWER_REQUEST,
200
+ )
201
+ )
202
+ elif enable_url_rewrite:
194
203
  function_associations.append(
195
204
  cloudfront.FunctionAssociation(
196
205
  function=self.__get_url_rewrite_function(),
197
206
  event_type=cloudfront.FunctionEventType.VIEWER_REQUEST,
198
207
  )
199
208
  )
200
-
201
- if self.restrict_to_known_hosts and self.aliases:
209
+ elif self.restrict_to_known_hosts and self.aliases:
202
210
  function_associations.append(
203
211
  cloudfront.FunctionAssociation(
204
212
  function=self.__get_cloudfront_host_restrictions(
@@ -210,6 +218,58 @@ class CloudFrontDistributionConstruct(Construct):
210
218
 
211
219
  return function_associations
212
220
 
221
+ def __get_combined_function(self, hosts: List[str]) -> cloudfront.Function:
222
+ """
223
+ Creates a combined CloudFront function that does both URL rewriting and host restrictions.
224
+ This is necessary because CloudFront only allows one function per event type.
225
+
226
+ Args:
227
+ hosts: List of allowed hostnames
228
+
229
+ Returns:
230
+ cloudfront.Function: Combined function
231
+ """
232
+ allowed_hosts = "[" + ", ".join(f"'{host}'" for host in hosts) + "]"
233
+
234
+ function_code = f"""
235
+ function handler(event) {{
236
+ var request = event.request;
237
+ var allowedHosts = {allowed_hosts};
238
+ var hostHeader = request.headers.host.value;
239
+
240
+ // Check host restrictions first
241
+ if (allowedHosts.indexOf(hostHeader) === -1) {{
242
+ return {{ statusCode: 403, statusDescription: 'Forbidden' }};
243
+ }}
244
+
245
+ // Then do URL rewrite
246
+ var uri = request.uri;
247
+
248
+ // If URI doesn't have a file extension and doesn't end with /
249
+ if (!uri.includes('.') && !uri.endsWith('/')) {{
250
+ request.uri = uri + '/index.html';
251
+ }}
252
+ // If URI ends with / but not index.html
253
+ else if (uri.endsWith('/') && !uri.endsWith('index.html')) {{
254
+ request.uri = uri + 'index.html';
255
+ }}
256
+ // If URI is exactly /
257
+ else if (uri === '/') {{
258
+ request.uri = '/index.html';
259
+ }}
260
+
261
+ return request;
262
+ }}
263
+ """
264
+
265
+ combined_function = cloudfront.Function(
266
+ self,
267
+ "CombinedFunction",
268
+ comment="Combined URL rewrite and host restrictions for static site routing",
269
+ code=cloudfront.FunctionCode.from_inline(function_code),
270
+ )
271
+ return combined_function
272
+
213
273
  def __get_url_rewrite_function(self) -> cloudfront.Function:
214
274
  """
215
275
  Creates a CloudFront function that rewrites URLs for SPA/static site routing.
cdk_factory/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.7.30"
1
+ __version__ = "0.7.31"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdk_factory
3
- Version: 0.7.30
3
+ Version: 0.7.31
4
4
  Summary: CDK Factory. A QuickStarter and best practices setup for CDK projects
5
5
  Author-email: Eric Wilson <eric.wilson@geekcafe.com>
6
6
  License: MIT License
@@ -1,7 +1,7 @@
1
1
  cdk_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  cdk_factory/app.py,sha256=xv863N7O6HPKznB68_t7O4la9JacrkG87t9TjoDUk7s,2827
3
3
  cdk_factory/cdk.json,sha256=SKZKhJ2PBpFH78j-F8S3VDYW-lf76--Q2I3ON-ZIQfw,3106
4
- cdk_factory/version.py,sha256=4c9Y6kqbBff_PtGI0UeOh2f4HPFaCOvIx0KdnuUqM7c,23
4
+ cdk_factory/version.py,sha256=CtvyqFRtdJwNvYSDVmaT9l1R18bsaIwflR8r696jttk,23
5
5
  cdk_factory/builds/README.md,sha256=9BBWd7bXpyKdMU_g2UljhQwrC9i5O_Tvkb6oPvndoZk,90
6
6
  cdk_factory/commands/command_loader.py,sha256=QbLquuP_AdxtlxlDy-2IWCQ6D-7qa58aphnDPtp_uTs,3744
7
7
  cdk_factory/configurations/base_config.py,sha256=JKjhNsy0RCUZy1s8n5D_aXXI-upR9izaLtCTfKYiV9k,9624
@@ -46,7 +46,7 @@ cdk_factory/configurations/resources/security_group.py,sha256=8kQtaaRVEn2aDm8XoC
46
46
  cdk_factory/configurations/resources/security_group_full_stack.py,sha256=x5MIMCa_olO7prFBKx9zVOfvsVdKo-2mWyhrCy27dFw,2031
47
47
  cdk_factory/configurations/resources/sqs.py,sha256=fAh2dqttJ6PX46enFRULuiLEu3TEj0Vb2xntAOgUpYE,4346
48
48
  cdk_factory/configurations/resources/vpc.py,sha256=sNn6w76bHFwmt6N76gZZhqpsuNB9860C1SZu6tebaXY,3835
49
- cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py,sha256=84RF7eH7LW2fkqJIQmH3kI1xTb5vbdZShE-0Xb65Gek,12194
49
+ cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py,sha256=7uDkDbFigeUOuYgsQ9ghA4dGlx63rUCa6Iiq4RWokEA,14627
50
50
  cdk_factory/constructs/ecr/ecr_construct.py,sha256=s0egnh4U7qgCSn_LLq1soRLWSxsFjrTx8P591AjkN84,7025
51
51
  cdk_factory/constructs/lambdas/lambda_function_construct.py,sha256=SQ5SEXn4kezVAzXuv_A_JB3o_svyBXOMi-htvfB9HQs,4516
52
52
  cdk_factory/constructs/lambdas/lambda_function_docker_construct.py,sha256=aSyn3eh1YnuIahZ7CbZ5WswwPL8u70ZibMoS24QQifc,9907
@@ -112,7 +112,7 @@ cdk_factory/utilities/lambda_function_utilities.py,sha256=j3tBdv_gC2MdEwBINDwAqY
112
112
  cdk_factory/utilities/os_execute.py,sha256=5Op0LY_8Y-pUm04y1k8MTpNrmQvcLmQHPQITEP7EuSU,1019
113
113
  cdk_factory/utils/api_gateway_utilities.py,sha256=If7Xu5s_UxmuV-kL3JkXxPLBdSVUKoLtohm0IUFoiV8,4378
114
114
  cdk_factory/workload/workload_factory.py,sha256=yBUDGIuB8-5p_mGcVFxsD2ZoZIziak3yh3LL3JvS0M4,5903
115
- cdk_factory-0.7.30.dist-info/METADATA,sha256=DHv28uW3uNKA65mnxlQXO3PQxnoaaYAdtPlTZuaM-9E,2451
116
- cdk_factory-0.7.30.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
117
- cdk_factory-0.7.30.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
118
- cdk_factory-0.7.30.dist-info/RECORD,,
115
+ cdk_factory-0.7.31.dist-info/METADATA,sha256=4M-frbniUr3CWM1NoNqV5rdJ9vZH_1nZADAJzyOEB78,2451
116
+ cdk_factory-0.7.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
117
+ cdk_factory-0.7.31.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
118
+ cdk_factory-0.7.31.dist-info/RECORD,,