Skip to content

Commit

Permalink
Revert "Bump moto-ext to 5.0.6.post2 (#10742)"
Browse files Browse the repository at this point in the history
This reverts commit ecd7dc8.
  • Loading branch information
bentsku committed May 16, 2024
1 parent 4068c66 commit 7f6cf72
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 74 deletions.
66 changes: 54 additions & 12 deletions localstack/services/apigateway/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,50 @@ def apigateway_models_Stage_init(
apigateway_models_Stage_init_orig = apigateway_models.Stage.__init__
apigateway_models.Stage.__init__ = apigateway_models_Stage_init

@patch(APIGatewayResponse.put_integration)
def apigateway_put_integration(fn, self, *args, **kwargs):
# TODO: verify if this patch is still necessary, this might have been fixed upstream
fn(self, *args, **kwargs)
@patch(APIGatewayResponse.integrations)
def apigateway_response_integrations(fn, self, request, *args, **kwargs):
result = fn(self, request, *args, **kwargs)

if self.method not in ["PUT", "PATCH"]:
return result

url_path_parts = self.path.split("/")
function_id = url_path_parts[2]
resource_id = url_path_parts[4]
method_type = url_path_parts[6]

integration = self.backend.get_integration(function_id, resource_id, method_type)
if not integration:
return result

if self.method == "PUT":
timeout_milliseconds = self._get_param("timeoutInMillis")
cache_key_parameters = self._get_param("cacheKeyParameters") or []
content_handling = self._get_param("contentHandling")
integration.cache_namespace = resource_id
integration.timeout_in_millis = timeout_milliseconds
integration.cache_key_parameters = cache_key_parameters
integration.content_handling = content_handling
return 201, {}, json.dumps(integration.to_json())

if self.method == "PATCH":
patch_operations = self._get_param("patchOperations")
apply_json_patch_safe(integration.to_json(), patch_operations, in_place=True)
# fix data types
if integration.timeout_in_millis:
integration.timeout_in_millis = int(integration.timeout_in_millis)
if skip_verification := (integration.tls_config or {}).get("insecureSkipVerification"):
integration.tls_config["insecureSkipVerification"] = str_to_bool(skip_verification)
return 200, {}, json.dumps(integration.to_json())

return result

timeout_milliseconds = self._get_param("timeoutInMillis")
cache_key_parameters = self._get_param("cacheKeyParameters") or []
content_handling = self._get_param("contentHandling")
integration.cache_namespace = resource_id
integration.timeout_in_millis = timeout_milliseconds
integration.cache_key_parameters = cache_key_parameters
integration.content_handling = content_handling
return 201, {}, json.dumps(integration.to_json())
def backend_update_deployment(self, function_id, deployment_id, patch_operations):
rest_api = self.get_rest_api(function_id)
deployment = rest_api.get_deployment(deployment_id)
deployment = deployment.to_json() or {}
apply_json_patch_safe(deployment, patch_operations, in_place=True)
return deployment

# define json-patch operations for backend models

Expand Down Expand Up @@ -115,6 +140,9 @@ def apigateway_models_resource_get_integration(fn, self, method_type):
raise NoIntegrationDefined()
return resource_method.method_integration

if not hasattr(apigateway_models.APIGatewayBackend, "update_deployment"):
apigateway_models.APIGatewayBackend.update_deployment = backend_update_deployment

@patch(apigateway_models.RestAPI.to_dict)
def apigateway_models_rest_api_to_dict(fn, self):
resp = fn(self)
Expand Down Expand Up @@ -144,6 +172,20 @@ def apigateway_models_stage_to_json(fn, self):

return result

@patch(APIGatewayResponse.individual_deployment)
def individual_deployment(fn, self, request, full_url, headers, *args, **kwargs):
result = fn(self, request, full_url, headers, *args, **kwargs)
if self.method == "PATCH":
url_path_parts = self.path.split("/")
function_id = url_path_parts[2]
deployment_id = url_path_parts[4]
patch_operations = self._get_param("patchOperations")
deployment = self.backend.update_deployment(
function_id, deployment_id, patch_operations
)
return 201, {}, json.dumps(deployment)
return result

@patch(apigateway_models.APIGatewayBackend.create_rest_api)
def create_rest_api(fn, self, *args, tags=None, **kwargs):
"""
Expand Down
57 changes: 0 additions & 57 deletions localstack/services/apigateway/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
CreateAuthorizerRequest,
CreateRestApiRequest,
CreateStageRequest,
Deployment,
DocumentationPart,
DocumentationPartIds,
DocumentationPartLocation,
Expand Down Expand Up @@ -1065,32 +1064,6 @@ def _patch_stage_response(self, response: dict):
if not response.get("variables"):
response.pop("variables", None)

def update_deployment(
self,
context: RequestContext,
rest_api_id: String,
deployment_id: String,
patch_operations: ListOfPatchOperation = None,
**kwargs,
) -> Deployment:
moto_rest_api = get_moto_rest_api(context, rest_api_id)
try:
deployment = moto_rest_api.get_deployment(deployment_id)
except KeyError:
raise NotFoundException("Invalid Deployment identifier specified")

for patch_operation in patch_operations:
# TODO: add validation for unsupported paths
# see https://docs.aws.amazon.com/apigateway/latest/api/patch-operations.html#UpdateDeployment-Patch
if (
patch_operation.get("path") == "/description"
and patch_operation.get("op") == "replace"
):
deployment.description = patch_operation["value"]

deployment_response: Deployment = deployment.to_json() or {}
return deployment_response

# authorizers

@handler("CreateAuthorizer", expand=False)
Expand Down Expand Up @@ -1923,36 +1896,6 @@ def put_integration(

return response

def update_integration(
self,
context: RequestContext,
rest_api_id: String,
resource_id: String,
http_method: String,
patch_operations: ListOfPatchOperation = None,
**kwargs,
) -> Integration:
moto_rest_api = get_moto_rest_api(context=context, rest_api_id=rest_api_id)
resource = moto_rest_api.resources.get(resource_id)
if not resource:
raise NotFoundException("Invalid Resource identifier specified")

method = resource.resource_methods.get(http_method)
if not method:
raise NotFoundException("Invalid Integration identifier specified")

integration = method.method_integration
_patch_api_gateway_entity(integration, patch_operations)

# fix data types
if integration.timeout_in_millis:
integration.timeout_in_millis = int(integration.timeout_in_millis)
if skip_verification := (integration.tls_config or {}).get("insecureSkipVerification"):
integration.tls_config["insecureSkipVerification"] = str_to_bool(skip_verification)

integration_dict: Integration = integration.to_json()
return integration_dict

def delete_integration(
self,
context: RequestContext,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ runtime = [
"json5>=0.9.11",
"jsonpath-ng>=1.6.1",
"jsonpath-rw>=1.4.0",
"moto-ext[all]==5.0.6.post2",
"moto-ext[all]==5.0.5.post1",
"opensearch-py>=2.4.1",
"pymongo>=4.2.0",
"pyopenssl>=23.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ markupsafe==2.1.5
# werkzeug
mdurl==0.1.2
# via markdown-it-py
moto-ext==5.0.6.post2
moto-ext==5.0.5.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down
2 changes: 1 addition & 1 deletion requirements-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ markupsafe==2.1.5
# werkzeug
mdurl==0.1.2
# via markdown-it-py
moto-ext==5.0.6.post2
moto-ext==5.0.5.post1
# via localstack-core (pyproject.toml)
mpmath==1.3.0
# via sympy
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ markupsafe==2.1.5
# werkzeug
mdurl==0.1.2
# via markdown-it-py
moto-ext==5.0.6.post2
moto-ext==5.0.5.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down
2 changes: 1 addition & 1 deletion requirements-typehint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ markupsafe==2.1.5
# werkzeug
mdurl==0.1.2
# via markdown-it-py
moto-ext==5.0.6.post2
moto-ext==5.0.5.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down

0 comments on commit 7f6cf72

Please sign in to comment.