fastly_api/apis/
product_ddos_protection_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 [`disable_product_ddos_protection`]
15#[derive(Clone, Debug, Default)]
16pub struct DisableProductDdosProtectionParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String
19}
20
21/// struct for passing parameters to the method [`enable_product_ddos_protection`]
22#[derive(Clone, Debug, Default)]
23pub struct EnableProductDdosProtectionParams {
24    /// Alphanumeric string identifying the service.
25    pub service_id: String,
26    pub ddos_protection_request_enable_mode: Option<crate::models::DdosProtectionRequestEnableMode>
27}
28
29/// struct for passing parameters to the method [`get_product_ddos_protection`]
30#[derive(Clone, Debug, Default)]
31pub struct GetProductDdosProtectionParams {
32    /// Alphanumeric string identifying the service.
33    pub service_id: String
34}
35
36/// struct for passing parameters to the method [`get_product_ddos_protection_configuration`]
37#[derive(Clone, Debug, Default)]
38pub struct GetProductDdosProtectionConfigurationParams {
39    /// Alphanumeric string identifying the service.
40    pub service_id: String
41}
42
43/// struct for passing parameters to the method [`set_product_ddos_protection_configuration`]
44#[derive(Clone, Debug, Default)]
45pub struct SetProductDdosProtectionConfigurationParams {
46    /// Alphanumeric string identifying the service.
47    pub service_id: String,
48    pub ddos_protection_request_update_configuration: Option<crate::models::DdosProtectionRequestUpdateConfiguration>
49}
50
51
52/// struct for typed errors of method [`disable_product_ddos_protection`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DisableProductDdosProtectionError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`enable_product_ddos_protection`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum EnableProductDdosProtectionError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_product_ddos_protection`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetProductDdosProtectionError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`get_product_ddos_protection_configuration`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum GetProductDdosProtectionConfigurationError {
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`get_services_product_ddos_protection`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetServicesProductDdosProtectionError {
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`set_product_ddos_protection_configuration`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum SetProductDdosProtectionConfigurationError {
91    UnknownValue(serde_json::Value),
92}
93
94
95/// Disable the DDoS Protection product on a service.
96pub async fn disable_product_ddos_protection(configuration: &mut configuration::Configuration, params: DisableProductDdosProtectionParams) -> Result<(), Error<DisableProductDdosProtectionError>> {
97    let local_var_configuration = configuration;
98
99    // unbox the parameters
100    let service_id = params.service_id;
101
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
112        let local_var_key = local_var_apikey.key.clone();
113        let local_var_value = match local_var_apikey.prefix {
114            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
115            None => local_var_key,
116        };
117        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
118    };
119
120    let local_var_req = local_var_req_builder.build()?;
121    let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123    if "DELETE" != "GET" && "DELETE" != "HEAD" {
124      let headers = local_var_resp.headers();
125      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
126          Some(v) => v.to_str().unwrap().parse().unwrap(),
127          None => configuration::DEFAULT_RATELIMIT,
128      };
129      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
130          Some(v) => v.to_str().unwrap().parse().unwrap(),
131          None => 0,
132      };
133    }
134
135    let local_var_status = local_var_resp.status();
136    let local_var_content = local_var_resp.text().await?;
137
138    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139        Ok(())
140    } else {
141        let local_var_entity: Option<DisableProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
142        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
143        Err(Error::ResponseError(local_var_error))
144    }
145}
146
147/// Enable the DDoS Protection product on a service in default 'log' mode unless otherwise specified in the request body.
148pub async fn enable_product_ddos_protection(configuration: &mut configuration::Configuration, params: EnableProductDdosProtectionParams) -> Result<crate::models::DdosProtectionResponseEnable, Error<EnableProductDdosProtectionError>> {
149    let local_var_configuration = configuration;
150
151    // unbox the parameters
152    let service_id = params.service_id;
153    let ddos_protection_request_enable_mode = params.ddos_protection_request_enable_mode;
154
155
156    let local_var_client = &local_var_configuration.client;
157
158    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
159    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
160
161    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163    }
164    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
165        let local_var_key = local_var_apikey.key.clone();
166        let local_var_value = match local_var_apikey.prefix {
167            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
168            None => local_var_key,
169        };
170        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
171    };
172    local_var_req_builder = local_var_req_builder.json(&ddos_protection_request_enable_mode);
173
174    let local_var_req = local_var_req_builder.build()?;
175    let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177    if "PUT" != "GET" && "PUT" != "HEAD" {
178      let headers = local_var_resp.headers();
179      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
180          Some(v) => v.to_str().unwrap().parse().unwrap(),
181          None => configuration::DEFAULT_RATELIMIT,
182      };
183      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
184          Some(v) => v.to_str().unwrap().parse().unwrap(),
185          None => 0,
186      };
187    }
188
189    let local_var_status = local_var_resp.status();
190    let local_var_content = local_var_resp.text().await?;
191
192    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
193        serde_json::from_str(&local_var_content).map_err(Error::from)
194    } else {
195        let local_var_entity: Option<EnableProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
196        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
197        Err(Error::ResponseError(local_var_error))
198    }
199}
200
201/// Get the enablement status of the DDoS Protection product on a service.
202pub async fn get_product_ddos_protection(configuration: &mut configuration::Configuration, params: GetProductDdosProtectionParams) -> Result<crate::models::DdosProtectionResponseEnable, Error<GetProductDdosProtectionError>> {
203    let local_var_configuration = configuration;
204
205    // unbox the parameters
206    let service_id = params.service_id;
207
208
209    let local_var_client = &local_var_configuration.client;
210
211    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
212    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216    }
217    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
218        let local_var_key = local_var_apikey.key.clone();
219        let local_var_value = match local_var_apikey.prefix {
220            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
221            None => local_var_key,
222        };
223        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
224    };
225
226    let local_var_req = local_var_req_builder.build()?;
227    let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229    if "GET" != "GET" && "GET" != "HEAD" {
230      let headers = local_var_resp.headers();
231      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
232          Some(v) => v.to_str().unwrap().parse().unwrap(),
233          None => configuration::DEFAULT_RATELIMIT,
234      };
235      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
236          Some(v) => v.to_str().unwrap().parse().unwrap(),
237          None => 0,
238      };
239    }
240
241    let local_var_status = local_var_resp.status();
242    let local_var_content = local_var_resp.text().await?;
243
244    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245        serde_json::from_str(&local_var_content).map_err(Error::from)
246    } else {
247        let local_var_entity: Option<GetProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
248        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
249        Err(Error::ResponseError(local_var_error))
250    }
251}
252
253/// Get configuration of the DDoS Protection product on a service.
254pub async fn get_product_ddos_protection_configuration(configuration: &mut configuration::Configuration, params: GetProductDdosProtectionConfigurationParams) -> Result<crate::models::DdosProtectionResponseConfigure, Error<GetProductDdosProtectionConfigurationError>> {
255    let local_var_configuration = configuration;
256
257    // unbox the parameters
258    let service_id = params.service_id;
259
260
261    let local_var_client = &local_var_configuration.client;
262
263    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}/configuration", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
264    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
265
266    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
270        let local_var_key = local_var_apikey.key.clone();
271        let local_var_value = match local_var_apikey.prefix {
272            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
273            None => local_var_key,
274        };
275        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
276    };
277
278    let local_var_req = local_var_req_builder.build()?;
279    let local_var_resp = local_var_client.execute(local_var_req).await?;
280
281    if "GET" != "GET" && "GET" != "HEAD" {
282      let headers = local_var_resp.headers();
283      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
284          Some(v) => v.to_str().unwrap().parse().unwrap(),
285          None => configuration::DEFAULT_RATELIMIT,
286      };
287      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
288          Some(v) => v.to_str().unwrap().parse().unwrap(),
289          None => 0,
290      };
291    }
292
293    let local_var_status = local_var_resp.status();
294    let local_var_content = local_var_resp.text().await?;
295
296    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
297        serde_json::from_str(&local_var_content).map_err(Error::from)
298    } else {
299        let local_var_entity: Option<GetProductDdosProtectionConfigurationError> = serde_json::from_str(&local_var_content).ok();
300        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
301        Err(Error::ResponseError(local_var_error))
302    }
303}
304
305/// Get all the services which have the DDoS Protection product enabled.
306pub async fn get_services_product_ddos_protection(configuration: &mut configuration::Configuration) -> Result<crate::models::DdosProtectionResponseBodyGetAllServices, Error<GetServicesProductDdosProtectionError>> {
307    let local_var_configuration = configuration;
308
309    // unbox the parameters
310
311
312    let local_var_client = &local_var_configuration.client;
313
314    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services", local_var_configuration.base_path);
315    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
316
317    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
318        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319    }
320    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
321        let local_var_key = local_var_apikey.key.clone();
322        let local_var_value = match local_var_apikey.prefix {
323            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
324            None => local_var_key,
325        };
326        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
327    };
328
329    let local_var_req = local_var_req_builder.build()?;
330    let local_var_resp = local_var_client.execute(local_var_req).await?;
331
332    if "GET" != "GET" && "GET" != "HEAD" {
333      let headers = local_var_resp.headers();
334      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
335          Some(v) => v.to_str().unwrap().parse().unwrap(),
336          None => configuration::DEFAULT_RATELIMIT,
337      };
338      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
339          Some(v) => v.to_str().unwrap().parse().unwrap(),
340          None => 0,
341      };
342    }
343
344    let local_var_status = local_var_resp.status();
345    let local_var_content = local_var_resp.text().await?;
346
347    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
348        serde_json::from_str(&local_var_content).map_err(Error::from)
349    } else {
350        let local_var_entity: Option<GetServicesProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
351        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
352        Err(Error::ResponseError(local_var_error))
353    }
354}
355
356/// Update configuration of the DDoS Protection product on a service.
357pub async fn set_product_ddos_protection_configuration(configuration: &mut configuration::Configuration, params: SetProductDdosProtectionConfigurationParams) -> Result<crate::models::DdosProtectionResponseConfigure, Error<SetProductDdosProtectionConfigurationError>> {
358    let local_var_configuration = configuration;
359
360    // unbox the parameters
361    let service_id = params.service_id;
362    let ddos_protection_request_update_configuration = params.ddos_protection_request_update_configuration;
363
364
365    let local_var_client = &local_var_configuration.client;
366
367    let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}/configuration", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
368    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
369
370    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
371        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
372    }
373    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
374        let local_var_key = local_var_apikey.key.clone();
375        let local_var_value = match local_var_apikey.prefix {
376            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
377            None => local_var_key,
378        };
379        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
380    };
381    local_var_req_builder = local_var_req_builder.json(&ddos_protection_request_update_configuration);
382
383    let local_var_req = local_var_req_builder.build()?;
384    let local_var_resp = local_var_client.execute(local_var_req).await?;
385
386    if "PATCH" != "GET" && "PATCH" != "HEAD" {
387      let headers = local_var_resp.headers();
388      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
389          Some(v) => v.to_str().unwrap().parse().unwrap(),
390          None => configuration::DEFAULT_RATELIMIT,
391      };
392      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
393          Some(v) => v.to_str().unwrap().parse().unwrap(),
394          None => 0,
395      };
396    }
397
398    let local_var_status = local_var_resp.status();
399    let local_var_content = local_var_resp.text().await?;
400
401    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
402        serde_json::from_str(&local_var_content).map_err(Error::from)
403    } else {
404        let local_var_entity: Option<SetProductDdosProtectionConfigurationError> = serde_json::from_str(&local_var_content).ok();
405        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
406        Err(Error::ResponseError(local_var_error))
407    }
408}
409