wasmcloud_control_interface/
broker.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const DEFAULT_TOPIC_PREFIX: &str = "wasmbus.ctl";
// Copied from https://docs.rs/wasmcloud-core/0.15.0/wasmcloud_core/constant.CTL_API_VERSION_1.html
// to avoid a dependency on a crate for one constant
const CTL_API_VERSION_1: &str = "v1";

fn prefix(topic_prefix: &Option<String>, lattice: &str, version: &str) -> String {
    format!(
        "{}.{version}.{lattice}",
        topic_prefix
            .as_ref()
            .unwrap_or(&DEFAULT_TOPIC_PREFIX.to_string())
    )
}

pub mod v1 {
    use crate::broker::CTL_API_VERSION_1;

    use super::prefix;

    pub fn provider_auction_subject(topic_prefix: &Option<String>, lattice: &str) -> String {
        format!(
            "{}.provider.auction",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn component_auction_subject(topic_prefix: &Option<String>, lattice: &str) -> String {
        format!(
            "{}.component.auction",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn put_link(topic_prefix: &Option<String>, lattice: &str) -> String {
        format!(
            "{}.link.put",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn delete_link(topic_prefix: &Option<String>, lattice: &str) -> String {
        format!(
            "{}.link.del",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn publish_registries(topic_prefix: &Option<String>, lattice: &str) -> String {
        format!(
            "{}.registry.put",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn put_config(topic_prefix: &Option<String>, lattice: &str, config_name: &str) -> String {
        format!(
            "{}.config.put.{config_name}",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn delete_config(
        topic_prefix: &Option<String>,
        lattice: &str,
        config_name: &str,
    ) -> String {
        format!(
            "{}.config.del.{config_name}",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn put_label(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
        format!(
            "{}.label.put.{host_id}",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub fn delete_label(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
        format!(
            "{}.label.del.{host_id}",
            prefix(topic_prefix, lattice, CTL_API_VERSION_1)
        )
    }

    pub mod commands {
        use crate::broker::CTL_API_VERSION_1;

        use super::prefix;

        pub fn scale_component(
            topic_prefix: &Option<String>,
            lattice: &str,
            host_id: &str,
        ) -> String {
            format!(
                "{}.component.scale.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn start_provider(
            topic_prefix: &Option<String>,
            lattice: &str,
            host_id: &str,
        ) -> String {
            format!(
                "{}.provider.start.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn stop_provider(
            topic_prefix: &Option<String>,
            lattice: &str,
            host_id: &str,
        ) -> String {
            format!(
                "{}.provider.stop.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn update_component(
            topic_prefix: &Option<String>,
            lattice: &str,
            host_id: &str,
        ) -> String {
            format!(
                "{}.component.update.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn stop_host(topic_prefix: &Option<String>, lattice: &str, host_id: &str) -> String {
            format!(
                "{}.host.stop.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }
    }

    pub mod queries {
        use crate::broker::CTL_API_VERSION_1;

        use super::prefix;

        pub fn link_definitions(topic_prefix: &Option<String>, lattice: &str) -> String {
            format!(
                "{}.link.get",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn claims(topic_prefix: &Option<String>, lattice: &str) -> String {
            format!(
                "{}.claims.get",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn host_inventory(
            topic_prefix: &Option<String>,
            lattice: &str,
            host_id: &str,
        ) -> String {
            format!(
                "{}.host.get.{host_id}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn hosts(topic_prefix: &Option<String>, lattice: &str) -> String {
            format!(
                "{}.host.ping",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1)
            )
        }

        pub fn config(topic_prefix: &Option<String>, lattice: &str, config_name: &str) -> String {
            format!(
                "{}.config.get.{config_name}",
                prefix(topic_prefix, lattice, CTL_API_VERSION_1),
            )
        }
    }
}