Skip to content

Commit

Permalink
Add CFn schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed May 10, 2024
1 parent 7917b4a commit e47046c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions localstack/services/cloudformation/resource_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ def deploy_loop(
"A ResourceProvider should always have a SCHEMA property defined."
)
resource_type_schema = resource_provider.SCHEMA
self.validate_model_properties(
logical_resource_id=raw_payload["requestData"]["logicalResourceId"],
schema=resource_type_schema,
model=event.resource_model,
)
physical_resource_id = (
self.extract_physical_resource_id_from_model_with_schema(
event.resource_model,
Expand Down Expand Up @@ -595,6 +600,14 @@ def extract_physical_resource_id_from_model_with_schema(

return physical_resource_id

def validate_model_properties(self, logical_resource_id: str, schema: dict, model: dict):
required_fields = schema.get("required", [])
for required_field in required_fields:
if required_field not in model or model[required_field] is None:
raise ValueError(
f"Missing required field '{required_field}' in resource definition for resource '{logical_resource_id}'"
)


plugin_manager = PluginManager(CloudFormationResourceProviderPlugin.namespace)
if PRO_RESOURCE_PROVIDERS:
Expand Down

0 comments on commit e47046c

Please sign in to comment.