mod dynamodb_table;
mod ecs_cluster;
mod elbv2_listener;
mod elbv2_load_balancer;
mod elbv2_target_group;
mod kms_key;
use std::collections::HashMap;
use std::sync::OnceLock;
use serde_json::Value;
pub struct ShapeContext<'a> {
pub region: &'a str,
pub account_id: &'a str,
}
pub struct ShapedResource {
pub primary_identifier: String,
pub properties: Value,
}
pub trait CfnResourceShaper: Send + Sync {
fn shape_create(
&self,
desired_state: &Value,
ctx: &ShapeContext<'_>,
) -> Result<ShapedResource, String>;
fn shape_update(
&self,
_previous: &Value,
patched: Value,
_ctx: &ShapeContext<'_>,
) -> Result<Value, String> {
Ok(patched)
}
}
type ShaperBox = Box<dyn CfnResourceShaper>;
fn registry() -> &'static HashMap<&'static str, ShaperBox> {
static REGISTRY: OnceLock<HashMap<&'static str, ShaperBox>> = OnceLock::new();
REGISTRY.get_or_init(|| {
let mut m: HashMap<&'static str, ShaperBox> = HashMap::new();
m.insert(
"AWS::DynamoDB::Table",
Box::new(dynamodb_table::DynamoDbTableShaper),
);
m.insert("AWS::ECS::Cluster", Box::new(ecs_cluster::EcsClusterShaper));
m.insert(
"AWS::ElasticLoadBalancingV2::Listener",
Box::new(elbv2_listener::ElbV2ListenerShaper),
);
m.insert(
"AWS::ElasticLoadBalancingV2::LoadBalancer",
Box::new(elbv2_load_balancer::ElbV2LoadBalancerShaper),
);
m.insert(
"AWS::ElasticLoadBalancingV2::TargetGroup",
Box::new(elbv2_target_group::ElbV2TargetGroupShaper),
);
m.insert("AWS::KMS::Key", Box::new(kms_key::KmsKeyShaper));
m
})
}
pub fn lookup(type_name: &str) -> Option<&'static dyn CfnResourceShaper> {
registry().get(type_name).map(|b| b.as_ref())
}