fastly_api/apis/
backend_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_backend`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateBackendParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// A hostname, IPv4, or IPv6 address for the backend. This is the preferred way to specify the location of your backend.
22    pub address: Option<String>,
23    /// Whether or not this backend should be automatically load balanced. If true, all backends with this setting that don't have a `request_condition` will be selected based on their `weight`.
24    pub auto_loadbalance: Option<bool>,
25    /// Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. If exceeded, the response received so far will be considered complete and the fetch will end. May be set at runtime using `bereq.between_bytes_timeout`.
26    pub between_bytes_timeout: Option<i32>,
27    /// Unused.
28    pub client_cert: Option<String>,
29    /// A freeform descriptive note.
30    pub comment: Option<String>,
31    /// Maximum duration in milliseconds to wait for a connection to this backend to be established. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.connect_timeout`.
32    pub connect_timeout: Option<i32>,
33    /// Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.first_byte_timeout`.
34    pub first_byte_timeout: Option<i32>,
35    /// The name of the healthcheck to use with this backend.
36    pub healthcheck: Option<String>,
37    /// The hostname of the backend. May be used as an alternative to `address` to set the backend location.
38    pub hostname: Option<String>,
39    /// IPv4 address of the backend. May be used as an alternative to `address` to set the backend location.
40    pub ipv4: Option<String>,
41    /// IPv6 address of the backend. May be used as an alternative to `address` to set the backend location.
42    pub ipv6: Option<String>,
43    /// How long in seconds to keep a persistent connection to the backend between requests.
44    pub keepalive_time: Option<i32>,
45    /// Maximum number of concurrent connections this backend will accept.
46    pub max_conn: Option<i32>,
47    /// Maximum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
48    pub max_tls_version: Option<String>,
49    /// Minimum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
50    pub min_tls_version: Option<String>,
51    /// The name of the backend.
52    pub name: Option<String>,
53    /// If set, will replace the client-supplied HTTP `Host` header on connections to this backend. Applied after VCL has been processed, so this setting will take precedence over changing `bereq.http.Host` in VCL.
54    pub override_host: Option<String>,
55    /// Port on which the backend server is listening for connections from Fastly. Setting `port` to 80 or 443 will also set `use_ssl` automatically (to false and true respectively), unless explicitly overridden by setting `use_ssl` in the same request.
56    pub port: Option<i32>,
57    /// Name of a Condition, which if satisfied, will select this backend during a request. If set, will override any `auto_loadbalance` setting. By default, the first backend added to a service is selected for all requests.
58    pub request_condition: Option<String>,
59    /// Value that when shared across backends will enable those backends to share the same health check.
60    pub share_key: Option<String>,
61    /// Identifier of the POP to use as a [shield](https://docs.fastly.com/en/guides/shielding).
62    pub shield: Option<String>,
63    /// CA certificate attached to origin.
64    pub ssl_ca_cert: Option<String>,
65    /// Overrides `ssl_hostname`, but only for cert verification. Does not affect SNI at all.
66    pub ssl_cert_hostname: Option<String>,
67    /// Be strict on checking SSL certs.
68    pub ssl_check_cert: Option<bool>,
69    /// List of [OpenSSL ciphers](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html) to support for connections to this origin. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
70    pub ssl_ciphers: Option<String>,
71    /// Client certificate attached to origin.
72    pub ssl_client_cert: Option<String>,
73    /// Client key attached to origin.
74    pub ssl_client_key: Option<String>,
75    /// Use `ssl_cert_hostname` and `ssl_sni_hostname` to configure certificate validation.
76    pub ssl_hostname: Option<String>,
77    /// Overrides `ssl_hostname`, but only for SNI in the handshake. Does not affect cert validation at all.
78    pub ssl_sni_hostname: Option<String>,
79    /// Whether to enable TCP keepalives for backend connections. Varnish defaults to using keepalives if this is unspecified.
80    pub tcp_keepalive_enable: Option<bool>,
81    /// Interval in seconds between subsequent keepalive probes.
82    pub tcp_keepalive_interval: Option<i32>,
83    /// Number of unacknowledged probes to send before considering the connection dead.
84    pub tcp_keepalive_probes: Option<i32>,
85    /// Interval in seconds between the last data packet sent and the first keepalive probe.
86    pub tcp_keepalive_time: Option<i32>,
87    /// Whether or not to require TLS for connections to this backend.
88    pub use_ssl: Option<bool>,
89    /// Weight used to load balance this backend against others. May be any positive integer. If `auto_loadbalance` is true, the chance of this backend being selected is equal to its own weight over the sum of all weights for backends that have `auto_loadbalance` set to true.
90    pub weight: Option<i32>
91}
92
93/// struct for passing parameters to the method [`delete_backend`]
94#[derive(Clone, Debug, Default)]
95pub struct DeleteBackendParams {
96    /// Alphanumeric string identifying the service.
97    pub service_id: String,
98    /// Integer identifying a service version.
99    pub version_id: i32,
100    /// The name of the backend.
101    pub backend_name: String
102}
103
104/// struct for passing parameters to the method [`get_backend`]
105#[derive(Clone, Debug, Default)]
106pub struct GetBackendParams {
107    /// Alphanumeric string identifying the service.
108    pub service_id: String,
109    /// Integer identifying a service version.
110    pub version_id: i32,
111    /// The name of the backend.
112    pub backend_name: String
113}
114
115/// struct for passing parameters to the method [`list_backends`]
116#[derive(Clone, Debug, Default)]
117pub struct ListBackendsParams {
118    /// Alphanumeric string identifying the service.
119    pub service_id: String,
120    /// Integer identifying a service version.
121    pub version_id: i32
122}
123
124/// struct for passing parameters to the method [`update_backend`]
125#[derive(Clone, Debug, Default)]
126pub struct UpdateBackendParams {
127    /// Alphanumeric string identifying the service.
128    pub service_id: String,
129    /// Integer identifying a service version.
130    pub version_id: i32,
131    /// The name of the backend.
132    pub backend_name: String,
133    /// A hostname, IPv4, or IPv6 address for the backend. This is the preferred way to specify the location of your backend.
134    pub address: Option<String>,
135    /// Whether or not this backend should be automatically load balanced. If true, all backends with this setting that don't have a `request_condition` will be selected based on their `weight`.
136    pub auto_loadbalance: Option<bool>,
137    /// Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. If exceeded, the response received so far will be considered complete and the fetch will end. May be set at runtime using `bereq.between_bytes_timeout`.
138    pub between_bytes_timeout: Option<i32>,
139    /// Unused.
140    pub client_cert: Option<String>,
141    /// A freeform descriptive note.
142    pub comment: Option<String>,
143    /// Maximum duration in milliseconds to wait for a connection to this backend to be established. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.connect_timeout`.
144    pub connect_timeout: Option<i32>,
145    /// Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.first_byte_timeout`.
146    pub first_byte_timeout: Option<i32>,
147    /// The name of the healthcheck to use with this backend.
148    pub healthcheck: Option<String>,
149    /// The hostname of the backend. May be used as an alternative to `address` to set the backend location.
150    pub hostname: Option<String>,
151    /// IPv4 address of the backend. May be used as an alternative to `address` to set the backend location.
152    pub ipv4: Option<String>,
153    /// IPv6 address of the backend. May be used as an alternative to `address` to set the backend location.
154    pub ipv6: Option<String>,
155    /// How long in seconds to keep a persistent connection to the backend between requests.
156    pub keepalive_time: Option<i32>,
157    /// Maximum number of concurrent connections this backend will accept.
158    pub max_conn: Option<i32>,
159    /// Maximum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
160    pub max_tls_version: Option<String>,
161    /// Minimum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
162    pub min_tls_version: Option<String>,
163    /// The name of the backend.
164    pub name: Option<String>,
165    /// If set, will replace the client-supplied HTTP `Host` header on connections to this backend. Applied after VCL has been processed, so this setting will take precedence over changing `bereq.http.Host` in VCL.
166    pub override_host: Option<String>,
167    /// Port on which the backend server is listening for connections from Fastly. Setting `port` to 80 or 443 will also set `use_ssl` automatically (to false and true respectively), unless explicitly overridden by setting `use_ssl` in the same request.
168    pub port: Option<i32>,
169    /// Name of a Condition, which if satisfied, will select this backend during a request. If set, will override any `auto_loadbalance` setting. By default, the first backend added to a service is selected for all requests.
170    pub request_condition: Option<String>,
171    /// Value that when shared across backends will enable those backends to share the same health check.
172    pub share_key: Option<String>,
173    /// Identifier of the POP to use as a [shield](https://docs.fastly.com/en/guides/shielding).
174    pub shield: Option<String>,
175    /// CA certificate attached to origin.
176    pub ssl_ca_cert: Option<String>,
177    /// Overrides `ssl_hostname`, but only for cert verification. Does not affect SNI at all.
178    pub ssl_cert_hostname: Option<String>,
179    /// Be strict on checking SSL certs.
180    pub ssl_check_cert: Option<bool>,
181    /// List of [OpenSSL ciphers](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html) to support for connections to this origin. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
182    pub ssl_ciphers: Option<String>,
183    /// Client certificate attached to origin.
184    pub ssl_client_cert: Option<String>,
185    /// Client key attached to origin.
186    pub ssl_client_key: Option<String>,
187    /// Use `ssl_cert_hostname` and `ssl_sni_hostname` to configure certificate validation.
188    pub ssl_hostname: Option<String>,
189    /// Overrides `ssl_hostname`, but only for SNI in the handshake. Does not affect cert validation at all.
190    pub ssl_sni_hostname: Option<String>,
191    /// Whether to enable TCP keepalives for backend connections. Varnish defaults to using keepalives if this is unspecified.
192    pub tcp_keepalive_enable: Option<bool>,
193    /// Interval in seconds between subsequent keepalive probes.
194    pub tcp_keepalive_interval: Option<i32>,
195    /// Number of unacknowledged probes to send before considering the connection dead.
196    pub tcp_keepalive_probes: Option<i32>,
197    /// Interval in seconds between the last data packet sent and the first keepalive probe.
198    pub tcp_keepalive_time: Option<i32>,
199    /// Whether or not to require TLS for connections to this backend.
200    pub use_ssl: Option<bool>,
201    /// Weight used to load balance this backend against others. May be any positive integer. If `auto_loadbalance` is true, the chance of this backend being selected is equal to its own weight over the sum of all weights for backends that have `auto_loadbalance` set to true.
202    pub weight: Option<i32>
203}
204
205
206/// struct for typed errors of method [`create_backend`]
207#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum CreateBackendError {
210    UnknownValue(serde_json::Value),
211}
212
213/// struct for typed errors of method [`delete_backend`]
214#[derive(Debug, Clone, Serialize, Deserialize)]
215#[serde(untagged)]
216pub enum DeleteBackendError {
217    UnknownValue(serde_json::Value),
218}
219
220/// struct for typed errors of method [`get_backend`]
221#[derive(Debug, Clone, Serialize, Deserialize)]
222#[serde(untagged)]
223pub enum GetBackendError {
224    UnknownValue(serde_json::Value),
225}
226
227/// struct for typed errors of method [`list_backends`]
228#[derive(Debug, Clone, Serialize, Deserialize)]
229#[serde(untagged)]
230pub enum ListBackendsError {
231    UnknownValue(serde_json::Value),
232}
233
234/// struct for typed errors of method [`update_backend`]
235#[derive(Debug, Clone, Serialize, Deserialize)]
236#[serde(untagged)]
237pub enum UpdateBackendError {
238    UnknownValue(serde_json::Value),
239}
240
241
242/// Create a backend for a particular service and version.
243pub async fn create_backend(configuration: &mut configuration::Configuration, params: CreateBackendParams) -> Result<crate::models::BackendResponse, Error<CreateBackendError>> {
244    let local_var_configuration = configuration;
245
246    // unbox the parameters
247    let service_id = params.service_id;
248    let version_id = params.version_id;
249    let address = params.address;
250    let auto_loadbalance = params.auto_loadbalance;
251    let between_bytes_timeout = params.between_bytes_timeout;
252    let client_cert = params.client_cert;
253    let comment = params.comment;
254    let connect_timeout = params.connect_timeout;
255    let first_byte_timeout = params.first_byte_timeout;
256    let healthcheck = params.healthcheck;
257    let hostname = params.hostname;
258    let ipv4 = params.ipv4;
259    let ipv6 = params.ipv6;
260    let keepalive_time = params.keepalive_time;
261    let max_conn = params.max_conn;
262    let max_tls_version = params.max_tls_version;
263    let min_tls_version = params.min_tls_version;
264    let name = params.name;
265    let override_host = params.override_host;
266    let port = params.port;
267    let request_condition = params.request_condition;
268    let share_key = params.share_key;
269    let shield = params.shield;
270    let ssl_ca_cert = params.ssl_ca_cert;
271    let ssl_cert_hostname = params.ssl_cert_hostname;
272    let ssl_check_cert = params.ssl_check_cert;
273    let ssl_ciphers = params.ssl_ciphers;
274    let ssl_client_cert = params.ssl_client_cert;
275    let ssl_client_key = params.ssl_client_key;
276    let ssl_hostname = params.ssl_hostname;
277    let ssl_sni_hostname = params.ssl_sni_hostname;
278    let tcp_keepalive_enable = params.tcp_keepalive_enable;
279    let tcp_keepalive_interval = params.tcp_keepalive_interval;
280    let tcp_keepalive_probes = params.tcp_keepalive_probes;
281    let tcp_keepalive_time = params.tcp_keepalive_time;
282    let use_ssl = params.use_ssl;
283    let weight = params.weight;
284
285
286    let local_var_client = &local_var_configuration.client;
287
288    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
289    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
290
291    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
292        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
293    }
294    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
295        let local_var_key = local_var_apikey.key.clone();
296        let local_var_value = match local_var_apikey.prefix {
297            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
298            None => local_var_key,
299        };
300        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
301    };
302    let mut local_var_form_params = std::collections::HashMap::new();
303    if let Some(local_var_param_value) = address {
304        local_var_form_params.insert("address", local_var_param_value.to_string());
305    }
306    if let Some(local_var_param_value) = auto_loadbalance {
307        local_var_form_params.insert("auto_loadbalance", local_var_param_value.to_string());
308    }
309    if let Some(local_var_param_value) = between_bytes_timeout {
310        local_var_form_params.insert("between_bytes_timeout", local_var_param_value.to_string());
311    }
312    if let Some(local_var_param_value) = client_cert {
313        local_var_form_params.insert("client_cert", local_var_param_value.to_string());
314    }
315    if let Some(local_var_param_value) = comment {
316        local_var_form_params.insert("comment", local_var_param_value.to_string());
317    }
318    if let Some(local_var_param_value) = connect_timeout {
319        local_var_form_params.insert("connect_timeout", local_var_param_value.to_string());
320    }
321    if let Some(local_var_param_value) = first_byte_timeout {
322        local_var_form_params.insert("first_byte_timeout", local_var_param_value.to_string());
323    }
324    if let Some(local_var_param_value) = healthcheck {
325        local_var_form_params.insert("healthcheck", local_var_param_value.to_string());
326    }
327    if let Some(local_var_param_value) = hostname {
328        local_var_form_params.insert("hostname", local_var_param_value.to_string());
329    }
330    if let Some(local_var_param_value) = ipv4 {
331        local_var_form_params.insert("ipv4", local_var_param_value.to_string());
332    }
333    if let Some(local_var_param_value) = ipv6 {
334        local_var_form_params.insert("ipv6", local_var_param_value.to_string());
335    }
336    if let Some(local_var_param_value) = keepalive_time {
337        local_var_form_params.insert("keepalive_time", local_var_param_value.to_string());
338    }
339    if let Some(local_var_param_value) = max_conn {
340        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
341    }
342    if let Some(local_var_param_value) = max_tls_version {
343        local_var_form_params.insert("max_tls_version", local_var_param_value.to_string());
344    }
345    if let Some(local_var_param_value) = min_tls_version {
346        local_var_form_params.insert("min_tls_version", local_var_param_value.to_string());
347    }
348    if let Some(local_var_param_value) = name {
349        local_var_form_params.insert("name", local_var_param_value.to_string());
350    }
351    if let Some(local_var_param_value) = override_host {
352        local_var_form_params.insert("override_host", local_var_param_value.to_string());
353    }
354    if let Some(local_var_param_value) = port {
355        local_var_form_params.insert("port", local_var_param_value.to_string());
356    }
357    if let Some(local_var_param_value) = request_condition {
358        local_var_form_params.insert("request_condition", local_var_param_value.to_string());
359    }
360    if let Some(local_var_param_value) = share_key {
361        local_var_form_params.insert("share_key", local_var_param_value.to_string());
362    }
363    if let Some(local_var_param_value) = shield {
364        local_var_form_params.insert("shield", local_var_param_value.to_string());
365    }
366    if let Some(local_var_param_value) = ssl_ca_cert {
367        local_var_form_params.insert("ssl_ca_cert", local_var_param_value.to_string());
368    }
369    if let Some(local_var_param_value) = ssl_cert_hostname {
370        local_var_form_params.insert("ssl_cert_hostname", local_var_param_value.to_string());
371    }
372    if let Some(local_var_param_value) = ssl_check_cert {
373        local_var_form_params.insert("ssl_check_cert", local_var_param_value.to_string());
374    }
375    if let Some(local_var_param_value) = ssl_ciphers {
376        local_var_form_params.insert("ssl_ciphers", local_var_param_value.to_string());
377    }
378    if let Some(local_var_param_value) = ssl_client_cert {
379        local_var_form_params.insert("ssl_client_cert", local_var_param_value.to_string());
380    }
381    if let Some(local_var_param_value) = ssl_client_key {
382        local_var_form_params.insert("ssl_client_key", local_var_param_value.to_string());
383    }
384    if let Some(local_var_param_value) = ssl_hostname {
385        local_var_form_params.insert("ssl_hostname", local_var_param_value.to_string());
386    }
387    if let Some(local_var_param_value) = ssl_sni_hostname {
388        local_var_form_params.insert("ssl_sni_hostname", local_var_param_value.to_string());
389    }
390    if let Some(local_var_param_value) = tcp_keepalive_enable {
391        local_var_form_params.insert("tcp_keepalive_enable", local_var_param_value.to_string());
392    }
393    if let Some(local_var_param_value) = tcp_keepalive_interval {
394        local_var_form_params.insert("tcp_keepalive_interval", local_var_param_value.to_string());
395    }
396    if let Some(local_var_param_value) = tcp_keepalive_probes {
397        local_var_form_params.insert("tcp_keepalive_probes", local_var_param_value.to_string());
398    }
399    if let Some(local_var_param_value) = tcp_keepalive_time {
400        local_var_form_params.insert("tcp_keepalive_time", local_var_param_value.to_string());
401    }
402    if let Some(local_var_param_value) = use_ssl {
403        local_var_form_params.insert("use_ssl", local_var_param_value.to_string());
404    }
405    if let Some(local_var_param_value) = weight {
406        local_var_form_params.insert("weight", local_var_param_value.to_string());
407    }
408    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
409
410    let local_var_req = local_var_req_builder.build()?;
411    let local_var_resp = local_var_client.execute(local_var_req).await?;
412
413    if "POST" != "GET" && "POST" != "HEAD" {
414      let headers = local_var_resp.headers();
415      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
416          Some(v) => v.to_str().unwrap().parse().unwrap(),
417          None => configuration::DEFAULT_RATELIMIT,
418      };
419      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
420          Some(v) => v.to_str().unwrap().parse().unwrap(),
421          None => 0,
422      };
423    }
424
425    let local_var_status = local_var_resp.status();
426    let local_var_content = local_var_resp.text().await?;
427
428    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
429        serde_json::from_str(&local_var_content).map_err(Error::from)
430    } else {
431        let local_var_entity: Option<CreateBackendError> = serde_json::from_str(&local_var_content).ok();
432        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
433        Err(Error::ResponseError(local_var_error))
434    }
435}
436
437/// Delete the backend for a particular service and version.
438pub async fn delete_backend(configuration: &mut configuration::Configuration, params: DeleteBackendParams) -> Result<crate::models::InlineResponse200, Error<DeleteBackendError>> {
439    let local_var_configuration = configuration;
440
441    // unbox the parameters
442    let service_id = params.service_id;
443    let version_id = params.version_id;
444    let backend_name = params.backend_name;
445
446
447    let local_var_client = &local_var_configuration.client;
448
449    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
450    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
451
452    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
453        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
454    }
455    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
456        let local_var_key = local_var_apikey.key.clone();
457        let local_var_value = match local_var_apikey.prefix {
458            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
459            None => local_var_key,
460        };
461        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
462    };
463
464    let local_var_req = local_var_req_builder.build()?;
465    let local_var_resp = local_var_client.execute(local_var_req).await?;
466
467    if "DELETE" != "GET" && "DELETE" != "HEAD" {
468      let headers = local_var_resp.headers();
469      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
470          Some(v) => v.to_str().unwrap().parse().unwrap(),
471          None => configuration::DEFAULT_RATELIMIT,
472      };
473      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
474          Some(v) => v.to_str().unwrap().parse().unwrap(),
475          None => 0,
476      };
477    }
478
479    let local_var_status = local_var_resp.status();
480    let local_var_content = local_var_resp.text().await?;
481
482    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
483        serde_json::from_str(&local_var_content).map_err(Error::from)
484    } else {
485        let local_var_entity: Option<DeleteBackendError> = serde_json::from_str(&local_var_content).ok();
486        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
487        Err(Error::ResponseError(local_var_error))
488    }
489}
490
491/// Get the backend for a particular service and version.
492pub async fn get_backend(configuration: &mut configuration::Configuration, params: GetBackendParams) -> Result<crate::models::BackendResponse, Error<GetBackendError>> {
493    let local_var_configuration = configuration;
494
495    // unbox the parameters
496    let service_id = params.service_id;
497    let version_id = params.version_id;
498    let backend_name = params.backend_name;
499
500
501    let local_var_client = &local_var_configuration.client;
502
503    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
504    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
505
506    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
507        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
508    }
509    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
510        let local_var_key = local_var_apikey.key.clone();
511        let local_var_value = match local_var_apikey.prefix {
512            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
513            None => local_var_key,
514        };
515        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
516    };
517
518    let local_var_req = local_var_req_builder.build()?;
519    let local_var_resp = local_var_client.execute(local_var_req).await?;
520
521    if "GET" != "GET" && "GET" != "HEAD" {
522      let headers = local_var_resp.headers();
523      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
524          Some(v) => v.to_str().unwrap().parse().unwrap(),
525          None => configuration::DEFAULT_RATELIMIT,
526      };
527      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
528          Some(v) => v.to_str().unwrap().parse().unwrap(),
529          None => 0,
530      };
531    }
532
533    let local_var_status = local_var_resp.status();
534    let local_var_content = local_var_resp.text().await?;
535
536    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
537        serde_json::from_str(&local_var_content).map_err(Error::from)
538    } else {
539        let local_var_entity: Option<GetBackendError> = serde_json::from_str(&local_var_content).ok();
540        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
541        Err(Error::ResponseError(local_var_error))
542    }
543}
544
545/// List all backends for a particular service and version.
546pub async fn list_backends(configuration: &mut configuration::Configuration, params: ListBackendsParams) -> Result<Vec<crate::models::BackendResponse>, Error<ListBackendsError>> {
547    let local_var_configuration = configuration;
548
549    // unbox the parameters
550    let service_id = params.service_id;
551    let version_id = params.version_id;
552
553
554    let local_var_client = &local_var_configuration.client;
555
556    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
557    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
558
559    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
560        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
561    }
562    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
563        let local_var_key = local_var_apikey.key.clone();
564        let local_var_value = match local_var_apikey.prefix {
565            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
566            None => local_var_key,
567        };
568        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
569    };
570
571    let local_var_req = local_var_req_builder.build()?;
572    let local_var_resp = local_var_client.execute(local_var_req).await?;
573
574    if "GET" != "GET" && "GET" != "HEAD" {
575      let headers = local_var_resp.headers();
576      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
577          Some(v) => v.to_str().unwrap().parse().unwrap(),
578          None => configuration::DEFAULT_RATELIMIT,
579      };
580      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
581          Some(v) => v.to_str().unwrap().parse().unwrap(),
582          None => 0,
583      };
584    }
585
586    let local_var_status = local_var_resp.status();
587    let local_var_content = local_var_resp.text().await?;
588
589    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
590        serde_json::from_str(&local_var_content).map_err(Error::from)
591    } else {
592        let local_var_entity: Option<ListBackendsError> = serde_json::from_str(&local_var_content).ok();
593        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
594        Err(Error::ResponseError(local_var_error))
595    }
596}
597
598/// Update the backend for a particular service and version.
599pub async fn update_backend(configuration: &mut configuration::Configuration, params: UpdateBackendParams) -> Result<crate::models::BackendResponse, Error<UpdateBackendError>> {
600    let local_var_configuration = configuration;
601
602    // unbox the parameters
603    let service_id = params.service_id;
604    let version_id = params.version_id;
605    let backend_name = params.backend_name;
606    let address = params.address;
607    let auto_loadbalance = params.auto_loadbalance;
608    let between_bytes_timeout = params.between_bytes_timeout;
609    let client_cert = params.client_cert;
610    let comment = params.comment;
611    let connect_timeout = params.connect_timeout;
612    let first_byte_timeout = params.first_byte_timeout;
613    let healthcheck = params.healthcheck;
614    let hostname = params.hostname;
615    let ipv4 = params.ipv4;
616    let ipv6 = params.ipv6;
617    let keepalive_time = params.keepalive_time;
618    let max_conn = params.max_conn;
619    let max_tls_version = params.max_tls_version;
620    let min_tls_version = params.min_tls_version;
621    let name = params.name;
622    let override_host = params.override_host;
623    let port = params.port;
624    let request_condition = params.request_condition;
625    let share_key = params.share_key;
626    let shield = params.shield;
627    let ssl_ca_cert = params.ssl_ca_cert;
628    let ssl_cert_hostname = params.ssl_cert_hostname;
629    let ssl_check_cert = params.ssl_check_cert;
630    let ssl_ciphers = params.ssl_ciphers;
631    let ssl_client_cert = params.ssl_client_cert;
632    let ssl_client_key = params.ssl_client_key;
633    let ssl_hostname = params.ssl_hostname;
634    let ssl_sni_hostname = params.ssl_sni_hostname;
635    let tcp_keepalive_enable = params.tcp_keepalive_enable;
636    let tcp_keepalive_interval = params.tcp_keepalive_interval;
637    let tcp_keepalive_probes = params.tcp_keepalive_probes;
638    let tcp_keepalive_time = params.tcp_keepalive_time;
639    let use_ssl = params.use_ssl;
640    let weight = params.weight;
641
642
643    let local_var_client = &local_var_configuration.client;
644
645    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
646    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
647
648    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
649        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
650    }
651    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
652        let local_var_key = local_var_apikey.key.clone();
653        let local_var_value = match local_var_apikey.prefix {
654            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
655            None => local_var_key,
656        };
657        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
658    };
659    let mut local_var_form_params = std::collections::HashMap::new();
660    if let Some(local_var_param_value) = address {
661        local_var_form_params.insert("address", local_var_param_value.to_string());
662    }
663    if let Some(local_var_param_value) = auto_loadbalance {
664        local_var_form_params.insert("auto_loadbalance", local_var_param_value.to_string());
665    }
666    if let Some(local_var_param_value) = between_bytes_timeout {
667        local_var_form_params.insert("between_bytes_timeout", local_var_param_value.to_string());
668    }
669    if let Some(local_var_param_value) = client_cert {
670        local_var_form_params.insert("client_cert", local_var_param_value.to_string());
671    }
672    if let Some(local_var_param_value) = comment {
673        local_var_form_params.insert("comment", local_var_param_value.to_string());
674    }
675    if let Some(local_var_param_value) = connect_timeout {
676        local_var_form_params.insert("connect_timeout", local_var_param_value.to_string());
677    }
678    if let Some(local_var_param_value) = first_byte_timeout {
679        local_var_form_params.insert("first_byte_timeout", local_var_param_value.to_string());
680    }
681    if let Some(local_var_param_value) = healthcheck {
682        local_var_form_params.insert("healthcheck", local_var_param_value.to_string());
683    }
684    if let Some(local_var_param_value) = hostname {
685        local_var_form_params.insert("hostname", local_var_param_value.to_string());
686    }
687    if let Some(local_var_param_value) = ipv4 {
688        local_var_form_params.insert("ipv4", local_var_param_value.to_string());
689    }
690    if let Some(local_var_param_value) = ipv6 {
691        local_var_form_params.insert("ipv6", local_var_param_value.to_string());
692    }
693    if let Some(local_var_param_value) = keepalive_time {
694        local_var_form_params.insert("keepalive_time", local_var_param_value.to_string());
695    }
696    if let Some(local_var_param_value) = max_conn {
697        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
698    }
699    if let Some(local_var_param_value) = max_tls_version {
700        local_var_form_params.insert("max_tls_version", local_var_param_value.to_string());
701    }
702    if let Some(local_var_param_value) = min_tls_version {
703        local_var_form_params.insert("min_tls_version", local_var_param_value.to_string());
704    }
705    if let Some(local_var_param_value) = name {
706        local_var_form_params.insert("name", local_var_param_value.to_string());
707    }
708    if let Some(local_var_param_value) = override_host {
709        local_var_form_params.insert("override_host", local_var_param_value.to_string());
710    }
711    if let Some(local_var_param_value) = port {
712        local_var_form_params.insert("port", local_var_param_value.to_string());
713    }
714    if let Some(local_var_param_value) = request_condition {
715        local_var_form_params.insert("request_condition", local_var_param_value.to_string());
716    }
717    if let Some(local_var_param_value) = share_key {
718        local_var_form_params.insert("share_key", local_var_param_value.to_string());
719    }
720    if let Some(local_var_param_value) = shield {
721        local_var_form_params.insert("shield", local_var_param_value.to_string());
722    }
723    if let Some(local_var_param_value) = ssl_ca_cert {
724        local_var_form_params.insert("ssl_ca_cert", local_var_param_value.to_string());
725    }
726    if let Some(local_var_param_value) = ssl_cert_hostname {
727        local_var_form_params.insert("ssl_cert_hostname", local_var_param_value.to_string());
728    }
729    if let Some(local_var_param_value) = ssl_check_cert {
730        local_var_form_params.insert("ssl_check_cert", local_var_param_value.to_string());
731    }
732    if let Some(local_var_param_value) = ssl_ciphers {
733        local_var_form_params.insert("ssl_ciphers", local_var_param_value.to_string());
734    }
735    if let Some(local_var_param_value) = ssl_client_cert {
736        local_var_form_params.insert("ssl_client_cert", local_var_param_value.to_string());
737    }
738    if let Some(local_var_param_value) = ssl_client_key {
739        local_var_form_params.insert("ssl_client_key", local_var_param_value.to_string());
740    }
741    if let Some(local_var_param_value) = ssl_hostname {
742        local_var_form_params.insert("ssl_hostname", local_var_param_value.to_string());
743    }
744    if let Some(local_var_param_value) = ssl_sni_hostname {
745        local_var_form_params.insert("ssl_sni_hostname", local_var_param_value.to_string());
746    }
747    if let Some(local_var_param_value) = tcp_keepalive_enable {
748        local_var_form_params.insert("tcp_keepalive_enable", local_var_param_value.to_string());
749    }
750    if let Some(local_var_param_value) = tcp_keepalive_interval {
751        local_var_form_params.insert("tcp_keepalive_interval", local_var_param_value.to_string());
752    }
753    if let Some(local_var_param_value) = tcp_keepalive_probes {
754        local_var_form_params.insert("tcp_keepalive_probes", local_var_param_value.to_string());
755    }
756    if let Some(local_var_param_value) = tcp_keepalive_time {
757        local_var_form_params.insert("tcp_keepalive_time", local_var_param_value.to_string());
758    }
759    if let Some(local_var_param_value) = use_ssl {
760        local_var_form_params.insert("use_ssl", local_var_param_value.to_string());
761    }
762    if let Some(local_var_param_value) = weight {
763        local_var_form_params.insert("weight", local_var_param_value.to_string());
764    }
765    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
766
767    let local_var_req = local_var_req_builder.build()?;
768    let local_var_resp = local_var_client.execute(local_var_req).await?;
769
770    if "PUT" != "GET" && "PUT" != "HEAD" {
771      let headers = local_var_resp.headers();
772      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
773          Some(v) => v.to_str().unwrap().parse().unwrap(),
774          None => configuration::DEFAULT_RATELIMIT,
775      };
776      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
777          Some(v) => v.to_str().unwrap().parse().unwrap(),
778          None => 0,
779      };
780    }
781
782    let local_var_status = local_var_resp.status();
783    let local_var_content = local_var_resp.text().await?;
784
785    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
786        serde_json::from_str(&local_var_content).map_err(Error::from)
787    } else {
788        let local_var_entity: Option<UpdateBackendError> = serde_json::from_str(&local_var_content).ok();
789        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
790        Err(Error::ResponseError(local_var_error))
791    }
792}
793