8000 fix APIGW UpdateStage for methods settings (#9334) · codeperl/localstack@cc1efb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc1efb8

Browse files
authored
fix APIGW UpdateStage for methods settings (localstack#9334)
1 parent 3d1f104 commit cc1efb8

File tree

4 files changed

+141
-5
lines changed

4 files changed

+141
-5
lines changed

localstack/services/apigateway/patches.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,19 @@ def backend_model_apply_operations(self, patch_operations):
143143
@patch(apigateway_models.Stage._get_default_method_settings)
144144
def _get_default_method_settings(fn, self):
145145
result = fn(self)
146-
result["cacheDataEncrypted"] = False
147-
result["throttlingRateLimit"] = 10000.0
146+
default_settings = self.method_settings.get("*/*", {})
147+
result["cacheDataEncrypted"] = default_settings.get("cacheDataEncrypted", False)
148+
result["throttlingRateLimit"] = default_settings.get("throttlingRateLimit", 10000.0)
149+
result["metricsEnabled"] = default_settings.get("metricsEnabled", False)
150+
result["dataTraceEnabled"] = default_settings.get("dataTraceEnabled", False)
151+
result["unauthorizedCacheControlHeaderStrategy"] = default_settings.get(
152+
"unauthorizedCacheControlHeaderStrategy", "SUCCEED_WITH_RESPONSE_HEADER"
153+
)
154+
result["cacheTtlInSeconds"] = default_settings.get("cacheTtlInSeconds", 300)
155+
result["cachingEnabled"] = default_settings.get("cachingEnabled", False)
156+
result["requireAuthorizationForCacheControl"] = default_settings.get(
157+
"requireAuthorizationForCacheControl", True
158+
)
148159
return result
149160

150161
# patch integration error responses

localstack/services/apigateway/provider.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@
138138
"/{resourcePath}/{httpMethod}/metrics/enabled",
139139
"/{resourcePath}/{httpMethod}/logging/dataTrace",
140140
"/{resourcePath}/{httpMethod}/logging/loglevel",
141-
"/{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds",
141+
"/{resourcePath}/{httpMethod}/throttling/burstLimit",
142+
"/{resourcePath}/{httpMethod}/throttling/rateLimit",
143+
"/{resourcePath}/{httpMethod}/caching/ttlInSeconds",
142144
"/{resourcePath}/{httpMethod}/caching/enabled",
143145
"/{resourcePath}/{httpMethod}/caching/dataEncrypted",
144146
"/{resourcePath}/{httpMethod}/caching/requireAuthorizationForCacheControl",
@@ -940,6 +942,10 @@ def update_stage(
940942
if not path_valid:
941943
valid_paths = f"[{', '.join(STAGE_UPDATE_PATHS)}]"
942944
# note: weird formatting in AWS - required for snapshot testing
945+
valid_paths = valid_paths.replace(
946+
"/{resourcePath}/{httpMethod}/throttling/burstLimit, /{resourcePath}/{httpMethod}/throttling/rateLimit, /{resourcePath}/{httpMethod}/caching/ttlInSeconds",
947+
"/{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds",
948+
)
943949
valid_paths = valid_paths.replace("/burstLimit, /", "/burstLimit /")
944950
valid_paths = valid_paths.replace("/rateLimit, /", "/rateLimit /")
945951
raise BadRequestException(

tests/aws/services/apigateway/test_apigateway_common.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ def test_create_update_stages(
539539
snapshot.match("error-update-tags", ctx.value.response)
540540

541541
# update & get stage
542-
543542
response = client.update_stage(
544543
restApiId=api_id,
545544
stageName="s1",
@@ -550,13 +549,25 @@ def test_create_update_stages(
550549
{"op": "replace", "path": "/*/*/throttling/burstLimit", "value": "123"},
551550
{"op": "replace", "path": "/*/*/caching/enabled", "value": "true"},
552551
{"op": "replace", "path": "/tracingEnabled", "value": "true"},
552+
{"op": "replace", "path": "/test/GET/throttling/burstLimit", "value": "124"},
553553
],
554554
)
555555
snapshot.match("update-stage", response)
556556

557557
response = client.get_stage(restApiId=api_id, stageName="s1")
558558
snapshot.match("get-stage", response)
559559

560+
# show that updating */* does not override previously set values, only provides default values then like shown
561+
# above
562+
response = client.update_stage(
563+
restApiId=api_id,
564+
stageName="s1",
565+
patchOperations=[
566+
{"op": "replace", "path": "/*/*/throttling/burstLimit", "value": "100"},
567+
],
568+
)
569+
snapshot.match("update-stage-override", response)
570+
560571

561572
class TestDeployments:
562573
@markers.aws.validated

tests/aws/services/apigateway/test_apigateway_common.snapshot.json

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
}
372372
},
373373
"tests/aws/services/apigateway/test_apigateway_common.py::TestStages::test_create_update_stages": {
374-
"recorded-date": "01-09-2023, 00:33:13",
374+
"recorded-date": "11-10-2023, 17:39:23",
375375
"recorded-content": {
376376
"create-stage": {
377377
"cacheClusterEnabled": false,
@@ -430,6 +430,17 @@
430430
"throttlingBurstLimit": 123,
431431
"throttlingRateLimit": 10000.0,
432432
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
433+
},
434+
"test/GET": {
435+
"cacheDataEncrypted": false,
436+
"cacheTtlInSeconds": 300,
437+
"cachingEnabled": true,
438+
"dataTraceEnabled": false,
439+
"metricsEnabled": false,
440+
"requireAuthorizationForCacheControl": true,
441+
"throttlingBurstLimit": 124,
442+
"throttlingRateLimit": 10000.0,
443+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
433444
}
434445
},
435446
"stageName": "s1",
@@ -462,6 +473,103 @@
462473
"throttlingBurstLimit": 123,
463474
"throttlingRateLimit": 10000.0,
464475
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
476+
},
477+
"test/GET": {
478+
"cacheDataEncrypted": false,
479+
"cacheTtlInSeconds": 300,
480+
"cachingEnabled": true,
481+
"dataTraceEnabled": false,
482+
"metricsEnabled": false,
483+
"requireAuthorizationForCacheControl": true,
484+
"throttlingBurstLimit": 124,
485+
"throttlingRateLimit": 10000.0,
486+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
487+
}
488+
},
489+
"stageName": "s1",
490+
"tracingEnabled": true,
491+
"variables": {
492+
"var1": "test",
493+
"var2": "test2"
494+
},
495+
"ResponseMetadata": {
496+
"HTTPHeaders": {},
497+
"HTTPStatusCode": 200
498+
}
499+
},
500+
"update-stage-override": {
501+
"cacheClusterEnabled": false,
502+
"cacheClusterStatus": "NOT_AVAILABLE",
503+
"createdDate": "datetime",
504+
"deploymentId": "<deployment-id:1>",
505+
"description": "stage new",
506+
"documentationVersion": "v123",
507+
"lastUpdatedDate": "datetime",
508+
"methodSettings": {
509+
"*/*": {
510+
"cacheDataEncrypted": false,
511+
"cacheTtlInSeconds": 300,
512+
"cachingEnabled": true,
513+
"dataTraceEnabled": false,
514+
"metricsEnabled": false,
515+
"requireAuthorizationForCacheControl": true,
516+
"throttlingBurstLimit": 100,
517+
"throttlingRateLimit": 10000.0,
518+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
519+
},
520+
"test/GET": {
521+
"cacheDataEncrypted": false,
522+
"cacheTtlInSeconds": 300,
523+
"cachingEnabled": true,
524+
"dataTraceEnabled": false,
525+
"metricsEnabled": false,
526+
"requireAuthorizationForCacheControl": true,
527+
"throttlingBurstLimit": 124,
528+
"throttlingRateLimit": 10000.0,
529+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
530+
}
531+
},
532+
"stageName": "s1",
533+
"tracingEnabled": true,
534+
"variables": {
535+
"var1": "test",
536+
"var2": "test2"
537+
},
538+
"ResponseMetadata": {
539+
"HTTPHeaders": {},
540+
"HTTPStatusCode": 200
541+
}
542+
},
543+
"get-stage-override": {
544+
"cacheClusterEnabled": false,
545+
"cacheClusterStatus": "NOT_AVAILABLE",
546+
"createdDate": "datetime",
547+
"deploymentId": "<deployment-id:1>",
548+
"description": "stage new",
549+
"documentationVersion": "v123",
550+
"lastUpdatedDate": "datetime",
551+
"methodSettings": {
552+
"*/*": {
553+
"cacheDataEncrypted": false,
554+
"cacheTtlInSeconds": 300,
555+
"cachingEnabled": true,
556+
"dataTraceEnabled": false,
557+
"metricsEnabled": false,
558+
"requireAuthorizationForCacheControl": true,
559+
"throttlingBurstLimit": 100,
560+
"throttlingRateLimit": 10000.0,
561+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
562+
},
563+
"test/GET": {
564+
"cacheDataEncrypted": false,
565+
"cacheTtlInSeconds": 300,
566+
"cachingEnabled": true,
567+
"dataTraceEnabled": false,
568+
"metricsEnabled": false,
569+
"requireAuthorizationForCacheControl": true,
570+
"throttlingBurstLimit": 124,
571+
"throttlingRateLimit": 10000.0,
572+
"unauthorizedCacheControlHeaderStrategy": "SUCCEED_WITH_RESPONSE_HEADER"
465573
}
466574
},
467575
"stageName": "s1",

0 commit comments

Comments
 (0)
0