fastly_api/apis/
waf_firewalls_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_firewall`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateWafFirewallParams {
17    pub waf_firewall: Option<crate::models::WafFirewall>
18}
19
20/// struct for passing parameters to the method [`delete_waf_firewall`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteWafFirewallParams {
23    /// Alphanumeric string identifying a WAF Firewall.
24    pub firewall_id: String,
25    pub waf_firewall: Option<crate::models::WafFirewall>
26}
27
28/// struct for passing parameters to the method [`get_waf_firewall`]
29#[derive(Clone, Debug, Default)]
30pub struct GetWafFirewallParams {
31    /// Alphanumeric string identifying a WAF Firewall.
32    pub firewall_id: String,
33    /// Limit the results returned to a specific service version.
34    pub filter_service_version_number: Option<String>,
35    /// Include related objects. Optional.
36    pub include: Option<String>
37}
38
39/// struct for passing parameters to the method [`list_waf_firewalls`]
40#[derive(Clone, Debug, Default)]
41pub struct ListWafFirewallsParams {
42    /// Current page.
43    pub page_number: Option<i32>,
44    /// Number of records per page.
45    pub page_size: Option<i32>,
46    /// Limit the results returned to a specific service.
47    pub filter_service_id: Option<String>,
48    /// Limit the results returned to a specific service version.
49    pub filter_service_version_number: Option<String>,
50    /// Include related objects. Optional.
51    pub include: Option<String>
52}
53
54/// struct for passing parameters to the method [`update_waf_firewall`]
55#[derive(Clone, Debug, Default)]
56pub struct UpdateWafFirewallParams {
57    /// Alphanumeric string identifying a WAF Firewall.
58    pub firewall_id: String,
59    pub waf_firewall: Option<crate::models::WafFirewall>
60}
61
62
63/// struct for typed errors of method [`create_waf_firewall`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum CreateWafFirewallError {
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`delete_waf_firewall`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum DeleteWafFirewallError {
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`get_waf_firewall`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum GetWafFirewallError {
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`list_waf_firewalls`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum ListWafFirewallsError {
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`update_waf_firewall`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum UpdateWafFirewallError {
95    UnknownValue(serde_json::Value),
96}
97
98
99/// Create a firewall object for a particular service and service version using a defined `prefetch_condition` and `response`. If the `prefetch_condition` or the `response` is missing from the request body, Fastly will generate a default object on your service. 
100pub async fn create_waf_firewall(configuration: &mut configuration::Configuration, params: CreateWafFirewallParams) -> Result<crate::models::WafFirewallResponse, Error<CreateWafFirewallError>> {
101    let local_var_configuration = configuration;
102
103    // unbox the parameters
104    let waf_firewall = params.waf_firewall;
105
106
107    let local_var_client = &local_var_configuration.client;
108
109    let local_var_uri_str = format!("{}/waf/firewalls", local_var_configuration.base_path);
110    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
111
112    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
113        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
114    }
115    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
116        let local_var_key = local_var_apikey.key.clone();
117        let local_var_value = match local_var_apikey.prefix {
118            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
119            None => local_var_key,
120        };
121        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
122    };
123    local_var_req_builder = local_var_req_builder.json(&waf_firewall);
124
125    let local_var_req = local_var_req_builder.build()?;
126    let local_var_resp = local_var_client.execute(local_var_req).await?;
127
128    if "POST" != "GET" && "POST" != "HEAD" {
129      let headers = local_var_resp.headers();
130      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
131          Some(v) => v.to_str().unwrap().parse().unwrap(),
132          None => configuration::DEFAULT_RATELIMIT,
133      };
134      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
135          Some(v) => v.to_str().unwrap().parse().unwrap(),
136          None => 0,
137      };
138    }
139
140    let local_var_status = local_var_resp.status();
141    let local_var_content = local_var_resp.text().await?;
142
143    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
144        serde_json::from_str(&local_var_content).map_err(Error::from)
145    } else {
146        let local_var_entity: Option<CreateWafFirewallError> = serde_json::from_str(&local_var_content).ok();
147        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
148        Err(Error::ResponseError(local_var_error))
149    }
150}
151
152/// Delete the firewall object for a particular service and service version. 
153pub async fn delete_waf_firewall(configuration: &mut configuration::Configuration, params: DeleteWafFirewallParams) -> Result<(), Error<DeleteWafFirewallError>> {
154    let local_var_configuration = configuration;
155
156    // unbox the parameters
157    let firewall_id = params.firewall_id;
158    let waf_firewall = params.waf_firewall;
159
160
161    let local_var_client = &local_var_configuration.client;
162
163    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id));
164    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
165
166    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
167        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
170        let local_var_key = local_var_apikey.key.clone();
171        let local_var_value = match local_var_apikey.prefix {
172            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
173            None => local_var_key,
174        };
175        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
176    };
177    local_var_req_builder = local_var_req_builder.json(&waf_firewall);
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    if "DELETE" != "GET" && "DELETE" != "HEAD" {
183      let headers = local_var_resp.headers();
184      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
185          Some(v) => v.to_str().unwrap().parse().unwrap(),
186          None => configuration::DEFAULT_RATELIMIT,
187      };
188      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
189          Some(v) => v.to_str().unwrap().parse().unwrap(),
190          None => 0,
191      };
192    }
193
194    let local_var_status = local_var_resp.status();
195    let local_var_content = local_var_resp.text().await?;
196
197    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198        Ok(())
199    } else {
200        let local_var_entity: Option<DeleteWafFirewallError> = serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
202        Err(Error::ResponseError(local_var_error))
203    }
204}
205
206/// Get a specific firewall object.
207pub async fn get_waf_firewall(configuration: &mut configuration::Configuration, params: GetWafFirewallParams) -> Result<crate::models::WafFirewallResponse, Error<GetWafFirewallError>> {
208    let local_var_configuration = configuration;
209
210    // unbox the parameters
211    let firewall_id = params.firewall_id;
212    let filter_service_version_number = params.filter_service_version_number;
213    let include = params.include;
214
215
216    let local_var_client = &local_var_configuration.client;
217
218    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id));
219    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
220
221    if let Some(ref local_var_str) = filter_service_version_number {
222        local_var_req_builder = local_var_req_builder.query(&[("filter[service_version_number]", &local_var_str.to_string())]);
223    }
224    if let Some(ref local_var_str) = include {
225        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
226    }
227    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
228        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229    }
230    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
231        let local_var_key = local_var_apikey.key.clone();
232        let local_var_value = match local_var_apikey.prefix {
233            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
234            None => local_var_key,
235        };
236        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
237    };
238
239    let local_var_req = local_var_req_builder.build()?;
240    let local_var_resp = local_var_client.execute(local_var_req).await?;
241
242    if "GET" != "GET" && "GET" != "HEAD" {
243      let headers = local_var_resp.headers();
244      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
245          Some(v) => v.to_str().unwrap().parse().unwrap(),
246          None => configuration::DEFAULT_RATELIMIT,
247      };
248      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
249          Some(v) => v.to_str().unwrap().parse().unwrap(),
250          None => 0,
251      };
252    }
253
254    let local_var_status = local_var_resp.status();
255    let local_var_content = local_var_resp.text().await?;
256
257    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
258        serde_json::from_str(&local_var_content).map_err(Error::from)
259    } else {
260        let local_var_entity: Option<GetWafFirewallError> = serde_json::from_str(&local_var_content).ok();
261        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
262        Err(Error::ResponseError(local_var_error))
263    }
264}
265
266/// List all firewall objects.
267pub async fn list_waf_firewalls(configuration: &mut configuration::Configuration, params: ListWafFirewallsParams) -> Result<crate::models::WafFirewallsResponse, Error<ListWafFirewallsError>> {
268    let local_var_configuration = configuration;
269
270    // unbox the parameters
271    let page_number = params.page_number;
272    let page_size = params.page_size;
273    let filter_service_id = params.filter_service_id;
274    let filter_service_version_number = params.filter_service_version_number;
275    let include = params.include;
276
277
278    let local_var_client = &local_var_configuration.client;
279
280    let local_var_uri_str = format!("{}/waf/firewalls", local_var_configuration.base_path);
281    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
282
283    if let Some(ref local_var_str) = page_number {
284        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
285    }
286    if let Some(ref local_var_str) = page_size {
287        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
288    }
289    if let Some(ref local_var_str) = filter_service_id {
290        local_var_req_builder = local_var_req_builder.query(&[("filter[service_id]", &local_var_str.to_string())]);
291    }
292    if let Some(ref local_var_str) = filter_service_version_number {
293        local_var_req_builder = local_var_req_builder.query(&[("filter[service_version_number]", &local_var_str.to_string())]);
294    }
295    if let Some(ref local_var_str) = include {
296        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
297    }
298    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
299        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
300    }
301    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
302        let local_var_key = local_var_apikey.key.clone();
303        let local_var_value = match local_var_apikey.prefix {
304            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
305            None => local_var_key,
306        };
307        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
308    };
309
310    let local_var_req = local_var_req_builder.build()?;
311    let local_var_resp = local_var_client.execute(local_var_req).await?;
312
313    if "GET" != "GET" && "GET" != "HEAD" {
314      let headers = local_var_resp.headers();
315      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
316          Some(v) => v.to_str().unwrap().parse().unwrap(),
317          None => configuration::DEFAULT_RATELIMIT,
318      };
319      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
320          Some(v) => v.to_str().unwrap().parse().unwrap(),
321          None => 0,
322      };
323    }
324
325    let local_var_status = local_var_resp.status();
326    let local_var_content = local_var_resp.text().await?;
327
328    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
329        serde_json::from_str(&local_var_content).map_err(Error::from)
330    } else {
331        let local_var_entity: Option<ListWafFirewallsError> = serde_json::from_str(&local_var_content).ok();
332        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
333        Err(Error::ResponseError(local_var_error))
334    }
335}
336
337/// Update a firewall object for a particular service and service version. Specifying a `service_version_number` is required. 
338pub async fn update_waf_firewall(configuration: &mut configuration::Configuration, params: UpdateWafFirewallParams) -> Result<crate::models::WafFirewallResponse, Error<UpdateWafFirewallError>> {
339    let local_var_configuration = configuration;
340
341    // unbox the parameters
342    let firewall_id = params.firewall_id;
343    let waf_firewall = params.waf_firewall;
344
345
346    let local_var_client = &local_var_configuration.client;
347
348    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id));
349    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
350
351    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
352        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
353    }
354    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
355        let local_var_key = local_var_apikey.key.clone();
356        let local_var_value = match local_var_apikey.prefix {
357            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
358            None => local_var_key,
359        };
360        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
361    };
362    local_var_req_builder = local_var_req_builder.json(&waf_firewall);
363
364    let local_var_req = local_var_req_builder.build()?;
365    let local_var_resp = local_var_client.execute(local_var_req).await?;
366
367    if "PATCH" != "GET" && "PATCH" != "HEAD" {
368      let headers = local_var_resp.headers();
369      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
370          Some(v) => v.to_str().unwrap().parse().unwrap(),
371          None => configuration::DEFAULT_RATELIMIT,
372      };
373      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
374          Some(v) => v.to_str().unwrap().parse().unwrap(),
375          None => 0,
376      };
377    }
378
379    let local_var_status = local_var_resp.status();
380    let local_var_content = local_var_resp.text().await?;
381
382    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
383        serde_json::from_str(&local_var_content).map_err(Error::from)
384    } else {
385        let local_var_entity: Option<UpdateWafFirewallError> = serde_json::from_str(&local_var_content).ok();
386        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
387        Err(Error::ResponseError(local_var_error))
388    }
389}
390