Added implementation for create-model,get-models,get-model in api gateway
This commit is contained in:
parent
48288d8bb1
commit
79e63e3bcf
5 changed files with 337 additions and 1 deletions
|
|
@ -13,6 +13,10 @@ from .exceptions import (
|
|||
ApiKeyAlreadyExists,
|
||||
DomainNameNotFound,
|
||||
InvalidDomainName,
|
||||
InvalidRestApiId,
|
||||
InvalidModelName,
|
||||
RestAPINotFound,
|
||||
ModelNotFound
|
||||
)
|
||||
|
||||
API_KEY_SOURCES = ["AUTHORIZER", "HEADER"]
|
||||
|
|
@ -595,3 +599,67 @@ class APIGatewayResponse(BaseResponse):
|
|||
error.message, error.error_type
|
||||
),
|
||||
)
|
||||
|
||||
def models(self,request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
rest_api_id = self.path.replace("/restapis/", "", 1).split("/")[0]
|
||||
|
||||
try:
|
||||
if self.method == "GET":
|
||||
models = self.backend.get_models(
|
||||
rest_api_id
|
||||
)
|
||||
return 200, {}, json.dumps({"item": models})
|
||||
|
||||
elif self.method == "POST":
|
||||
name = self._get_param("name")
|
||||
description = self._get_param("description")
|
||||
schema = self._get_param("schema")
|
||||
content_type = self._get_param("contentType")
|
||||
cli_input_json = self._get_param("cliInputJson")
|
||||
generate_cli_skeleton = self._get_param(
|
||||
"generateCliSkeleton"
|
||||
)
|
||||
model = self.backend.create_model(
|
||||
rest_api_id,
|
||||
name,
|
||||
content_type,
|
||||
description,
|
||||
schema,
|
||||
cli_input_json,
|
||||
generate_cli_skeleton
|
||||
)
|
||||
|
||||
return 200, {}, json.dumps(model)
|
||||
|
||||
except (InvalidRestApiId, InvalidModelName,RestAPINotFound) as error:
|
||||
return (
|
||||
error.code,
|
||||
{},
|
||||
'{{"message":"{0}","code":"{1}"}}'.format(
|
||||
error.message, error.error_type
|
||||
),
|
||||
)
|
||||
|
||||
def model_induvidual(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
url_path_parts = self.path.split("/")
|
||||
rest_api_id = url_path_parts[2]
|
||||
model_name = url_path_parts[4]
|
||||
model_info = {}
|
||||
try:
|
||||
if self.method == "GET":
|
||||
model_info = self.backend.get_model(
|
||||
rest_api_id,
|
||||
model_name
|
||||
)
|
||||
return 200, {}, json.dumps(model_info)
|
||||
except (ModelNotFound, RestAPINotFound, InvalidRestApiId,
|
||||
InvalidModelName) as error:
|
||||
return (
|
||||
error.code,
|
||||
{},
|
||||
'{{"message":"{0}","code":"{1}"}}'.format(
|
||||
error.message, error.error_type
|
||||
),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue