fastly_api/apis/
healthcheck_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_healthcheck`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateHealthcheckParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// How often to run the health check in milliseconds.
22    pub check_interval: Option<i32>,
23    /// A freeform descriptive note.
24    pub comment: Option<String>,
25    /// The status code expected from the host.
26    pub expected_response: Option<i32>,
27    /// Array of custom headers that will be added to the health check probes.
28    pub headers: Option<Vec<String>>,
29    /// Which host to check.
30    pub host: Option<String>,
31    /// Whether to use version 1.0 or 1.1 HTTP.
32    pub http_version: Option<String>,
33    /// When loading a config, the initial number of probes to be seen as OK.
34    pub initial: Option<i32>,
35    /// Which HTTP method to use.
36    pub method: Option<String>,
37    /// The name of the health check.
38    pub name: Option<String>,
39    /// The path to check.
40    pub path: Option<String>,
41    /// How many health checks must succeed to be considered healthy.
42    pub threshold: Option<i32>,
43    /// Timeout in milliseconds.
44    pub timeout: Option<i32>,
45    /// The number of most recent health check queries to keep for this health check.
46    pub window: Option<i32>
47}
48
49/// struct for passing parameters to the method [`delete_healthcheck`]
50#[derive(Clone, Debug, Default)]
51pub struct DeleteHealthcheckParams {
52    /// Alphanumeric string identifying the service.
53    pub service_id: String,
54    /// Integer identifying a service version.
55    pub version_id: i32,
56    /// The name of the health check.
57    pub healthcheck_name: String
58}
59
60/// struct for passing parameters to the method [`get_healthcheck`]
61#[derive(Clone, Debug, Default)]
62pub struct GetHealthcheckParams {
63    /// Alphanumeric string identifying the service.
64    pub service_id: String,
65    /// Integer identifying a service version.
66    pub version_id: i32,
67    /// The name of the health check.
68    pub healthcheck_name: String
69}
70
71/// struct for passing parameters to the method [`list_healthchecks`]
72#[derive(Clone, Debug, Default)]
73pub struct ListHealthchecksParams {
74    /// Alphanumeric string identifying the service.
75    pub service_id: String,
76    /// Integer identifying a service version.
77    pub version_id: i32
78}
79
80/// struct for passing parameters to the method [`update_healthcheck`]
81#[derive(Clone, Debug, Default)]
82pub struct UpdateHealthcheckParams {
83    /// Alphanumeric string identifying the service.
84    pub service_id: String,
85    /// Integer identifying a service version.
86    pub version_id: i32,
87    /// The name of the health check.
88    pub healthcheck_name: String,
89    /// How often to run the health check in milliseconds.
90    pub check_interval: Option<i32>,
91    /// A freeform descriptive note.
92    pub comment: Option<String>,
93    /// The status code expected from the host.
94    pub expected_response: Option<i32>,
95    /// Array of custom headers that will be added to the health check probes.
96    pub headers: Option<Vec<String>>,
97    /// Which host to check.
98    pub host: Option<String>,
99    /// Whether to use version 1.0 or 1.1 HTTP.
100    pub http_version: Option<String>,
101    /// When loading a config, the initial number of probes to be seen as OK.
102    pub initial: Option<i32>,
103    /// Which HTTP method to use.
104    pub method: Option<String>,
105    /// The name of the health check.
106    pub name: Option<String>,
107    /// The path to check.
108    pub path: Option<String>,
109    /// How many health checks must succeed to be considered healthy.
110    pub threshold: Option<i32>,
111    /// Timeout in milliseconds.
112    pub timeout: Option<i32>,
113    /// The number of most recent health check queries to keep for this health check.
114    pub window: Option<i32>
115}
116
117
118/// struct for typed errors of method [`create_healthcheck`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum CreateHealthcheckError {
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`delete_healthcheck`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum DeleteHealthcheckError {
129    UnknownValue(serde_json::Value),
130}
131
132/// struct for typed errors of method [`get_healthcheck`]
133#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(untagged)]
135pub enum GetHealthcheckError {
136    UnknownValue(serde_json::Value),
137}
138
139/// struct for typed errors of method [`list_healthchecks`]
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(untagged)]
142pub enum ListHealthchecksError {
143    UnknownValue(serde_json::Value),
144}
145
146/// struct for typed errors of method [`update_healthcheck`]
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(untagged)]
149pub enum UpdateHealthcheckError {
150    UnknownValue(serde_json::Value),
151}
152
153
154/// Create a health check for a particular service and version.
155pub async fn create_healthcheck(configuration: &mut configuration::Configuration, params: CreateHealthcheckParams) -> Result<crate::models::HealthcheckResponse, Error<CreateHealthcheckError>> {
156    let local_var_configuration = configuration;
157
158    // unbox the parameters
159    let service_id = params.service_id;
160    let version_id = params.version_id;
161    let check_interval = params.check_interval;
162    let comment = params.comment;
163    let expected_response = params.expected_response;
164    let headers = params.headers;
165    let host = params.host;
166    let http_version = params.http_version;
167    let initial = params.initial;
168    let method = params.method;
169    let name = params.name;
170    let path = params.path;
171    let threshold = params.threshold;
172    let timeout = params.timeout;
173    let window = params.window;
174
175
176    let local_var_client = &local_var_configuration.client;
177
178    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/healthcheck", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
179    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
180
181    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
182        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
183    }
184    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
185        let local_var_key = local_var_apikey.key.clone();
186        let local_var_value = match local_var_apikey.prefix {
187            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
188            None => local_var_key,
189        };
190        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
191    };
192    let mut local_var_form_params = std::collections::HashMap::new();
193    if let Some(local_var_param_value) = check_interval {
194        local_var_form_params.insert("check_interval", local_var_param_value.to_string());
195    }
196    if let Some(local_var_param_value) = comment {
197        local_var_form_params.insert("comment", local_var_param_value.to_string());
198    }
199    if let Some(local_var_param_value) = expected_response {
200        local_var_form_params.insert("expected_response", local_var_param_value.to_string());
201    }
202    if let Some(local_var_param_value) = headers {
203        local_var_form_params.insert("headers[]", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
204    }
205    if let Some(local_var_param_value) = host {
206        local_var_form_params.insert("host", local_var_param_value.to_string());
207    }
208    if let Some(local_var_param_value) = http_version {
209        local_var_form_params.insert("http_version", local_var_param_value.to_string());
210    }
211    if let Some(local_var_param_value) = initial {
212        local_var_form_params.insert("initial", local_var_param_value.to_string());
213    }
214    if let Some(local_var_param_value) = method {
215        local_var_form_params.insert("method", local_var_param_value.to_string());
216    }
217    if let Some(local_var_param_value) = name {
218        local_var_form_params.insert("name", local_var_param_value.to_string());
219    }
220    if let Some(local_var_param_value) = path {
221        local_var_form_params.insert("path", local_var_param_value.to_string());
222    }
223    if let Some(local_var_param_value) = threshold {
224        local_var_form_params.insert("threshold", local_var_param_value.to_string());
225    }
226    if let Some(local_var_param_value) = timeout {
227        local_var_form_params.insert("timeout", local_var_param_value.to_string());
228    }
229    if let Some(local_var_param_value) = window {
230        local_var_form_params.insert("window", local_var_param_value.to_string());
231    }
232    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
233
234    let local_var_req = local_var_req_builder.build()?;
235    let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237    if "POST" != "GET" && "POST" != "HEAD" {
238      let headers = local_var_resp.headers();
239      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
240          Some(v) => v.to_str().unwrap().parse().unwrap(),
241          None => configuration::DEFAULT_RATELIMIT,
242      };
243      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
244          Some(v) => v.to_str().unwrap().parse().unwrap(),
245          None => 0,
246      };
247    }
248
249    let local_var_status = local_var_resp.status();
250    let local_var_content = local_var_resp.text().await?;
251
252    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
253        serde_json::from_str(&local_var_content).map_err(Error::from)
254    } else {
255        let local_var_entity: Option<CreateHealthcheckError> = serde_json::from_str(&local_var_content).ok();
256        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
257        Err(Error::ResponseError(local_var_error))
258    }
259}
260
261/// Delete the health check for a particular service and version.
262pub async fn delete_healthcheck(configuration: &mut configuration::Configuration, params: DeleteHealthcheckParams) -> Result<crate::models::InlineResponse200, Error<DeleteHealthcheckError>> {
263    let local_var_configuration = configuration;
264
265    // unbox the parameters
266    let service_id = params.service_id;
267    let version_id = params.version_id;
268    let healthcheck_name = params.healthcheck_name;
269
270
271    let local_var_client = &local_var_configuration.client;
272
273    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/healthcheck/{healthcheck_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, healthcheck_name=crate::apis::urlencode(healthcheck_name));
274    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
275
276    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
277        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278    }
279    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
280        let local_var_key = local_var_apikey.key.clone();
281        let local_var_value = match local_var_apikey.prefix {
282            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
283            None => local_var_key,
284        };
285        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
286    };
287
288    let local_var_req = local_var_req_builder.build()?;
289    let local_var_resp = local_var_client.execute(local_var_req).await?;
290
291    if "DELETE" != "GET" && "DELETE" != "HEAD" {
292      let headers = local_var_resp.headers();
293      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
294          Some(v) => v.to_str().unwrap().parse().unwrap(),
295          None => configuration::DEFAULT_RATELIMIT,
296      };
297      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
298          Some(v) => v.to_str().unwrap().parse().unwrap(),
299          None => 0,
300      };
301    }
302
303    let local_var_status = local_var_resp.status();
304    let local_var_content = local_var_resp.text().await?;
305
306    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
307        serde_json::from_str(&local_var_content).map_err(Error::from)
308    } else {
309        let local_var_entity: Option<DeleteHealthcheckError> = serde_json::from_str(&local_var_content).ok();
310        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
311        Err(Error::ResponseError(local_var_error))
312    }
313}
314
315/// Get the health check for a particular service and version.
316pub async fn get_healthcheck(configuration: &mut configuration::Configuration, params: GetHealthcheckParams) -> Result<crate::models::HealthcheckResponse, Error<GetHealthcheckError>> {
317    let local_var_configuration = configuration;
318
319    // unbox the parameters
320    let service_id = params.service_id;
321    let version_id = params.version_id;
322    let healthcheck_name = params.healthcheck_name;
323
324
325    let local_var_client = &local_var_configuration.client;
326
327    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/healthcheck/{healthcheck_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, healthcheck_name=crate::apis::urlencode(healthcheck_name));
328    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
329
330    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
331        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
332    }
333    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
334        let local_var_key = local_var_apikey.key.clone();
335        let local_var_value = match local_var_apikey.prefix {
336            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
337            None => local_var_key,
338        };
339        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
340    };
341
342    let local_var_req = local_var_req_builder.build()?;
343    let local_var_resp = local_var_client.execute(local_var_req).await?;
344
345    if "GET" != "GET" && "GET" != "HEAD" {
346      let headers = local_var_resp.headers();
347      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
348          Some(v) => v.to_str().unwrap().parse().unwrap(),
349          None => configuration::DEFAULT_RATELIMIT,
350      };
351      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
352          Some(v) => v.to_str().unwrap().parse().unwrap(),
353          None => 0,
354      };
355    }
356
357    let local_var_status = local_var_resp.status();
358    let local_var_content = local_var_resp.text().await?;
359
360    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
361        serde_json::from_str(&local_var_content).map_err(Error::from)
362    } else {
363        let local_var_entity: Option<GetHealthcheckError> = serde_json::from_str(&local_var_content).ok();
364        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
365        Err(Error::ResponseError(local_var_error))
366    }
367}
368
369/// List all of the health checks for a particular service and version.
370pub async fn list_healthchecks(configuration: &mut configuration::Configuration, params: ListHealthchecksParams) -> Result<Vec<crate::models::HealthcheckResponse>, Error<ListHealthchecksError>> {
371    let local_var_configuration = configuration;
372
373    // unbox the parameters
374    let service_id = params.service_id;
375    let version_id = params.version_id;
376
377
378    let local_var_client = &local_var_configuration.client;
379
380    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/healthcheck", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
381    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
382
383    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
384        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
385    }
386    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
387        let local_var_key = local_var_apikey.key.clone();
388        let local_var_value = match local_var_apikey.prefix {
389            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
390            None => local_var_key,
391        };
392        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
393    };
394
395    let local_var_req = local_var_req_builder.build()?;
396    let local_var_resp = local_var_client.execute(local_var_req).await?;
397
398    if "GET" != "GET" && "GET" != "HEAD" {
399      let headers = local_var_resp.headers();
400      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
401          Some(v) => v.to_str().unwrap().parse().unwrap(),
402          None => configuration::DEFAULT_RATELIMIT,
403      };
404      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
405          Some(v) => v.to_str().unwrap().parse().unwrap(),
406          None => 0,
407      };
408    }
409
410    let local_var_status = local_var_resp.status();
411    let local_var_content = local_var_resp.text().await?;
412
413    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
414        serde_json::from_str(&local_var_content).map_err(Error::from)
415    } else {
416        let local_var_entity: Option<ListHealthchecksError> = serde_json::from_str(&local_var_content).ok();
417        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
418        Err(Error::ResponseError(local_var_error))
419    }
420}
421
422/// Update the health check for a particular service and version.
423pub async fn update_healthcheck(configuration: &mut configuration::Configuration, params: UpdateHealthcheckParams) -> Result<crate::models::HealthcheckResponse, Error<UpdateHealthcheckError>> {
424    let local_var_configuration = configuration;
425
426    // unbox the parameters
427    let service_id = params.service_id;
428    let version_id = params.version_id;
429    let healthcheck_name = params.healthcheck_name;
430    let check_interval = params.check_interval;
431    let comment = params.comment;
432    let expected_response = params.expected_response;
433    let headers = params.headers;
434    let host = params.host;
435    let http_version = params.http_version;
436    let initial = params.initial;
437    let method = params.method;
438    let name = params.name;
439    let path = params.path;
440    let threshold = params.threshold;
441    let timeout = params.timeout;
442    let window = params.window;
443
444
445    let local_var_client = &local_var_configuration.client;
446
447    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/healthcheck/{healthcheck_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, healthcheck_name=crate::apis::urlencode(healthcheck_name));
448    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
449
450    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
451        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
452    }
453    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
454        let local_var_key = local_var_apikey.key.clone();
455        let local_var_value = match local_var_apikey.prefix {
456            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
457            None => local_var_key,
458        };
459        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
460    };
461    let mut local_var_form_params = std::collections::HashMap::new();
462    if let Some(local_var_param_value) = check_interval {
463        local_var_form_params.insert("check_interval", local_var_param_value.to_string());
464    }
465    if let Some(local_var_param_value) = comment {
466        local_var_form_params.insert("comment", local_var_param_value.to_string());
467    }
468    if let Some(local_var_param_value) = expected_response {
469        local_var_form_params.insert("expected_response", local_var_param_value.to_string());
470    }
471    if let Some(local_var_param_value) = headers {
472        local_var_form_params.insert("headers[]", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
473    }
474    if let Some(local_var_param_value) = host {
475        local_var_form_params.insert("host", local_var_param_value.to_string());
476    }
477    if let Some(local_var_param_value) = http_version {
478        local_var_form_params.insert("http_version", local_var_param_value.to_string());
479    }
480    if let Some(local_var_param_value) = initial {
481        local_var_form_params.insert("initial", local_var_param_value.to_string());
482    }
483    if let Some(local_var_param_value) = method {
484        local_var_form_params.insert("method", local_var_param_value.to_string());
485    }
486    if let Some(local_var_param_value) = name {
487        local_var_form_params.insert("name", local_var_param_value.to_string());
488    }
489    if let Some(local_var_param_value) = path {
490        local_var_form_params.insert("path", local_var_param_value.to_string());
491    }
492    if let Some(local_var_param_value) = threshold {
493        local_var_form_params.insert("threshold", local_var_param_value.to_string());
494    }
495    if let Some(local_var_param_value) = timeout {
496        local_var_form_params.insert("timeout", local_var_param_value.to_string());
497    }
498    if let Some(local_var_param_value) = window {
499        local_var_form_params.insert("window", local_var_param_value.to_string());
500    }
501    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
502
503    let local_var_req = local_var_req_builder.build()?;
504    let local_var_resp = local_var_client.execute(local_var_req).await?;
505
506    if "PUT" != "GET" && "PUT" != "HEAD" {
507      let headers = local_var_resp.headers();
508      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
509          Some(v) => v.to_str().unwrap().parse().unwrap(),
510          None => configuration::DEFAULT_RATELIMIT,
511      };
512      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
513          Some(v) => v.to_str().unwrap().parse().unwrap(),
514          None => 0,
515      };
516    }
517
518    let local_var_status = local_var_resp.status();
519    let local_var_content = local_var_resp.text().await?;
520
521    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
522        serde_json::from_str(&local_var_content).map_err(Error::from)
523    } else {
524        let local_var_entity: Option<UpdateHealthcheckError> = serde_json::from_str(&local_var_content).ok();
525        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
526        Err(Error::ResponseError(local_var_error))
527    }
528}
529