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