fastly_api/apis/
waf_exclusions_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_waf_rule_exclusion`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateWafRuleExclusionParams {
17    /// Alphanumeric string identifying a WAF Firewall.
18    pub firewall_id: String,
19    /// Integer identifying a WAF firewall version.
20    pub firewall_version_number: i32,
21    pub waf_exclusion: Option<crate::models::WafExclusion>
22}
23
24/// struct for passing parameters to the method [`delete_waf_rule_exclusion`]
25#[derive(Clone, Debug, Default)]
26pub struct DeleteWafRuleExclusionParams {
27    /// Alphanumeric string identifying a WAF Firewall.
28    pub firewall_id: String,
29    /// Integer identifying a WAF firewall version.
30    pub firewall_version_number: i32,
31    /// A numeric ID identifying a WAF exclusion.
32    pub exclusion_number: i32
33}
34
35/// struct for passing parameters to the method [`get_waf_rule_exclusion`]
36#[derive(Clone, Debug, Default)]
37pub struct GetWafRuleExclusionParams {
38    /// Alphanumeric string identifying a WAF Firewall.
39    pub firewall_id: String,
40    /// Integer identifying a WAF firewall version.
41    pub firewall_version_number: i32,
42    /// A numeric ID identifying a WAF exclusion.
43    pub exclusion_number: i32
44}
45
46/// struct for passing parameters to the method [`list_waf_rule_exclusions`]
47#[derive(Clone, Debug, Default)]
48pub struct ListWafRuleExclusionsParams {
49    /// Alphanumeric string identifying a WAF Firewall.
50    pub firewall_id: String,
51    /// Integer identifying a WAF firewall version.
52    pub firewall_version_number: i32,
53    /// Filters the results based on this exclusion type.
54    pub filter_exclusion_type: Option<String>,
55    /// Filters the results based on name.
56    pub filter_name: Option<String>,
57    /// Filters the results based on this ModSecurity rule ID.
58    pub filter_waf_rules_modsec_rule_id: Option<i32>,
59    /// Current page.
60    pub page_number: Option<i32>,
61    /// Number of records per page.
62    pub page_size: Option<i32>,
63    /// Include relationships. Optional, comma-separated values. Permitted values: `waf_rules` and `waf_rule_revisions`. 
64    pub include: Option<String>
65}
66
67/// struct for passing parameters to the method [`update_waf_rule_exclusion`]
68#[derive(Clone, Debug, Default)]
69pub struct UpdateWafRuleExclusionParams {
70    /// Alphanumeric string identifying a WAF Firewall.
71    pub firewall_id: String,
72    /// Integer identifying a WAF firewall version.
73    pub firewall_version_number: i32,
74    /// A numeric ID identifying a WAF exclusion.
75    pub exclusion_number: i32,
76    pub waf_exclusion: Option<crate::models::WafExclusion>
77}
78
79
80/// struct for typed errors of method [`create_waf_rule_exclusion`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum CreateWafRuleExclusionError {
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`delete_waf_rule_exclusion`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum DeleteWafRuleExclusionError {
91    UnknownValue(serde_json::Value),
92}
93
94/// struct for typed errors of method [`get_waf_rule_exclusion`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum GetWafRuleExclusionError {
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`list_waf_rule_exclusions`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum ListWafRuleExclusionsError {
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`update_waf_rule_exclusion`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum UpdateWafRuleExclusionError {
112    UnknownValue(serde_json::Value),
113}
114
115
116/// Create a WAF exclusion for a particular firewall version.
117pub async fn create_waf_rule_exclusion(configuration: &mut configuration::Configuration, params: CreateWafRuleExclusionParams) -> Result<crate::models::WafExclusionResponse, Error<CreateWafRuleExclusionError>> {
118    let local_var_configuration = configuration;
119
120    // unbox the parameters
121    let firewall_id = params.firewall_id;
122    let firewall_version_number = params.firewall_version_number;
123    let waf_exclusion = params.waf_exclusion;
124
125
126    let local_var_client = &local_var_configuration.client;
127
128    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/exclusions", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
129    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
130
131    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133    }
134    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
135        let local_var_key = local_var_apikey.key.clone();
136        let local_var_value = match local_var_apikey.prefix {
137            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
138            None => local_var_key,
139        };
140        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
141    };
142    local_var_req_builder = local_var_req_builder.json(&waf_exclusion);
143
144    let local_var_req = local_var_req_builder.build()?;
145    let local_var_resp = local_var_client.execute(local_var_req).await?;
146
147    if "POST" != "GET" && "POST" != "HEAD" {
148      let headers = local_var_resp.headers();
149      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
150          Some(v) => v.to_str().unwrap().parse().unwrap(),
151          None => configuration::DEFAULT_RATELIMIT,
152      };
153      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
154          Some(v) => v.to_str().unwrap().parse().unwrap(),
155          None => 0,
156      };
157    }
158
159    let local_var_status = local_var_resp.status();
160    let local_var_content = local_var_resp.text().await?;
161
162    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163        serde_json::from_str(&local_var_content).map_err(Error::from)
164    } else {
165        let local_var_entity: Option<CreateWafRuleExclusionError> = serde_json::from_str(&local_var_content).ok();
166        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
167        Err(Error::ResponseError(local_var_error))
168    }
169}
170
171/// Delete a WAF exclusion for a particular firewall version.
172pub async fn delete_waf_rule_exclusion(configuration: &mut configuration::Configuration, params: DeleteWafRuleExclusionParams) -> Result<(), Error<DeleteWafRuleExclusionError>> {
173    let local_var_configuration = configuration;
174
175    // unbox the parameters
176    let firewall_id = params.firewall_id;
177    let firewall_version_number = params.firewall_version_number;
178    let exclusion_number = params.exclusion_number;
179
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/exclusions/{exclusion_number}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number, exclusion_number=exclusion_number);
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
190        let local_var_key = local_var_apikey.key.clone();
191        let local_var_value = match local_var_apikey.prefix {
192            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
193            None => local_var_key,
194        };
195        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
196    };
197
198    let local_var_req = local_var_req_builder.build()?;
199    let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201    if "DELETE" != "GET" && "DELETE" != "HEAD" {
202      let headers = local_var_resp.headers();
203      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
204          Some(v) => v.to_str().unwrap().parse().unwrap(),
205          None => configuration::DEFAULT_RATELIMIT,
206      };
207      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
208          Some(v) => v.to_str().unwrap().parse().unwrap(),
209          None => 0,
210      };
211    }
212
213    let local_var_status = local_var_resp.status();
214    let local_var_content = local_var_resp.text().await?;
215
216    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217        Ok(())
218    } else {
219        let local_var_entity: Option<DeleteWafRuleExclusionError> = serde_json::from_str(&local_var_content).ok();
220        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
221        Err(Error::ResponseError(local_var_error))
222    }
223}
224
225/// Get a specific WAF exclusion object.
226pub async fn get_waf_rule_exclusion(configuration: &mut configuration::Configuration, params: GetWafRuleExclusionParams) -> Result<crate::models::WafExclusionResponse, Error<GetWafRuleExclusionError>> {
227    let local_var_configuration = configuration;
228
229    // unbox the parameters
230    let firewall_id = params.firewall_id;
231    let firewall_version_number = params.firewall_version_number;
232    let exclusion_number = params.exclusion_number;
233
234
235    let local_var_client = &local_var_configuration.client;
236
237    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/exclusions/{exclusion_number}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number, exclusion_number=exclusion_number);
238    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
239
240    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
241        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242    }
243    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
244        let local_var_key = local_var_apikey.key.clone();
245        let local_var_value = match local_var_apikey.prefix {
246            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
247            None => local_var_key,
248        };
249        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
250    };
251
252    let local_var_req = local_var_req_builder.build()?;
253    let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255    if "GET" != "GET" && "GET" != "HEAD" {
256      let headers = local_var_resp.headers();
257      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
258          Some(v) => v.to_str().unwrap().parse().unwrap(),
259          None => configuration::DEFAULT_RATELIMIT,
260      };
261      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
262          Some(v) => v.to_str().unwrap().parse().unwrap(),
263          None => 0,
264      };
265    }
266
267    let local_var_status = local_var_resp.status();
268    let local_var_content = local_var_resp.text().await?;
269
270    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
271        serde_json::from_str(&local_var_content).map_err(Error::from)
272    } else {
273        let local_var_entity: Option<GetWafRuleExclusionError> = serde_json::from_str(&local_var_content).ok();
274        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
275        Err(Error::ResponseError(local_var_error))
276    }
277}
278
279/// List all exclusions for a particular firewall version.
280pub async fn list_waf_rule_exclusions(configuration: &mut configuration::Configuration, params: ListWafRuleExclusionsParams) -> Result<crate::models::WafExclusionsResponse, Error<ListWafRuleExclusionsError>> {
281    let local_var_configuration = configuration;
282
283    // unbox the parameters
284    let firewall_id = params.firewall_id;
285    let firewall_version_number = params.firewall_version_number;
286    let filter_exclusion_type = params.filter_exclusion_type;
287    let filter_name = params.filter_name;
288    let filter_waf_rules_modsec_rule_id = params.filter_waf_rules_modsec_rule_id;
289    let page_number = params.page_number;
290    let page_size = params.page_size;
291    let include = params.include;
292
293
294    let local_var_client = &local_var_configuration.client;
295
296    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/exclusions", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
297    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
298
299    if let Some(ref local_var_str) = filter_exclusion_type {
300        local_var_req_builder = local_var_req_builder.query(&[("filter[exclusion_type]", &local_var_str.to_string())]);
301    }
302    if let Some(ref local_var_str) = filter_name {
303        local_var_req_builder = local_var_req_builder.query(&[("filter[name]", &local_var_str.to_string())]);
304    }
305    if let Some(ref local_var_str) = filter_waf_rules_modsec_rule_id {
306        local_var_req_builder = local_var_req_builder.query(&[("filter[waf_rules.modsec_rule_id]", &local_var_str.to_string())]);
307    }
308    if let Some(ref local_var_str) = page_number {
309        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
310    }
311    if let Some(ref local_var_str) = page_size {
312        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
313    }
314    if let Some(ref local_var_str) = include {
315        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
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<ListWafRuleExclusionsError> = 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 a WAF exclusion for a particular firewall version.
357pub async fn update_waf_rule_exclusion(configuration: &mut configuration::Configuration, params: UpdateWafRuleExclusionParams) -> Result<crate::models::WafExclusionResponse, Error<UpdateWafRuleExclusionError>> {
358    let local_var_configuration = configuration;
359
360    // unbox the parameters
361    let firewall_id = params.firewall_id;
362    let firewall_version_number = params.firewall_version_number;
363    let exclusion_number = params.exclusion_number;
364    let waf_exclusion = params.waf_exclusion;
365
366
367    let local_var_client = &local_var_configuration.client;
368
369    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/exclusions/{exclusion_number}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number, exclusion_number=exclusion_number);
370    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
371
372    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
373        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
374    }
375    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
376        let local_var_key = local_var_apikey.key.clone();
377        let local_var_value = match local_var_apikey.prefix {
378            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
379            None => local_var_key,
380        };
381        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
382    };
383    local_var_req_builder = local_var_req_builder.json(&waf_exclusion);
384
385    let local_var_req = local_var_req_builder.build()?;
386    let local_var_resp = local_var_client.execute(local_var_req).await?;
387
388    if "PATCH" != "GET" && "PATCH" != "HEAD" {
389      let headers = local_var_resp.headers();
390      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
391          Some(v) => v.to_str().unwrap().parse().unwrap(),
392          None => configuration::DEFAULT_RATELIMIT,
393      };
394      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
395          Some(v) => v.to_str().unwrap().parse().unwrap(),
396          None => 0,
397      };
398    }
399
400    let local_var_status = local_var_resp.status();
401    let local_var_content = local_var_resp.text().await?;
402
403    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
404        serde_json::from_str(&local_var_content).map_err(Error::from)
405    } else {
406        let local_var_entity: Option<UpdateWafRuleExclusionError> = serde_json::from_str(&local_var_content).ok();
407        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
408        Err(Error::ResponseError(local_var_error))
409    }
410}
411