wick_config/v1/conversions/triggers/
mod.rs1use option_utils::OptionUtils;
2
3use crate::error::ManifestError;
4use crate::utils::{VecMapInto, VecTryMapInto};
5use crate::{config, v1};
6
7type Result<T> = std::result::Result<T, ManifestError>;
8
9impl TryFrom<config::TriggerDefinition> for v1::TriggerDefinition {
10 type Error = ManifestError;
11 fn try_from(value: config::TriggerDefinition) -> Result<Self> {
12 Ok(match value {
13 config::TriggerDefinition::Http(v) => v1::TriggerDefinition::HttpTrigger(v.try_into()?),
14 config::TriggerDefinition::Cli(v) => v1::TriggerDefinition::CliTrigger(v.try_into()?),
15 config::TriggerDefinition::Time(v) => v1::TriggerDefinition::TimeTrigger(v.try_into()?),
16 config::TriggerDefinition::WasmCommand(v) => v1::TriggerDefinition::WasmCommandTrigger(v.try_into()?),
17 })
18 }
19}
20
21impl TryFrom<config::WasmCommandConfig> for v1::WasmCommandTrigger {
22 type Error = ManifestError;
23 fn try_from(value: config::WasmCommandConfig) -> Result<Self> {
24 Ok(Self {
25 reference: value.reference.try_into()?,
26 volumes: value.volumes.try_map_into()?,
27 })
28 }
29}
30
31impl TryFrom<config::TimeTriggerConfig> for v1::TimeTrigger {
32 type Error = ManifestError;
33 fn try_from(value: config::TimeTriggerConfig) -> Result<Self> {
34 let payload: Result<Vec<v1::OperationInput>> = value.payload.try_map_into();
35
36 Ok(Self {
37 schedule: value.schedule.try_into()?,
38 operation: value.operation.try_into()?,
39 payload: payload?,
40 })
41 }
42}
43
44impl TryFrom<config::ScheduleConfig> for v1::Schedule {
45 type Error = ManifestError;
46 fn try_from(value: config::ScheduleConfig) -> Result<Self> {
47 Ok(Self {
48 cron: value.cron,
49 repeat: value.repeat,
50 })
51 }
52}
53
54impl TryFrom<v1::Schedule> for config::ScheduleConfig {
55 type Error = ManifestError;
56 fn try_from(value: v1::Schedule) -> Result<Self> {
57 Ok(Self {
58 cron: value.cron,
59 repeat: value.repeat,
60 })
61 }
62}
63
64impl TryFrom<config::OperationInputConfig> for v1::OperationInput {
66 type Error = ManifestError;
67
68 fn try_from(value: config::OperationInputConfig) -> Result<Self> {
69 Ok(v1::OperationInput {
70 name: value.name,
71 value: value.value,
72 })
73 }
74}
75
76impl TryFrom<v1::OperationInput> for config::OperationInputConfig {
78 type Error = ManifestError;
79
80 fn try_from(value: v1::OperationInput) -> Result<Self> {
81 Ok(config::OperationInputConfig {
82 name: value.name,
83 value: value.value,
84 })
85 }
86}
87
88impl TryFrom<config::CliConfig> for v1::CliTrigger {
89 type Error = ManifestError;
90 fn try_from(value: config::CliConfig) -> Result<Self> {
91 Ok(Self {
92 operation: value.operation.try_into()?,
93 })
94 }
95}
96
97impl TryFrom<config::HttpTriggerConfig> for v1::HttpTrigger {
98 type Error = ManifestError;
99 fn try_from(value: config::HttpTriggerConfig) -> Result<Self> {
100 Ok(Self {
101 resource: value.resource.id().to_owned(),
102 routers: value.routers.into_iter().map(|v| v.try_into()).collect::<Result<_>>()?,
103 })
104 }
105}
106
107impl TryFrom<config::HttpRouterConfig> for v1::HttpRouter {
108 type Error = ManifestError;
109 fn try_from(value: config::HttpRouterConfig) -> Result<Self> {
110 Ok(match value {
111 config::HttpRouterConfig::RawRouter(v) => v1::HttpRouter::RawRouter(v.try_into()?),
112 config::HttpRouterConfig::RestRouter(v) => v1::HttpRouter::RestRouter(v.try_into()?),
113 config::HttpRouterConfig::StaticRouter(v) => v1::HttpRouter::StaticRouter(v.try_into()?),
114 config::HttpRouterConfig::ProxyRouter(v) => v1::HttpRouter::ProxyRouter(v.try_into()?),
115 })
116 }
117}
118
119impl TryFrom<config::ProxyRouterConfig> for v1::ProxyRouter {
120 type Error = ManifestError;
121 fn try_from(value: config::ProxyRouterConfig) -> Result<Self> {
122 Ok(Self {
123 path: value.path,
124 url: value.url.id().to_owned(),
125 strip_path: value.strip_path,
126 middleware: value.middleware.try_map_into()?,
127 })
128 }
129}
130
131impl TryFrom<config::StaticRouterConfig> for v1::StaticRouter {
132 type Error = ManifestError;
133 fn try_from(value: config::StaticRouterConfig) -> Result<Self> {
134 Ok(Self {
135 path: value.path,
136 volume: value.volume.id().to_owned(),
137 fallback: value.fallback,
138 middleware: value.middleware.try_map_into()?,
139 indexes: value.indexes,
140 })
141 }
142}
143
144impl TryFrom<config::RawRouterConfig> for v1::RawRouter {
145 type Error = ManifestError;
146 fn try_from(value: config::RawRouterConfig) -> Result<Self> {
147 Ok(Self {
148 path: value.path,
149 codec: value.codec.map_into(),
150 operation: value.operation.try_into()?,
151 middleware: value.middleware.try_map_into()?,
152 })
153 }
154}
155
156impl TryFrom<config::RestRouterConfig> for v1::RestRouter {
157 type Error = ManifestError;
158 fn try_from(value: config::RestRouterConfig) -> Result<Self> {
159 Ok(Self {
160 path: value.path,
161 tools: value.tools.try_map_into()?,
162 routes: value.routes.try_map_into()?,
163 middleware: value.middleware.try_map_into()?,
164 info: value.info.try_map_into()?,
165 })
166 }
167}
168
169impl TryFrom<config::Middleware> for v1::Middleware {
170 type Error = ManifestError;
171
172 fn try_from(value: config::Middleware) -> Result<Self> {
173 Ok(Self {
174 request: value.request.try_map_into()?,
175 response: value.response.try_map_into()?,
176 })
177 }
178}
179
180impl TryFrom<v1::Middleware> for config::Middleware {
181 type Error = ManifestError;
182
183 fn try_from(value: v1::Middleware) -> Result<Self> {
184 Ok(Self {
185 request: value.request.try_map_into()?,
186 response: value.response.try_map_into()?,
187 })
188 }
189}
190
191impl TryFrom<config::Tools> for v1::Tools {
192 type Error = ManifestError;
193
194 fn try_from(value: config::Tools) -> Result<Self> {
195 Ok(Self { openapi: value.openapi })
196 }
197}
198
199impl TryFrom<v1::Tools> for config::Tools {
200 type Error = ManifestError;
201
202 fn try_from(value: v1::Tools) -> Result<Self> {
203 Ok(Self { openapi: value.openapi })
204 }
205}
206
207impl TryFrom<v1::Route> for config::RestRoute {
208 type Error = ManifestError;
209
210 fn try_from(value: v1::Route) -> Result<Self> {
211 Ok(Self {
212 id: value.id,
213 methods: value.methods.map_into(),
214 sub_path: value.sub_path,
215 operation: value.operation.try_into()?,
216 description: value.description,
217 summary: value.summary,
218 })
219 }
220}
221
222impl TryFrom<config::RestRoute> for v1::Route {
223 type Error = ManifestError;
224
225 fn try_from(value: config::RestRoute) -> Result<Self> {
226 Ok(Self {
227 id: value.id,
228 methods: value.methods.map_into(),
229 sub_path: value.sub_path,
230 operation: value.operation.try_into()?,
231 description: value.description,
232 summary: value.summary,
233 })
234 }
235}
236
237impl TryFrom<v1::Info> for config::Info {
238 type Error = ManifestError;
239
240 fn try_from(value: v1::Info) -> Result<Self> {
241 Ok(Self {
242 title: value.title,
243 description: value.description,
244 tos: value.tos,
245 contact: value.contact.try_map_into()?,
246 license: value.license.try_map_into()?,
247 version: value.version,
248 documentation: value.documentation.try_map_into()?,
249 })
250 }
251}
252
253impl TryFrom<config::Info> for v1::Info {
254 type Error = ManifestError;
255
256 fn try_from(value: config::Info) -> Result<Self> {
257 Ok(Self {
258 title: value.title,
259 description: value.description,
260 tos: value.tos,
261 contact: value.contact.try_map_into()?,
262 license: value.license.try_map_into()?,
263 version: value.version,
264 documentation: value.documentation.try_map_into()?,
265 })
266 }
267}
268
269impl TryFrom<v1::Documentation> for config::Documentation {
270 type Error = ManifestError;
271
272 fn try_from(value: v1::Documentation) -> Result<Self> {
273 Ok(Self {
274 description: value.description,
275 url: value.url,
276 })
277 }
278}
279
280impl TryFrom<config::Documentation> for v1::Documentation {
281 type Error = ManifestError;
282
283 fn try_from(value: config::Documentation) -> Result<Self> {
284 Ok(Self {
285 description: value.description,
286 url: value.url,
287 })
288 }
289}
290
291impl TryFrom<v1::Contact> for config::Contact {
292 type Error = ManifestError;
293
294 fn try_from(value: v1::Contact) -> Result<Self> {
295 Ok(Self {
296 name: value.name,
297 url: value.url,
298 email: value.email,
299 })
300 }
301}
302
303impl TryFrom<config::Contact> for v1::Contact {
304 type Error = ManifestError;
305
306 fn try_from(value: config::Contact) -> Result<Self> {
307 Ok(Self {
308 name: value.name,
309 url: value.url,
310 email: value.email,
311 })
312 }
313}
314
315impl TryFrom<v1::License> for config::License {
316 type Error = ManifestError;
317
318 fn try_from(value: v1::License) -> Result<Self> {
319 Ok(Self {
320 name: value.name,
321 url: value.url,
322 })
323 }
324}
325
326impl TryFrom<config::License> for v1::License {
327 type Error = ManifestError;
328
329 fn try_from(value: config::License) -> Result<Self> {
330 Ok(Self {
331 name: value.name,
332 url: value.url,
333 })
334 }
335}