fastly_api/apis/
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 [`ddos_protection_event_get`]
15#[derive(Clone, Debug, Default)]
16pub struct DdosProtectionEventGetParams {
17    /// Unique ID of the event.
18    pub event_id: String
19}
20
21/// struct for passing parameters to the method [`ddos_protection_event_list`]
22#[derive(Clone, Debug, Default)]
23pub struct DdosProtectionEventListParams {
24    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
25    pub cursor: Option<String>,
26    /// Limit how many results are returned.
27    pub limit: Option<i32>,
28    /// Filter results based on a service_id.
29    pub service_id: Option<String>,
30    /// Represents the start of a date-time range expressed in RFC 3339 format.
31    pub from: Option<String>,
32    /// Represents the end of a date-time range expressed in RFC 3339 format.
33    pub to: Option<String>,
34    pub name: Option<String>
35}
36
37/// struct for passing parameters to the method [`ddos_protection_event_rule_list`]
38#[derive(Clone, Debug, Default)]
39pub struct DdosProtectionEventRuleListParams {
40    /// Unique ID of the event.
41    pub event_id: String,
42    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
43    pub cursor: Option<String>,
44    /// Limit how many results are returned.
45    pub limit: Option<i32>,
46    /// Include relationships. Optional. Comma-separated values.
47    pub include: Option<String>
48}
49
50/// struct for passing parameters to the method [`ddos_protection_rule_get`]
51#[derive(Clone, Debug, Default)]
52pub struct DdosProtectionRuleGetParams {
53    /// Unique ID of the rule.
54    pub rule_id: String
55}
56
57/// struct for passing parameters to the method [`ddos_protection_rule_patch`]
58#[derive(Clone, Debug, Default)]
59pub struct DdosProtectionRulePatchParams {
60    /// Unique ID of the rule.
61    pub rule_id: String,
62    pub ddos_protection_rule_patch: Option<crate::models::DdosProtectionRulePatch>
63}
64
65/// struct for passing parameters to the method [`ddos_protection_traffic_stats_rule_get`]
66#[derive(Clone, Debug, Default)]
67pub struct DdosProtectionTrafficStatsRuleGetParams {
68    /// Unique ID of the event.
69    pub event_id: String,
70    /// Unique ID of the rule.
71    pub rule_id: String
72}
73
74
75/// struct for typed errors of method [`ddos_protection_event_get`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum DdosProtectionEventGetError {
79    Status401(crate::models::DdosProtectionError),
80    Status404(crate::models::DdosProtectionError),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`ddos_protection_event_list`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum DdosProtectionEventListError {
88    Status401(crate::models::DdosProtectionError),
89    Status404(crate::models::DdosProtectionError),
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`ddos_protection_event_rule_list`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum DdosProtectionEventRuleListError {
97    Status401(crate::models::DdosProtectionError),
98    Status404(crate::models::DdosProtectionError),
99    UnknownValue(serde_json::Value),
100}
101
102/// struct for typed errors of method [`ddos_protection_rule_get`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum DdosProtectionRuleGetError {
106    Status401(crate::models::DdosProtectionError),
107    Status404(crate::models::DdosProtectionError),
108    UnknownValue(serde_json::Value),
109}
110
111/// struct for typed errors of method [`ddos_protection_rule_patch`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum DdosProtectionRulePatchError {
115    Status400(crate::models::DdosProtectionError),
116    Status401(crate::models::DdosProtectionError),
117    Status403(crate::models::DdosProtectionError),
118    Status404(crate::models::DdosProtectionError),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`ddos_protection_traffic_stats_rule_get`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum DdosProtectionTrafficStatsRuleGetError {
126    Status401(crate::models::DdosProtectionError),
127    Status404(crate::models::DdosProtectionError),
128    UnknownValue(serde_json::Value),
129}
130
131
132/// Get event by ID.
133pub async fn ddos_protection_event_get(configuration: &mut configuration::Configuration, params: DdosProtectionEventGetParams) -> Result<crate::models::DdosProtectionEvent, Error<DdosProtectionEventGetError>> {
134    let local_var_configuration = configuration;
135
136    // unbox the parameters
137    let event_id = params.event_id;
138
139
140    let local_var_client = &local_var_configuration.client;
141
142    let local_var_uri_str = format!("{}/ddos-protection/v1/events/{event_id}", local_var_configuration.base_path, event_id=crate::apis::urlencode(event_id));
143    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147    }
148    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
149        let local_var_key = local_var_apikey.key.clone();
150        let local_var_value = match local_var_apikey.prefix {
151            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
152            None => local_var_key,
153        };
154        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
155    };
156
157    let local_var_req = local_var_req_builder.build()?;
158    let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160    if "GET" != "GET" && "GET" != "HEAD" {
161      let headers = local_var_resp.headers();
162      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
163          Some(v) => v.to_str().unwrap().parse().unwrap(),
164          None => configuration::DEFAULT_RATELIMIT,
165      };
166      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
167          Some(v) => v.to_str().unwrap().parse().unwrap(),
168          None => 0,
169      };
170    }
171
172    let local_var_status = local_var_resp.status();
173    let local_var_content = local_var_resp.text().await?;
174
175    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176        serde_json::from_str(&local_var_content).map_err(Error::from)
177    } else {
178        let local_var_entity: Option<DdosProtectionEventGetError> = serde_json::from_str(&local_var_content).ok();
179        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180        Err(Error::ResponseError(local_var_error))
181    }
182}
183
184/// Get events.
185pub async fn ddos_protection_event_list(configuration: &mut configuration::Configuration, params: DdosProtectionEventListParams) -> Result<crate::models::InlineResponse2002, Error<DdosProtectionEventListError>> {
186    let local_var_configuration = configuration;
187
188    // unbox the parameters
189    let cursor = params.cursor;
190    let limit = params.limit;
191    let service_id = params.service_id;
192    let from = params.from;
193    let to = params.to;
194    let name = params.name;
195
196
197    let local_var_client = &local_var_configuration.client;
198
199    let local_var_uri_str = format!("{}/ddos-protection/v1/events", local_var_configuration.base_path);
200    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
201
202    if let Some(ref local_var_str) = cursor {
203        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
204    }
205    if let Some(ref local_var_str) = limit {
206        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
207    }
208    if let Some(ref local_var_str) = service_id {
209        local_var_req_builder = local_var_req_builder.query(&[("service_id", &local_var_str.to_string())]);
210    }
211    if let Some(ref local_var_str) = from {
212        local_var_req_builder = local_var_req_builder.query(&[("from", &local_var_str.to_string())]);
213    }
214    if let Some(ref local_var_str) = to {
215        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
216    }
217    if let Some(ref local_var_str) = name {
218        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
219    }
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222    }
223    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
224        let local_var_key = local_var_apikey.key.clone();
225        let local_var_value = match local_var_apikey.prefix {
226            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
227            None => local_var_key,
228        };
229        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
230    };
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    if "GET" != "GET" && "GET" != "HEAD" {
236      let headers = local_var_resp.headers();
237      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
238          Some(v) => v.to_str().unwrap().parse().unwrap(),
239          None => configuration::DEFAULT_RATELIMIT,
240      };
241      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
242          Some(v) => v.to_str().unwrap().parse().unwrap(),
243          None => 0,
244      };
245    }
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        serde_json::from_str(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<DdosProtectionEventListError> = serde_json::from_str(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258
259/// Get all rules for an event.
260pub async fn ddos_protection_event_rule_list(configuration: &mut configuration::Configuration, params: DdosProtectionEventRuleListParams) -> Result<crate::models::InlineResponse2003, Error<DdosProtectionEventRuleListError>> {
261    let local_var_configuration = configuration;
262
263    // unbox the parameters
264    let event_id = params.event_id;
265    let cursor = params.cursor;
266    let limit = params.limit;
267    let include = params.include;
268
269
270    let local_var_client = &local_var_configuration.client;
271
272    let local_var_uri_str = format!("{}/ddos-protection/v1/events/{event_id}/rules", local_var_configuration.base_path, event_id=crate::apis::urlencode(event_id));
273    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
274
275    if let Some(ref local_var_str) = cursor {
276        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
277    }
278    if let Some(ref local_var_str) = limit {
279        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
280    }
281    if let Some(ref local_var_str) = include {
282        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
283    }
284    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
285        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
286    }
287    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
288        let local_var_key = local_var_apikey.key.clone();
289        let local_var_value = match local_var_apikey.prefix {
290            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
291            None => local_var_key,
292        };
293        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
294    };
295
296    let local_var_req = local_var_req_builder.build()?;
297    let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299    if "GET" != "GET" && "GET" != "HEAD" {
300      let headers = local_var_resp.headers();
301      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
302          Some(v) => v.to_str().unwrap().parse().unwrap(),
303          None => configuration::DEFAULT_RATELIMIT,
304      };
305      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
306          Some(v) => v.to_str().unwrap().parse().unwrap(),
307          None => 0,
308      };
309    }
310
311    let local_var_status = local_var_resp.status();
312    let local_var_content = local_var_resp.text().await?;
313
314    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315        serde_json::from_str(&local_var_content).map_err(Error::from)
316    } else {
317        let local_var_entity: Option<DdosProtectionEventRuleListError> = serde_json::from_str(&local_var_content).ok();
318        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
319        Err(Error::ResponseError(local_var_error))
320    }
321}
322
323/// Get a rule by ID.
324pub async fn ddos_protection_rule_get(configuration: &mut configuration::Configuration, params: DdosProtectionRuleGetParams) -> Result<crate::models::DdosProtectionRule, Error<DdosProtectionRuleGetError>> {
325    let local_var_configuration = configuration;
326
327    // unbox the parameters
328    let rule_id = params.rule_id;
329
330
331    let local_var_client = &local_var_configuration.client;
332
333    let local_var_uri_str = format!("{}/ddos-protection/v1/rules/{rule_id}", local_var_configuration.base_path, rule_id=crate::apis::urlencode(rule_id));
334    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
335
336    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
337        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
338    }
339    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
340        let local_var_key = local_var_apikey.key.clone();
341        let local_var_value = match local_var_apikey.prefix {
342            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
343            None => local_var_key,
344        };
345        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
346    };
347
348    let local_var_req = local_var_req_builder.build()?;
349    let local_var_resp = local_var_client.execute(local_var_req).await?;
350
351    if "GET" != "GET" && "GET" != "HEAD" {
352      let headers = local_var_resp.headers();
353      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
354          Some(v) => v.to_str().unwrap().parse().unwrap(),
355          None => configuration::DEFAULT_RATELIMIT,
356      };
357      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
358          Some(v) => v.to_str().unwrap().parse().unwrap(),
359          None => 0,
360      };
361    }
362
363    let local_var_status = local_var_resp.status();
364    let local_var_content = local_var_resp.text().await?;
365
366    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
367        serde_json::from_str(&local_var_content).map_err(Error::from)
368    } else {
369        let local_var_entity: Option<DdosProtectionRuleGetError> = serde_json::from_str(&local_var_content).ok();
370        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
371        Err(Error::ResponseError(local_var_error))
372    }
373}
374
375/// Update rule.
376pub async fn ddos_protection_rule_patch(configuration: &mut configuration::Configuration, params: DdosProtectionRulePatchParams) -> Result<crate::models::DdosProtectionRule, Error<DdosProtectionRulePatchError>> {
377    let local_var_configuration = configuration;
378
379    // unbox the parameters
380    let rule_id = params.rule_id;
381    let ddos_protection_rule_patch = params.ddos_protection_rule_patch;
382
383
384    let local_var_client = &local_var_configuration.client;
385
386    let local_var_uri_str = format!("{}/ddos-protection/v1/rules/{rule_id}", local_var_configuration.base_path, rule_id=crate::apis::urlencode(rule_id));
387    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
388
389    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
390        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
391    }
392    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
393        let local_var_key = local_var_apikey.key.clone();
394        let local_var_value = match local_var_apikey.prefix {
395            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
396            None => local_var_key,
397        };
398        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
399    };
400    local_var_req_builder = local_var_req_builder.json(&ddos_protection_rule_patch);
401
402    let local_var_req = local_var_req_builder.build()?;
403    let local_var_resp = local_var_client.execute(local_var_req).await?;
404
405    if "PATCH" != "GET" && "PATCH" != "HEAD" {
406      let headers = local_var_resp.headers();
407      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
408          Some(v) => v.to_str().unwrap().parse().unwrap(),
409          None => configuration::DEFAULT_RATELIMIT,
410      };
411      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
412          Some(v) => v.to_str().unwrap().parse().unwrap(),
413          None => 0,
414      };
415    }
416
417    let local_var_status = local_var_resp.status();
418    let local_var_content = local_var_resp.text().await?;
419
420    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
421        serde_json::from_str(&local_var_content).map_err(Error::from)
422    } else {
423        let local_var_entity: Option<DdosProtectionRulePatchError> = serde_json::from_str(&local_var_content).ok();
424        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
425        Err(Error::ResponseError(local_var_error))
426    }
427}
428
429/// Get traffic stats for a rule.
430pub async fn ddos_protection_traffic_stats_rule_get(configuration: &mut configuration::Configuration, params: DdosProtectionTrafficStatsRuleGetParams) -> Result<crate::models::DdosProtectionTrafficStats, Error<DdosProtectionTrafficStatsRuleGetError>> {
431    let local_var_configuration = configuration;
432
433    // unbox the parameters
434    let event_id = params.event_id;
435    let rule_id = params.rule_id;
436
437
438    let local_var_client = &local_var_configuration.client;
439
440    let local_var_uri_str = format!("{}/ddos-protection/v1/events/{event_id}/rules/{rule_id}/traffic-stats", local_var_configuration.base_path, event_id=crate::apis::urlencode(event_id), rule_id=crate::apis::urlencode(rule_id));
441    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
442
443    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
444        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
445    }
446    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
447        let local_var_key = local_var_apikey.key.clone();
448        let local_var_value = match local_var_apikey.prefix {
449            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
450            None => local_var_key,
451        };
452        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
453    };
454
455    let local_var_req = local_var_req_builder.build()?;
456    let local_var_resp = local_var_client.execute(local_var_req).await?;
457
458    if "GET" != "GET" && "GET" != "HEAD" {
459      let headers = local_var_resp.headers();
460      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
461          Some(v) => v.to_str().unwrap().parse().unwrap(),
462          None => configuration::DEFAULT_RATELIMIT,
463      };
464      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
465          Some(v) => v.to_str().unwrap().parse().unwrap(),
466          None => 0,
467      };
468    }
469
470    let local_var_status = local_var_resp.status();
471    let local_var_content = local_var_resp.text().await?;
472
473    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
474        serde_json::from_str(&local_var_content).map_err(Error::from)
475    } else {
476        let local_var_entity: Option<DdosProtectionTrafficStatsRuleGetError> = serde_json::from_str(&local_var_content).ok();
477        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
478        Err(Error::ResponseError(local_var_error))
479    }
480}
481