Merge pull request #2720 from jrbeilke/feature-apigw-defaults
Feature apigw defaults
This commit is contained in:
commit
7719ac76a3
3 changed files with 184 additions and 5 deletions
|
|
@ -394,12 +394,17 @@ class UsagePlanKey(BaseModel, dict):
|
|||
|
||||
|
||||
class RestAPI(BaseModel):
|
||||
def __init__(self, id, region_name, name, description):
|
||||
def __init__(self, id, region_name, name, description, **kwargs):
|
||||
self.id = id
|
||||
self.region_name = region_name
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.create_date = int(time.time())
|
||||
self.api_key_source = kwargs.get("api_key_source") or "HEADER"
|
||||
self.endpoint_configuration = kwargs.get("endpoint_configuration") or {
|
||||
"types": ["EDGE"]
|
||||
}
|
||||
self.tags = kwargs.get("tags") or {}
|
||||
|
||||
self.deployments = {}
|
||||
self.stages = {}
|
||||
|
|
@ -416,6 +421,9 @@ class RestAPI(BaseModel):
|
|||
"name": self.name,
|
||||
"description": self.description,
|
||||
"createdDate": int(time.time()),
|
||||
"apiKeySource": self.api_key_source,
|
||||
"endpointConfiguration": self.endpoint_configuration,
|
||||
"tags": self.tags,
|
||||
}
|
||||
|
||||
def add_child(self, path, parent_id=None):
|
||||
|
|
@ -529,9 +537,24 @@ class APIGatewayBackend(BaseBackend):
|
|||
self.__dict__ = {}
|
||||
self.__init__(region_name)
|
||||
|
||||
def create_rest_api(self, name, description):
|
||||
def create_rest_api(
|
||||
self,
|
||||
name,
|
||||
description,
|
||||
api_key_source=None,
|
||||
endpoint_configuration=None,
|
||||
tags=None,
|
||||
):
|
||||
api_id = create_id()
|
||||
rest_api = RestAPI(api_id, self.region_name, name, description)
|
||||
rest_api = RestAPI(
|
||||
api_id,
|
||||
self.region_name,
|
||||
name,
|
||||
description,
|
||||
api_key_source=api_key_source,
|
||||
endpoint_configuration=endpoint_configuration,
|
||||
tags=tags,
|
||||
)
|
||||
self.apis[api_id] = rest_api
|
||||
return rest_api
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ from .exceptions import (
|
|||
ApiKeyAlreadyExists,
|
||||
)
|
||||
|
||||
API_KEY_SOURCES = ["AUTHORIZER", "HEADER"]
|
||||
ENDPOINT_CONFIGURATION_TYPES = ["PRIVATE", "EDGE", "REGIONAL"]
|
||||
|
||||
|
||||
class APIGatewayResponse(BaseResponse):
|
||||
def error(self, type_, message, status=400):
|
||||
|
|
@ -45,7 +48,45 @@ class APIGatewayResponse(BaseResponse):
|
|||
elif self.method == "POST":
|
||||
name = self._get_param("name")
|
||||
description = self._get_param("description")
|
||||
rest_api = self.backend.create_rest_api(name, description)
|
||||
api_key_source = self._get_param("apiKeySource")
|
||||
endpoint_configuration = self._get_param("endpointConfiguration")
|
||||
tags = self._get_param("tags")
|
||||
|
||||
# Param validation
|
||||
if api_key_source and api_key_source not in API_KEY_SOURCES:
|
||||
return self.error(
|
||||
"ValidationException",
|
||||
(
|
||||
"1 validation error detected: "
|
||||
"Value '{api_key_source}' at 'createRestApiInput.apiKeySource' failed "
|
||||
"to satisfy constraint: Member must satisfy enum value set: "
|
||||
"[AUTHORIZER, HEADER]"
|
||||
).format(api_key_source=api_key_source),
|
||||
)
|
||||
|
||||
if endpoint_configuration and "types" in endpoint_configuration:
|
||||
invalid_types = list(
|
||||
set(endpoint_configuration["types"])
|
||||
- set(ENDPOINT_CONFIGURATION_TYPES)
|
||||
)
|
||||
if invalid_types:
|
||||
return self.error(
|
||||
"ValidationException",
|
||||
(
|
||||
"1 validation error detected: Value '{endpoint_type}' "
|
||||
"at 'createRestApiInput.endpointConfiguration.types' failed "
|
||||
"to satisfy constraint: Member must satisfy enum value set: "
|
||||
"[PRIVATE, EDGE, REGIONAL]"
|
||||
).format(endpoint_type=invalid_types[0]),
|
||||
)
|
||||
|
||||
rest_api = self.backend.create_rest_api(
|
||||
name,
|
||||
description,
|
||||
api_key_source=api_key_source,
|
||||
endpoint_configuration=endpoint_configuration,
|
||||
tags=tags,
|
||||
)
|
||||
return 200, {}, json.dumps(rest_api.to_dict())
|
||||
|
||||
def restapis_individual(self, request, full_url, headers):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue