flakery_client/
lib.rs

1#[allow(unused_imports)]
2use progenitor_client::{encode_path, RequestBuilderExt};
3#[allow(unused_imports)]
4pub use progenitor_client::{ByteStream, Error, ResponseValue};
5#[allow(unused_imports)]
6use reqwest::header::{HeaderMap, HeaderValue};
7/// Types used as operation parameters and responses.
8#[allow(clippy::all)]
9pub mod types {
10    use serde::{Deserialize, Serialize};
11    #[allow(unused_imports)]
12    use std::convert::TryFrom;
13    /// Error types.
14    pub mod error {
15        /// Error from a TryFrom or FromStr implementation.
16        pub struct ConversionError(std::borrow::Cow<'static, str>);
17        impl std::error::Error for ConversionError {}
18        impl std::fmt::Display for ConversionError {
19            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
20                std::fmt::Display::fmt(&self.0, f)
21            }
22        }
23
24        impl std::fmt::Debug for ConversionError {
25            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
26                std::fmt::Debug::fmt(&self.0, f)
27            }
28        }
29
30        impl From<&'static str> for ConversionError {
31            fn from(value: &'static str) -> Self {
32                Self(value.into())
33            }
34        }
35
36        impl From<String> for ConversionError {
37            fn from(value: String) -> Self {
38                Self(value.into())
39            }
40        }
41    }
42
43    ///CreateListenerInput
44    ///
45    /// <details><summary>JSON schema</summary>
46    ///
47    /// ```json
48    ///{
49    ///  "type": "object",
50    ///  "required": [
51    ///    "deployment_id",
52    ///    "mappings"
53    ///  ],
54    ///  "properties": {
55    ///    "deployment_id": {
56    ///      "type": "string"
57    ///    },
58    ///    "mappings": {
59    ///      "type": "array",
60    ///      "items": {
61    ///        "$ref": "#/components/schemas/Mapping"
62    ///      }
63    ///    }
64    ///  }
65    ///}
66    /// ```
67    /// </details>
68    #[derive(Clone, Debug, Deserialize, Serialize)]
69    pub struct CreateListenerInput {
70        pub deployment_id: String,
71        pub mappings: Vec<Mapping>,
72    }
73
74    impl From<&CreateListenerInput> for CreateListenerInput {
75        fn from(value: &CreateListenerInput) -> Self {
76            value.clone()
77        }
78    }
79
80    ///CreateListenerOutput
81    ///
82    /// <details><summary>JSON schema</summary>
83    ///
84    /// ```json
85    ///{
86    ///  "type": "object"
87    ///}
88    /// ```
89    /// </details>
90    #[derive(Clone, Debug, Deserialize, Serialize)]
91    pub struct CreateListenerOutput(pub serde_json::Map<String, serde_json::Value>);
92    impl std::ops::Deref for CreateListenerOutput {
93        type Target = serde_json::Map<String, serde_json::Value>;
94        fn deref(&self) -> &serde_json::Map<String, serde_json::Value> {
95            &self.0
96        }
97    }
98
99    impl From<CreateListenerOutput> for serde_json::Map<String, serde_json::Value> {
100        fn from(value: CreateListenerOutput) -> Self {
101            value.0
102        }
103    }
104
105    impl From<&CreateListenerOutput> for CreateListenerOutput {
106        fn from(value: &CreateListenerOutput) -> Self {
107            value.clone()
108        }
109    }
110
111    impl From<serde_json::Map<String, serde_json::Value>> for CreateListenerOutput {
112        fn from(value: serde_json::Map<String, serde_json::Value>) -> Self {
113            Self(value)
114        }
115    }
116
117    ///DeployAwsInput
118    ///
119    /// <details><summary>JSON schema</summary>
120    ///
121    /// ```json
122    ///{
123    ///  "type": "object",
124    ///  "required": [
125    ///    "deployment_slug",
126    ///    "flake_url",
127    ///    "instance_type",
128    ///    "subdomain_prefix",
129    ///    "template_id"
130    ///  ],
131    ///  "properties": {
132    ///    "deployment_slug": {
133    ///      "type": "string"
134    ///    },
135    ///    "files": {
136    ///      "type": [
137    ///        "array",
138    ///        "null"
139    ///      ],
140    ///      "items": {
141    ///        "$ref": "#/components/schemas/File"
142    ///      }
143    ///    },
144    ///    "flake_url": {
145    ///      "type": "string"
146    ///    },
147    ///    "instance_type": {
148    ///      "type": "string"
149    ///    },
150    ///    "max_size": {
151    ///      "type": [
152    ///        "integer",
153    ///        "null"
154    ///      ],
155    ///      "format": "int64"
156    ///    },
157    ///    "min_size": {
158    ///      "type": [
159    ///        "integer",
160    ///        "null"
161    ///      ],
162    ///      "format": "int64"
163    ///    },
164    ///    "subdomain_prefix": {
165    ///      "type": "string"
166    ///    },
167    ///    "targets": {
168    ///      "type": [
169    ///        "array",
170    ///        "null"
171    ///      ],
172    ///      "items": {
173    ///        "$ref": "#/components/schemas/Target"
174    ///      }
175    ///    },
176    ///    "template_id": {
177    ///      "type": "string"
178    ///    }
179    ///  }
180    ///}
181    /// ```
182    /// </details>
183    #[derive(Clone, Debug, Deserialize, Serialize)]
184    pub struct DeployAwsInput {
185        pub deployment_slug: String,
186        #[serde(default, skip_serializing_if = "Option::is_none")]
187        pub files: Option<Vec<File>>,
188        pub flake_url: String,
189        pub instance_type: String,
190        #[serde(default, skip_serializing_if = "Option::is_none")]
191        pub max_size: Option<i64>,
192        #[serde(default, skip_serializing_if = "Option::is_none")]
193        pub min_size: Option<i64>,
194        pub subdomain_prefix: String,
195        #[serde(default, skip_serializing_if = "Option::is_none")]
196        pub targets: Option<Vec<Target>>,
197        pub template_id: String,
198    }
199
200    impl From<&DeployAwsInput> for DeployAwsInput {
201        fn from(value: &DeployAwsInput) -> Self {
202            value.clone()
203        }
204    }
205
206    ///DeployAwsOutput
207    ///
208    /// <details><summary>JSON schema</summary>
209    ///
210    /// ```json
211    ///{
212    ///  "type": "object",
213    ///  "required": [
214    ///    "id",
215    ///    "input"
216    ///  ],
217    ///  "properties": {
218    ///    "id": {
219    ///      "type": "string"
220    ///    },
221    ///    "input": {
222    ///      "$ref": "#/components/schemas/DeployAWSInput"
223    ///    },
224    ///    "lb_arn": {
225    ///      "type": [
226    ///        "string",
227    ///        "null"
228    ///      ]
229    ///    }
230    ///  }
231    ///}
232    /// ```
233    /// </details>
234    #[derive(Clone, Debug, Deserialize, Serialize)]
235    pub struct DeployAwsOutput {
236        pub id: String,
237        pub input: DeployAwsInput,
238        #[serde(default, skip_serializing_if = "Option::is_none")]
239        pub lb_arn: Option<String>,
240    }
241
242    impl From<&DeployAwsOutput> for DeployAwsOutput {
243        fn from(value: &DeployAwsOutput) -> Self {
244            value.clone()
245        }
246    }
247
248    ///File
249    ///
250    /// <details><summary>JSON schema</summary>
251    ///
252    /// ```json
253    ///{
254    ///  "type": "object",
255    ///  "required": [
256    ///    "content",
257    ///    "path"
258    ///  ],
259    ///  "properties": {
260    ///    "content": {
261    ///      "type": "string"
262    ///    },
263    ///    "path": {
264    ///      "type": "string"
265    ///    }
266    ///  }
267    ///}
268    /// ```
269    /// </details>
270    #[derive(Clone, Debug, Deserialize, Serialize)]
271    pub struct File {
272        pub content: String,
273        pub path: String,
274    }
275
276    impl From<&File> for File {
277        fn from(value: &File) -> Self {
278            value.clone()
279        }
280    }
281
282    ///LogInput
283    ///
284    /// <details><summary>JSON schema</summary>
285    ///
286    /// ```json
287    ///{
288    ///  "type": "object",
289    ///  "required": [
290    ///    "log"
291    ///  ],
292    ///  "properties": {
293    ///    "log": {
294    ///      "type": "string"
295    ///    }
296    ///  }
297    ///}
298    /// ```
299    /// </details>
300    #[derive(Clone, Debug, Deserialize, Serialize)]
301    pub struct LogInput {
302        pub log: String,
303    }
304
305    impl From<&LogInput> for LogInput {
306        fn from(value: &LogInput) -> Self {
307            value.clone()
308        }
309    }
310
311    ///LogOutput
312    ///
313    /// <details><summary>JSON schema</summary>
314    ///
315    /// ```json
316    ///{
317    ///  "type": "object"
318    ///}
319    /// ```
320    /// </details>
321    #[derive(Clone, Debug, Deserialize, Serialize)]
322    pub struct LogOutput(pub serde_json::Map<String, serde_json::Value>);
323    impl std::ops::Deref for LogOutput {
324        type Target = serde_json::Map<String, serde_json::Value>;
325        fn deref(&self) -> &serde_json::Map<String, serde_json::Value> {
326            &self.0
327        }
328    }
329
330    impl From<LogOutput> for serde_json::Map<String, serde_json::Value> {
331        fn from(value: LogOutput) -> Self {
332            value.0
333        }
334    }
335
336    impl From<&LogOutput> for LogOutput {
337        fn from(value: &LogOutput) -> Self {
338            value.clone()
339        }
340    }
341
342    impl From<serde_json::Map<String, serde_json::Value>> for LogOutput {
343        fn from(value: serde_json::Map<String, serde_json::Value>) -> Self {
344            Self(value)
345        }
346    }
347
348    ///Mapping
349    ///
350    /// <details><summary>JSON schema</summary>
351    ///
352    /// ```json
353    ///{
354    ///  "type": "object",
355    ///  "required": [
356    ///    "listener_port",
357    ///    "target_port"
358    ///  ],
359    ///  "properties": {
360    ///    "listener_port": {
361    ///      "type": "integer",
362    ///      "format": "int64"
363    ///    },
364    ///    "target_port": {
365    ///      "type": "integer",
366    ///      "format": "int64"
367    ///    }
368    ///  }
369    ///}
370    /// ```
371    /// </details>
372    #[derive(Clone, Debug, Deserialize, Serialize)]
373    pub struct Mapping {
374        pub listener_port: i64,
375        pub target_port: i64,
376    }
377
378    impl From<&Mapping> for Mapping {
379        fn from(value: &Mapping) -> Self {
380            value.clone()
381        }
382    }
383
384    ///Target
385    ///
386    /// <details><summary>JSON schema</summary>
387    ///
388    /// ```json
389    ///{
390    ///  "type": "object",
391    ///  "required": [
392    ///    "port"
393    ///  ],
394    ///  "properties": {
395    ///    "health_check_enabled": {
396    ///      "type": [
397    ///        "boolean",
398    ///        "null"
399    ///      ]
400    ///    },
401    ///    "health_check_path": {
402    ///      "type": [
403    ///        "string",
404    ///        "null"
405    ///      ]
406    ///    },
407    ///    "port": {
408    ///      "type": "integer",
409    ///      "format": "int64"
410    ///    }
411    ///  }
412    ///}
413    /// ```
414    /// </details>
415    #[derive(Clone, Debug, Deserialize, Serialize)]
416    pub struct Target {
417        #[serde(default, skip_serializing_if = "Option::is_none")]
418        pub health_check_enabled: Option<bool>,
419        #[serde(default, skip_serializing_if = "Option::is_none")]
420        pub health_check_path: Option<String>,
421        pub port: i64,
422    }
423
424    impl From<&Target> for Target {
425        fn from(value: &Target) -> Self {
426            value.clone()
427        }
428    }
429}
430
431#[derive(Clone, Debug)]
432///Client for webserver
433///
434///Version: 0.1.0
435pub struct Client {
436    pub(crate) baseurl: String,
437    pub(crate) client: reqwest::Client,
438}
439
440impl Client {
441    /// Create a new client.
442    ///
443    /// `baseurl` is the base URL provided to the internal
444    /// `reqwest::Client`, and should include a scheme and hostname,
445    /// as well as port and a path stem if applicable.
446    pub fn new(baseurl: &str) -> Self {
447        #[cfg(not(target_arch = "wasm32"))]
448        let client = {
449            let dur = std::time::Duration::from_secs(15);
450            reqwest::ClientBuilder::new()
451                .connect_timeout(dur)
452                .timeout(dur)
453        };
454        #[cfg(target_arch = "wasm32")]
455        let client = reqwest::ClientBuilder::new();
456        Self::new_with_client(baseurl, client.build().unwrap())
457    }
458
459    /// Construct a new client with an existing `reqwest::Client`,
460    /// allowing more control over its configuration.
461    ///
462    /// `baseurl` is the base URL provided to the internal
463    /// `reqwest::Client`, and should include a scheme and hostname,
464    /// as well as port and a path stem if applicable.
465    pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
466        Self {
467            baseurl: baseurl.to_string(),
468            client,
469        }
470    }
471
472    /// Get the base URL to which requests are made.
473    pub fn baseurl(&self) -> &String {
474        &self.baseurl
475    }
476
477    /// Get the internal `reqwest::Client` used to make requests.
478    pub fn client(&self) -> &reqwest::Client {
479        &self.client
480    }
481
482    /// Get the version of this API.
483    ///
484    /// This string is pulled directly from the source OpenAPI
485    /// document and may be in any format the API selects.
486    pub fn api_version(&self) -> &'static str {
487        "0.1.0"
488    }
489}
490
491#[allow(clippy::all)]
492impl Client {
493    ///Get instance ID from queue
494    ///
495    ///Retrieves the next available EC2 instance ID from the queue.
496    ///
497    ///Sends a `POST` request to `/deploy/aws/create`
498    pub async fn handlers_deploy_deploy_aws_create<'a>(
499        &'a self,
500        body: &'a types::DeployAwsInput,
501    ) -> Result<ResponseValue<types::DeployAwsOutput>, Error<()>> {
502        let url = format!("{}/deploy/aws/create", self.baseurl,);
503        #[allow(unused_mut)]
504        let mut request = self
505            .client
506            .post(url)
507            .header(
508                reqwest::header::ACCEPT,
509                reqwest::header::HeaderValue::from_static("application/json"),
510            )
511            .json(&body)
512            .build()?;
513        let result = self.client.execute(request).await;
514        let response = result?;
515        match response.status().as_u16() {
516            200u16 => ResponseValue::from_response(response).await,
517            400u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
518            404u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
519            422u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
520            500u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
521            _ => Err(Error::UnexpectedResponse(response)),
522        }
523    }
524
525    ///Get instance ID from queue
526    ///
527    ///Retrieves the next available EC2 instance ID from the queue.
528    ///
529    ///Sends a `POST` request to `/log`
530    pub async fn handlers_log_log<'a>(
531        &'a self,
532        body: &'a types::LogInput,
533    ) -> Result<ResponseValue<types::LogOutput>, Error<()>> {
534        let url = format!("{}/log", self.baseurl,);
535        #[allow(unused_mut)]
536        let mut request = self
537            .client
538            .post(url)
539            .header(
540                reqwest::header::ACCEPT,
541                reqwest::header::HeaderValue::from_static("application/json"),
542            )
543            .json(&body)
544            .build()?;
545        let result = self.client.execute(request).await;
546        let response = result?;
547        match response.status().as_u16() {
548            200u16 => ResponseValue::from_response(response).await,
549            400u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
550            404u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
551            422u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
552            500u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
553            _ => Err(Error::UnexpectedResponse(response)),
554        }
555    }
556
557    ///Sends a `POST` request to `/create-listener`
558    pub async fn handlers_create_listener_create_listener<'a>(
559        &'a self,
560        body: &'a types::CreateListenerInput,
561    ) -> Result<ResponseValue<types::CreateListenerOutput>, Error<()>> {
562        let url = format!("{}/create-listener", self.baseurl,);
563        #[allow(unused_mut)]
564        let mut request = self
565            .client
566            .post(url)
567            .header(
568                reqwest::header::ACCEPT,
569                reqwest::header::HeaderValue::from_static("application/json"),
570            )
571            .json(&body)
572            .build()?;
573        let result = self.client.execute(request).await;
574        let response = result?;
575        match response.status().as_u16() {
576            200u16 => ResponseValue::from_response(response).await,
577            400u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
578            404u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
579            422u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
580            500u16 => Err(Error::ErrorResponse(ResponseValue::empty(response))),
581            _ => Err(Error::UnexpectedResponse(response)),
582        }
583    }
584}
585
586/// Items consumers will typically use such as the Client.
587pub mod prelude {
588    #[allow(unused_imports)]
589    pub use super::Client;
590}