ApiGateway: update_usage_plan() now supports adding apiStages (#7361)
This commit is contained in:
parent
f13ceb92b0
commit
cb82b7025d
@ -151,5 +151,13 @@ apigateway
|
|||||||
- [X] update_stage
|
- [X] update_stage
|
||||||
- [ ] update_usage
|
- [ ] update_usage
|
||||||
- [X] update_usage_plan
|
- [X] update_usage_plan
|
||||||
|
|
||||||
|
The following PatchOperations are currently supported:
|
||||||
|
add : Everything except /apiStages/{apidId:stageName}/throttle/ and children
|
||||||
|
replace: Everything except /apiStages/{apidId:stageName}/throttle/ and children
|
||||||
|
remove : Nothing yet
|
||||||
|
copy : Nothing yet
|
||||||
|
|
||||||
|
|
||||||
- [ ] update_vpc_link
|
- [ ] update_vpc_link
|
||||||
|
|
||||||
|
@ -874,21 +874,29 @@ class UsagePlan(BaseModel):
|
|||||||
for op in patch_operations:
|
for op in patch_operations:
|
||||||
path = op["path"]
|
path = op["path"]
|
||||||
value = op["value"]
|
value = op["value"]
|
||||||
|
if op["op"] == "add":
|
||||||
|
if path == "/apiStages":
|
||||||
|
self.api_stages.append(
|
||||||
|
{"apiId": value.split(":")[0], "stage": value.split(":")[1]}
|
||||||
|
)
|
||||||
if op["op"] == "replace":
|
if op["op"] == "replace":
|
||||||
if "/name" in path:
|
if "/name" in path:
|
||||||
self.name = value
|
self.name = value
|
||||||
if "/productCode" in path:
|
|
||||||
self.product_code = value
|
|
||||||
if "/description" in path:
|
if "/description" in path:
|
||||||
self.description = value
|
self.description = value
|
||||||
|
if op["op"] in ["add", "replace"]:
|
||||||
|
if "/productCode" in path:
|
||||||
|
self.product_code = value
|
||||||
if "/quota/limit" in path:
|
if "/quota/limit" in path:
|
||||||
self.quota["limit"] = value
|
self.quota["limit"] = value
|
||||||
if "/quota/period" in path:
|
if "/quota/period" in path:
|
||||||
self.quota["period"] = value
|
self.quota["period"] = value
|
||||||
|
if path == "/quota/offset":
|
||||||
|
self.quota["offset"] = value
|
||||||
if "/throttle/rateLimit" in path:
|
if "/throttle/rateLimit" in path:
|
||||||
self.throttle["rateLimit"] = value
|
self.throttle["rateLimit"] = int(value)
|
||||||
if "/throttle/burstLimit" in path:
|
if "/throttle/burstLimit" in path:
|
||||||
self.throttle["burstLimit"] = value
|
self.throttle["burstLimit"] = int(value)
|
||||||
|
|
||||||
|
|
||||||
class RequestValidator(BaseModel):
|
class RequestValidator(BaseModel):
|
||||||
@ -2103,6 +2111,13 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
return self.usage_plans[usage_plan_id]
|
return self.usage_plans[usage_plan_id]
|
||||||
|
|
||||||
def update_usage_plan(self, usage_plan_id: str, patch_operations: Any) -> UsagePlan:
|
def update_usage_plan(self, usage_plan_id: str, patch_operations: Any) -> UsagePlan:
|
||||||
|
"""
|
||||||
|
The following PatchOperations are currently supported:
|
||||||
|
add : Everything except /apiStages/{apidId:stageName}/throttle/ and children
|
||||||
|
replace: Everything except /apiStages/{apidId:stageName}/throttle/ and children
|
||||||
|
remove : Nothing yet
|
||||||
|
copy : Nothing yet
|
||||||
|
"""
|
||||||
if usage_plan_id not in self.usage_plans:
|
if usage_plan_id not in self.usage_plans:
|
||||||
raise UsagePlanNotFoundException()
|
raise UsagePlanNotFoundException()
|
||||||
self.usage_plans[usage_plan_id].apply_patch_operations(patch_operations)
|
self.usage_plans[usage_plan_id].apply_patch_operations(patch_operations)
|
||||||
|
@ -1701,13 +1701,28 @@ def test_update_usage_plan():
|
|||||||
payload = {
|
payload = {
|
||||||
"name": "TEST-PLAN-2",
|
"name": "TEST-PLAN-2",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"quota": {"limit": 10, "period": "DAY", "offset": 0},
|
|
||||||
"throttle": {"rateLimit": 2, "burstLimit": 1},
|
|
||||||
"apiStages": [{"apiId": "foo", "stage": "bar"}],
|
|
||||||
"tags": {"tag_key": "tag_value"},
|
"tags": {"tag_key": "tag_value"},
|
||||||
}
|
}
|
||||||
response = client.create_usage_plan(**payload)
|
response = client.create_usage_plan(**payload)
|
||||||
usage_plan_id = response["id"]
|
usage_plan_id = response["id"]
|
||||||
|
|
||||||
|
add = client.update_usage_plan(
|
||||||
|
usagePlanId=usage_plan_id,
|
||||||
|
patchOperations=[
|
||||||
|
{"op": "add", "path": "/apiStages", "value": "foo:bar"},
|
||||||
|
{"op": "add", "path": "/productCode", "value": "mypc"},
|
||||||
|
{"op": "add", "path": "/quota/limit", "value": "1"},
|
||||||
|
{"op": "add", "path": "/quota/offset", "value": "2"},
|
||||||
|
{"op": "add", "path": "/quota/period", "value": "DAY"},
|
||||||
|
{"op": "add", "path": "/throttle/burstLimit", "value": "11"},
|
||||||
|
{"op": "add", "path": "/throttle/rateLimit", "value": "12"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert add["apiStages"] == [{"apiId": "foo", "stage": "bar"}]
|
||||||
|
assert add["productCode"] == "mypc"
|
||||||
|
assert add["quota"] == {"limit": 1, "offset": 2, "period": "DAY"}
|
||||||
|
assert add["throttle"] == {"burstLimit": 11, "rateLimit": 12}
|
||||||
|
|
||||||
response = client.update_usage_plan(
|
response = client.update_usage_plan(
|
||||||
usagePlanId=usage_plan_id,
|
usagePlanId=usage_plan_id,
|
||||||
patchOperations=[
|
patchOperations=[
|
||||||
|
Loading…
Reference in New Issue
Block a user