wasmcloud_control_interface/
broker.rs

1const DEFAULT_TOPIC_PREFIX: &str = "wasmbus.ctl";
2// Copied from https://docs.rs/wasmcloud-core/0.15.0/wasmcloud_core/constant.CTL_API_VERSION_1.html
3// to avoid a dependency on a crate for one constant
4const CTL_API_VERSION_1: &str = "v1";
5
6fn prefix(topic_prefix: &Option<String>, lattice: &str, version: &str) -> String {
7    format!(
8        "{}.{version}.{lattice}",
9        topic_prefix
10            .as_ref()
11            .unwrap_or(&DEFAULT_TOPIC_PREFIX.to_string())
12    )
13}
14
15pub mod v1 {
16    use crate::broker::CTL_API_VERSION_1;
17
18    use super::prefix;
19
20    pub fn provider_auction_subject(topic_prefix: &Option<String>, lattice: &str) -> String {
21        format!(
22            "{}.provider.auction",
23            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
24        )
25    }
26
27    pub fn component_auction_subject(topic_prefix: &Option<String>, lattice: &str) -> String {
28        format!(
29            "{}.component.auction",
30            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
31        )
32    }
33
34    pub fn put_link(topic_prefix: &Option<String>, lattice: &str) -> String {
35        format!(
36            "{}.link.put",
37            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
38        )
39    }
40
41    pub fn delete_link(topic_prefix: &Option<String>, lattice: &str) -> String {
42        format!(
43            "{}.link.del",
44            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
45        )
46    }
47
48    pub fn publish_registries(topic_prefix: &Option<String>, lattice: &str) -> String {
49        format!(
50            "{}.registry.put",
51            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
52        )
53    }
54
55    pub fn put_config(topic_prefix: &Option<String>, lattice: &str, config_name: &str) -> String {
56        format!(
57            "{}.config.put.{config_name}",
58            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
59        )
60    }
61
62    pub fn delete_config(
63        topic_prefix: &Option<String>,
64        lattice: &str,
65        config_name: &str,
66    ) -> String {
67        format!(
68            "{}.config.del.{config_name}",
69            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
70        )
71    }
72
73    pub fn put_label(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
74        format!(
75            "{}.label.put.{host_id}",
76            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
77        )
78    }
79
80    pub fn delete_label(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
81        format!(
82            "{}.label.del.{host_id}",
83            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
84        )
85    }
86
87    pub mod commands {
88        use crate::broker::CTL_API_VERSION_1;
89
90        use super::prefix;
91
92        pub fn scale_component(
93            topic_prefix: &Option<String>,
94            lattice: &str,
95            host_id: &str,
96        ) -> String {
97            format!(
98                "{}.component.scale.{host_id}",
99                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
100            )
101        }
102
103        pub fn start_provider(
104            topic_prefix: &Option<String>,
105            lattice: &str,
106            host_id: &str,
107        ) -> String {
108            format!(
109                "{}.provider.start.{host_id}",
110                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
111            )
112        }
113
114        pub fn stop_provider(
115            topic_prefix: &Option<String>,
116            lattice: &str,
117            host_id: &str,
118        ) -> String {
119            format!(
120                "{}.provider.stop.{host_id}",
121                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
122            )
123        }
124
125        pub fn update_component(
126            topic_prefix: &Option<String>,
127            lattice: &str,
128            host_id: &str,
129        ) -> String {
130            format!(
131                "{}.component.update.{host_id}",
132                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
133            )
134        }
135
136        pub fn stop_host(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
137            format!(
138                "{}.host.stop.{host_id}",
139                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
140            )
141        }
142    }
143
144    pub mod queries {
145        use crate::broker::CTL_API_VERSION_1;
146
147        use super::prefix;
148
149        pub fn link_definitions(topic_prefix: &Option<String>, lattice: &str) -> String {
150            format!(
151                "{}.link.get",
152                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
153            )
154        }
155
156        pub fn claims(topic_prefix: &Option<String>, lattice: &str) -> String {
157            format!(
158                "{}.claims.get",
159                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
160            )
161        }
162
163        pub fn host_inventory(
164            topic_prefix: &Option<String>,
165            lattice: &str,
166            host_id: &str,
167        ) -> String {
168            format!(
169                "{}.host.get.{host_id}",
170                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
171            )
172        }
173
174        pub fn hosts(topic_prefix: &Option<String>, lattice: &str) -> String {
175            format!(
176                "{}.host.ping",
177                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
178            )
179        }
180
181        pub fn config(topic_prefix: &Option<String>, lattice: &str, config_name: &str) -> String {
182            format!(
183                "{}.config.get.{config_name}",
184                prefix(topic_prefix, lattice, CTL_API_VERSION_1),
185            )
186        }
187    }
188}