Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
feat(cfn): support API Gateway request validators (#1189)
robert-pitt-foodhub292db2be6af1
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex 0b9473cc..45456a39 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -2420,24 +2420,22 @@ def _apigw_documentation_part_delete(physical_id, props):_apigw_v1._delete_documentation_part(api_id, physical_id)-# --- API Gateway DocumentationVersion ---+# --- API Gateway RequestValidator ----def _apigw_documentation_version_identity(props):- return f"{props.get('RestApiId', '')}/{props.get('DocumentationVersion', '')}"+def _apigw_request_validator_create(logical_id, props, stack_name):+ validator_id = new_uuid().replace("-", "")[:8]+ return validator_id, {"RequestValidatorId": validator_id}-def _apigw_documentation_version_create(logical_id, props, stack_name):- # Documentation snapshots do not affect MiniStack's permissive local API- # request handling. A native CFN identity is sufficient for templates and- # dependent resources to complete their lifecycle.- return _apigw_documentation_version_identity(props), {}+def _apigw_request_validator_update(physical_id, old_props, new_props, stack_name):+ # RestApiId and Name require replacement. Validation flags update in place;+ # request handling remains deliberately permissive in the local data plane.+ if any(new_props.get(key) != old_props.get(key) for key in ("RestApiId", "Name")):+ return _apigw_request_validator_create(physical_id, new_props, stack_name)+ return physical_id, {"RequestValidatorId": physical_id}-def _apigw_documentation_version_update(physical_id, old_props, new_props, stack_name):- return _apigw_documentation_version_identity(new_props), {}---def _apigw_documentation_version_delete(physical_id, props):+def _apigw_request_validator_delete(physical_id, props):pass@@ -5315,6 +5313,10 @@ _RESOURCE_HANDLERS = {"update": _apigw_documentation_part_update,"delete": _apigw_documentation_part_delete,},+ "AWS::ApiGateway::RequestValidator": {+ "create": _apigw_request_validator_create,+ "update": _apigw_request_validator_update,+ "delete": _apigw_request_validator_delete,"AWS::ApiGateway::DocumentationVersion": {"create": _apigw_documentation_version_create,"update": _apigw_documentation_version_update,diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 37a3af26..786eac21 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -5151,46 +5151,56 @@ def test_cfn_apigateway_documentation_part_lifecycle(cfn, apigw_v1):apigw_v1.delete_rest_api(restApiId=api_id)-def test_cfn_apigateway_documentation_version_lifecycle(cfn, apigw_v1):- """DocumentationVersion has a stable CFN identity and supports replacement."""+def test_cfn_apigateway_request_validator_identity(cfn, apigw_v1):+ """RequestValidator exposes its ID while local requests remain permissive."""suffix = _uuid_mod.uuid4().hex[:8]- stack_name = f"cfn-documentation-version-{suffix}"- api_id = apigw_v1.create_rest_api(name=f"documentation-version-{suffix}")["id"]+ stack_name = f"cfn-request-validator-{suffix}"+ api_id = apigw_v1.create_rest_api(name=f"request-validator-{suffix}")["id"]- def template(version, description):+ def template(name, validate_body):return {"Resources": {- "DocumentationVersion": {- "Type": "AWS::ApiGateway::DocumentationVersion",+ "RequestValidator": {+ "Type": "AWS::ApiGateway::RequestValidator","Properties": {"RestApiId": api_id,- "DocumentationVersion": version,- "Description": description,+ "Name": name,+ "ValidateRequestBody": validate_body,+ "ValidateRequestParameters": True,},},},+ "Outputs": {+ "RefId": {"Value": {"Ref": "RequestValidator"}},+ "GetAttId": {+ "Value": {+ "Fn::GetAtt": ["RequestValidator", "RequestValidatorId"]+ }+ },+ },}def physical_id():detail = cfn.describe_stack_resource(StackName=stack_name,- LogicalResourceId="DocumentationVersion",+ LogicalResourceId="RequestValidator",)["StackResourceDetail"]return detail["PhysicalResourceId"]try:cfn.create_stack(StackName=stack_name,- TemplateBody=json.dumps(template("v1", "Created")),+ TemplateBody=json.dumps(template("body-and-parameters", True)),)stack = _wait_stack(cfn, stack_name)assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")created_id = physical_id()- assert created_id == f"{api_id}/v1"+ outputs = {item["OutputKey"]: item["OutputValue"] for item in stack["Outputs"]}+ assert outputs == {"RefId": created_id, "GetAttId": created_id}cfn.update_stack(StackName=stack_name,- TemplateBody=json.dumps(template("v1", "Updated")),+ TemplateBody=json.dumps(template("body-and-parameters", False)),)stack = _wait_stack(cfn, stack_name)assert stack["StackStatus"] == "UPDATE_COMPLETE", stack.get("StackStatusReason")@@ -5198,11 +5208,11 @@ def test_cfn_apigateway_documentation_version_lifecycle(cfn, apigw_v1):cfn.update_stack(StackName=stack_name,- TemplateBody=json.dumps(template("v2", "Replacement")),+ TemplateBody=json.dumps(template("replacement", False)),)stack = _wait_stack(cfn, stack_name)assert stack["StackStatus"] == "UPDATE_COMPLETE", stack.get("StackStatusReason")- assert physical_id() == f"{api_id}/v2"+ assert physical_id() != created_idfinally:try:cfn.delete_stack(StackName=stack_name)