Adds keyId support to apigateway get_usage_plans

apigateway is able to filter the result set, returning only usage plans
with the given keyId.

This commit supports filtering the usage plans returned to the user by
filtering the list of usage plans by checking for usage plan keys
This commit is contained in:
George Alton 2018-10-17 13:44:00 +01:00
commit d919024510
No known key found for this signature in database
GPG key ID: BF2E281ABF61709E
3 changed files with 44 additions and 3 deletions

View file

@ -606,8 +606,15 @@ class APIGatewayBackend(BaseBackend):
self.usage_plans[plan['id']] = plan
return plan
def get_usage_plans(self):
return list(self.usage_plans.values())
def get_usage_plans(self, api_key_id=None):
plans = list(self.usage_plans.values())
if api_key_id is not None:
plans = [
plan
for plan in plans
if self.usage_plan_keys.get(plan['id'], {}).get(api_key_id, False)
]
return plans
def get_usage_plan(self, usage_plan_id):
return self.usage_plans[usage_plan_id]

View file

@ -255,7 +255,8 @@ class APIGatewayResponse(BaseResponse):
if self.method == 'POST':
usage_plan_response = self.backend.create_usage_plan(json.loads(self.body))
elif self.method == 'GET':
usage_plans_response = self.backend.get_usage_plans()
api_key_id = self.querystring.get("keyId", [None])[0]
usage_plans_response = self.backend.get_usage_plans(api_key_id=api_key_id)
return 200, {}, json.dumps({"item": usage_plans_response})
return 200, {}, json.dumps(usage_plan_response)