fastly_api/apis/
server_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_pool_server`]
15#[derive(Clone, Debug, Default)]
16pub struct CreatePoolServerParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Alphanumeric string identifying a Pool.
20    pub pool_id: String,
21    /// Weight (`1-100`) used to load balance this server against others.
22    pub weight: Option<i32>,
23    /// Maximum number of connections. If the value is `0`, it inherits the value from pool's `max_conn_default`.
24    pub max_conn: Option<i32>,
25    /// Port number. Setting port `443` does not force TLS. Set `use_tls` in pool to force TLS.
26    pub port: Option<i32>,
27    /// A hostname, IPv4, or IPv6 address for the server. Required.
28    pub address: Option<String>,
29    /// A freeform descriptive note.
30    pub comment: Option<String>,
31    /// Allows servers to be enabled and disabled in a pool.
32    pub disabled: Option<bool>,
33    /// The hostname to override the Host header. Defaults to `null` meaning no override of the Host header if not set. This setting can also be added to a Pool definition. However, the server setting will override the Pool setting.
34    pub override_host: Option<String>
35}
36
37/// struct for passing parameters to the method [`delete_pool_server`]
38#[derive(Clone, Debug, Default)]
39pub struct DeletePoolServerParams {
40    /// Alphanumeric string identifying the service.
41    pub service_id: String,
42    /// Alphanumeric string identifying a Pool.
43    pub pool_id: String,
44    /// Alphanumeric string identifying a Server.
45    pub server_id: String
46}
47
48/// struct for passing parameters to the method [`get_pool_server`]
49#[derive(Clone, Debug, Default)]
50pub struct GetPoolServerParams {
51    /// Alphanumeric string identifying the service.
52    pub service_id: String,
53    /// Alphanumeric string identifying a Pool.
54    pub pool_id: String,
55    /// Alphanumeric string identifying a Server.
56    pub server_id: String
57}
58
59/// struct for passing parameters to the method [`list_pool_servers`]
60#[derive(Clone, Debug, Default)]
61pub struct ListPoolServersParams {
62    /// Alphanumeric string identifying the service.
63    pub service_id: String,
64    /// Alphanumeric string identifying a Pool.
65    pub pool_id: String
66}
67
68/// struct for passing parameters to the method [`update_pool_server`]
69#[derive(Clone, Debug, Default)]
70pub struct UpdatePoolServerParams {
71    /// Alphanumeric string identifying the service.
72    pub service_id: String,
73    /// Alphanumeric string identifying a Pool.
74    pub pool_id: String,
75    /// Alphanumeric string identifying a Server.
76    pub server_id: String,
77    /// Weight (`1-100`) used to load balance this server against others.
78    pub weight: Option<i32>,
79    /// Maximum number of connections. If the value is `0`, it inherits the value from pool's `max_conn_default`.
80    pub max_conn: Option<i32>,
81    /// Port number. Setting port `443` does not force TLS. Set `use_tls` in pool to force TLS.
82    pub port: Option<i32>,
83    /// A hostname, IPv4, or IPv6 address for the server. Required.
84    pub address: Option<String>,
85    /// A freeform descriptive note.
86    pub comment: Option<String>,
87    /// Allows servers to be enabled and disabled in a pool.
88    pub disabled: Option<bool>,
89    /// The hostname to override the Host header. Defaults to `null` meaning no override of the Host header if not set. This setting can also be added to a Pool definition. However, the server setting will override the Pool setting.
90    pub override_host: Option<String>
91}
92
93
94/// struct for typed errors of method [`create_pool_server`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum CreatePoolServerError {
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`delete_pool_server`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum DeletePoolServerError {
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_pool_server`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetPoolServerError {
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`list_pool_servers`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum ListPoolServersError {
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`update_pool_server`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum UpdatePoolServerError {
126    UnknownValue(serde_json::Value),
127}
128
129
130/// Creates a single server for a particular service and pool.
131pub async fn create_pool_server(configuration: &mut configuration::Configuration, params: CreatePoolServerParams) -> Result<crate::models::ServerResponse, Error<CreatePoolServerError>> {
132    let local_var_configuration = configuration;
133
134    // unbox the parameters
135    let service_id = params.service_id;
136    let pool_id = params.pool_id;
137    let weight = params.weight;
138    let max_conn = params.max_conn;
139    let port = params.port;
140    let address = params.address;
141    let comment = params.comment;
142    let disabled = params.disabled;
143    let override_host = params.override_host;
144
145
146    let local_var_client = &local_var_configuration.client;
147
148    let local_var_uri_str = format!("{}/service/{service_id}/pool/{pool_id}/server", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), pool_id=crate::apis::urlencode(pool_id));
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153    }
154    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
155        let local_var_key = local_var_apikey.key.clone();
156        let local_var_value = match local_var_apikey.prefix {
157            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
158            None => local_var_key,
159        };
160        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
161    };
162    let mut local_var_form_params = std::collections::HashMap::new();
163    if let Some(local_var_param_value) = weight {
164        local_var_form_params.insert("weight", local_var_param_value.to_string());
165    }
166    if let Some(local_var_param_value) = max_conn {
167        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
168    }
169    if let Some(local_var_param_value) = port {
170        local_var_form_params.insert("port", local_var_param_value.to_string());
171    }
172    if let Some(local_var_param_value) = address {
173        local_var_form_params.insert("address", local_var_param_value.to_string());
174    }
175    if let Some(local_var_param_value) = comment {
176        local_var_form_params.insert("comment", local_var_param_value.to_string());
177    }
178    if let Some(local_var_param_value) = disabled {
179        local_var_form_params.insert("disabled", local_var_param_value.to_string());
180    }
181    if let Some(local_var_param_value) = override_host {
182        local_var_form_params.insert("override_host", local_var_param_value.to_string());
183    }
184    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
185
186    let local_var_req = local_var_req_builder.build()?;
187    let local_var_resp = local_var_client.execute(local_var_req).await?;
188
189    if "POST" != "GET" && "POST" != "HEAD" {
190      let headers = local_var_resp.headers();
191      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
192          Some(v) => v.to_str().unwrap().parse().unwrap(),
193          None => configuration::DEFAULT_RATELIMIT,
194      };
195      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
196          Some(v) => v.to_str().unwrap().parse().unwrap(),
197          None => 0,
198      };
199    }
200
201    let local_var_status = local_var_resp.status();
202    let local_var_content = local_var_resp.text().await?;
203
204    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
205        serde_json::from_str(&local_var_content).map_err(Error::from)
206    } else {
207        let local_var_entity: Option<CreatePoolServerError> = serde_json::from_str(&local_var_content).ok();
208        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
209        Err(Error::ResponseError(local_var_error))
210    }
211}
212
213/// Deletes a single server for a particular service and pool.
214pub async fn delete_pool_server(configuration: &mut configuration::Configuration, params: DeletePoolServerParams) -> Result<crate::models::InlineResponse200, Error<DeletePoolServerError>> {
215    let local_var_configuration = configuration;
216
217    // unbox the parameters
218    let service_id = params.service_id;
219    let pool_id = params.pool_id;
220    let server_id = params.server_id;
221
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/service/{service_id}/pool/{pool_id}/server/{server_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), pool_id=crate::apis::urlencode(pool_id), server_id=crate::apis::urlencode(server_id));
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
232        let local_var_key = local_var_apikey.key.clone();
233        let local_var_value = match local_var_apikey.prefix {
234            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
235            None => local_var_key,
236        };
237        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
238    };
239
240    let local_var_req = local_var_req_builder.build()?;
241    let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243    if "DELETE" != "GET" && "DELETE" != "HEAD" {
244      let headers = local_var_resp.headers();
245      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
246          Some(v) => v.to_str().unwrap().parse().unwrap(),
247          None => configuration::DEFAULT_RATELIMIT,
248      };
249      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
250          Some(v) => v.to_str().unwrap().parse().unwrap(),
251          None => 0,
252      };
253    }
254
255    let local_var_status = local_var_resp.status();
256    let local_var_content = local_var_resp.text().await?;
257
258    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259        serde_json::from_str(&local_var_content).map_err(Error::from)
260    } else {
261        let local_var_entity: Option<DeletePoolServerError> = serde_json::from_str(&local_var_content).ok();
262        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263        Err(Error::ResponseError(local_var_error))
264    }
265}
266
267/// Gets a single server for a particular service and pool.
268pub async fn get_pool_server(configuration: &mut configuration::Configuration, params: GetPoolServerParams) -> Result<crate::models::ServerResponse, Error<GetPoolServerError>> {
269    let local_var_configuration = configuration;
270
271    // unbox the parameters
272    let service_id = params.service_id;
273    let pool_id = params.pool_id;
274    let server_id = params.server_id;
275
276
277    let local_var_client = &local_var_configuration.client;
278
279    let local_var_uri_str = format!("{}/service/{service_id}/pool/{pool_id}/server/{server_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), pool_id=crate::apis::urlencode(pool_id), server_id=crate::apis::urlencode(server_id));
280    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
281
282    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284    }
285    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
286        let local_var_key = local_var_apikey.key.clone();
287        let local_var_value = match local_var_apikey.prefix {
288            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
289            None => local_var_key,
290        };
291        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
292    };
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    if "GET" != "GET" && "GET" != "HEAD" {
298      let headers = local_var_resp.headers();
299      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
300          Some(v) => v.to_str().unwrap().parse().unwrap(),
301          None => configuration::DEFAULT_RATELIMIT,
302      };
303      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
304          Some(v) => v.to_str().unwrap().parse().unwrap(),
305          None => 0,
306      };
307    }
308
309    let local_var_status = local_var_resp.status();
310    let local_var_content = local_var_resp.text().await?;
311
312    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
313        serde_json::from_str(&local_var_content).map_err(Error::from)
314    } else {
315        let local_var_entity: Option<GetPoolServerError> = serde_json::from_str(&local_var_content).ok();
316        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
317        Err(Error::ResponseError(local_var_error))
318    }
319}
320
321/// Lists all servers for a particular service and pool.
322pub async fn list_pool_servers(configuration: &mut configuration::Configuration, params: ListPoolServersParams) -> Result<Vec<crate::models::ServerResponse>, Error<ListPoolServersError>> {
323    let local_var_configuration = configuration;
324
325    // unbox the parameters
326    let service_id = params.service_id;
327    let pool_id = params.pool_id;
328
329
330    let local_var_client = &local_var_configuration.client;
331
332    let local_var_uri_str = format!("{}/service/{service_id}/pool/{pool_id}/servers", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), pool_id=crate::apis::urlencode(pool_id));
333    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
334
335    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
336        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
337    }
338    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
339        let local_var_key = local_var_apikey.key.clone();
340        let local_var_value = match local_var_apikey.prefix {
341            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
342            None => local_var_key,
343        };
344        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
345    };
346
347    let local_var_req = local_var_req_builder.build()?;
348    let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350    if "GET" != "GET" && "GET" != "HEAD" {
351      let headers = local_var_resp.headers();
352      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
353          Some(v) => v.to_str().unwrap().parse().unwrap(),
354          None => configuration::DEFAULT_RATELIMIT,
355      };
356      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
357          Some(v) => v.to_str().unwrap().parse().unwrap(),
358          None => 0,
359      };
360    }
361
362    let local_var_status = local_var_resp.status();
363    let local_var_content = local_var_resp.text().await?;
364
365    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
366        serde_json::from_str(&local_var_content).map_err(Error::from)
367    } else {
368        let local_var_entity: Option<ListPoolServersError> = serde_json::from_str(&local_var_content).ok();
369        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
370        Err(Error::ResponseError(local_var_error))
371    }
372}
373
374/// Updates a single server for a particular service and pool.
375pub async fn update_pool_server(configuration: &mut configuration::Configuration, params: UpdatePoolServerParams) -> Result<crate::models::ServerResponse, Error<UpdatePoolServerError>> {
376    let local_var_configuration = configuration;
377
378    // unbox the parameters
379    let service_id = params.service_id;
380    let pool_id = params.pool_id;
381    let server_id = params.server_id;
382    let weight = params.weight;
383    let max_conn = params.max_conn;
384    let port = params.port;
385    let address = params.address;
386    let comment = params.comment;
387    let disabled = params.disabled;
388    let override_host = params.override_host;
389
390
391    let local_var_client = &local_var_configuration.client;
392
393    let local_var_uri_str = format!("{}/service/{service_id}/pool/{pool_id}/server/{server_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), pool_id=crate::apis::urlencode(pool_id), server_id=crate::apis::urlencode(server_id));
394    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
395
396    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
397        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
398    }
399    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
400        let local_var_key = local_var_apikey.key.clone();
401        let local_var_value = match local_var_apikey.prefix {
402            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
403            None => local_var_key,
404        };
405        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
406    };
407    let mut local_var_form_params = std::collections::HashMap::new();
408    if let Some(local_var_param_value) = weight {
409        local_var_form_params.insert("weight", local_var_param_value.to_string());
410    }
411    if let Some(local_var_param_value) = max_conn {
412        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
413    }
414    if let Some(local_var_param_value) = port {
415        local_var_form_params.insert("port", local_var_param_value.to_string());
416    }
417    if let Some(local_var_param_value) = address {
418        local_var_form_params.insert("address", local_var_param_value.to_string());
419    }
420    if let Some(local_var_param_value) = comment {
421        local_var_form_params.insert("comment", local_var_param_value.to_string());
422    }
423    if let Some(local_var_param_value) = disabled {
424        local_var_form_params.insert("disabled", local_var_param_value.to_string());
425    }
426    if let Some(local_var_param_value) = override_host {
427        local_var_form_params.insert("override_host", local_var_param_value.to_string());
428    }
429    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
430
431    let local_var_req = local_var_req_builder.build()?;
432    let local_var_resp = local_var_client.execute(local_var_req).await?;
433
434    if "PUT" != "GET" && "PUT" != "HEAD" {
435      let headers = local_var_resp.headers();
436      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
437          Some(v) => v.to_str().unwrap().parse().unwrap(),
438          None => configuration::DEFAULT_RATELIMIT,
439      };
440      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
441          Some(v) => v.to_str().unwrap().parse().unwrap(),
442          None => 0,
443      };
444    }
445
446    let local_var_status = local_var_resp.status();
447    let local_var_content = local_var_resp.text().await?;
448
449    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
450        serde_json::from_str(&local_var_content).map_err(Error::from)
451    } else {
452        let local_var_entity: Option<UpdatePoolServerError> = serde_json::from_str(&local_var_content).ok();
453        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
454        Err(Error::ResponseError(local_var_error))
455    }
456}
457