winterbaume_cloudcontrol/cfn_schema/
mod.rs1mod dynamodb_table;
13mod ecs_cluster;
14mod elbv2_listener;
15mod elbv2_load_balancer;
16mod elbv2_target_group;
17mod kms_key;
18
19use std::collections::HashMap;
20use std::sync::OnceLock;
21
22use serde_json::Value;
23
24pub struct ShapeContext<'a> {
27 pub region: &'a str,
28 pub account_id: &'a str,
29}
30
31pub struct ShapedResource {
33 pub primary_identifier: String,
36 pub properties: Value,
39}
40
41pub trait CfnResourceShaper: Send + Sync {
42 fn shape_create(
44 &self,
45 desired_state: &Value,
46 ctx: &ShapeContext<'_>,
47 ) -> Result<ShapedResource, String>;
48
49 fn shape_update(
52 &self,
53 _previous: &Value,
54 patched: Value,
55 _ctx: &ShapeContext<'_>,
56 ) -> Result<Value, String> {
57 Ok(patched)
58 }
59}
60
61type ShaperBox = Box<dyn CfnResourceShaper>;
62
63fn registry() -> &'static HashMap<&'static str, ShaperBox> {
64 static REGISTRY: OnceLock<HashMap<&'static str, ShaperBox>> = OnceLock::new();
65 REGISTRY.get_or_init(|| {
66 let mut m: HashMap<&'static str, ShaperBox> = HashMap::new();
67 m.insert(
68 "AWS::DynamoDB::Table",
69 Box::new(dynamodb_table::DynamoDbTableShaper),
70 );
71 m.insert("AWS::ECS::Cluster", Box::new(ecs_cluster::EcsClusterShaper));
72 m.insert(
73 "AWS::ElasticLoadBalancingV2::Listener",
74 Box::new(elbv2_listener::ElbV2ListenerShaper),
75 );
76 m.insert(
77 "AWS::ElasticLoadBalancingV2::LoadBalancer",
78 Box::new(elbv2_load_balancer::ElbV2LoadBalancerShaper),
79 );
80 m.insert(
81 "AWS::ElasticLoadBalancingV2::TargetGroup",
82 Box::new(elbv2_target_group::ElbV2TargetGroupShaper),
83 );
84 m.insert("AWS::KMS::Key", Box::new(kms_key::KmsKeyShaper));
85 m
86 })
87}
88
89pub fn lookup(type_name: &str) -> Option<&'static dyn CfnResourceShaper> {
91 registry().get(type_name).map(|b| b.as_ref())
92}