fastly_api/apis/
waf_firewall_versions_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 [`clone_waf_firewall_version`]
15#[derive(Clone, Debug, Default)]
16pub struct CloneWafFirewallVersionParams {
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}
22
23/// struct for passing parameters to the method [`create_waf_firewall_version`]
24#[derive(Clone, Debug, Default)]
25pub struct CreateWafFirewallVersionParams {
26    /// Alphanumeric string identifying a WAF Firewall.
27    pub firewall_id: String,
28    pub waf_firewall_version: Option<crate::models::WafFirewallVersion>
29}
30
31/// struct for passing parameters to the method [`deploy_activate_waf_firewall_version`]
32#[derive(Clone, Debug, Default)]
33pub struct DeployActivateWafFirewallVersionParams {
34    /// Alphanumeric string identifying a WAF Firewall.
35    pub firewall_id: String,
36    /// Integer identifying a WAF firewall version.
37    pub firewall_version_number: i32
38}
39
40/// struct for passing parameters to the method [`get_waf_firewall_version`]
41#[derive(Clone, Debug, Default)]
42pub struct GetWafFirewallVersionParams {
43    /// Alphanumeric string identifying a WAF Firewall.
44    pub firewall_id: String,
45    /// Integer identifying a WAF firewall version.
46    pub firewall_version_number: i32,
47    /// Include relationships. Optional, comma-separated values. Permitted values: `waf_firewall` and `waf_active_rules`. 
48    pub include: Option<String>
49}
50
51/// struct for passing parameters to the method [`list_waf_firewall_versions`]
52#[derive(Clone, Debug, Default)]
53pub struct ListWafFirewallVersionsParams {
54    /// Alphanumeric string identifying a WAF Firewall.
55    pub firewall_id: String,
56    /// Include relationships. Optional.
57    pub include: Option<String>,
58    /// Current page.
59    pub page_number: Option<i32>,
60    /// Number of records per page.
61    pub page_size: Option<i32>
62}
63
64/// struct for passing parameters to the method [`update_waf_firewall_version`]
65#[derive(Clone, Debug, Default)]
66pub struct UpdateWafFirewallVersionParams {
67    /// Alphanumeric string identifying a WAF Firewall.
68    pub firewall_id: String,
69    /// Integer identifying a WAF firewall version.
70    pub firewall_version_number: i32,
71    pub waf_firewall_version: Option<crate::models::WafFirewallVersion>
72}
73
74
75/// struct for typed errors of method [`clone_waf_firewall_version`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum CloneWafFirewallVersionError {
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`create_waf_firewall_version`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateWafFirewallVersionError {
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`deploy_activate_waf_firewall_version`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum DeployActivateWafFirewallVersionError {
93    UnknownValue(serde_json::Value),
94}
95
96/// struct for typed errors of method [`get_waf_firewall_version`]
97#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum GetWafFirewallVersionError {
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`list_waf_firewall_versions`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum ListWafFirewallVersionsError {
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`update_waf_firewall_version`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum UpdateWafFirewallVersionError {
114    UnknownValue(serde_json::Value),
115}
116
117
118/// Clone a specific, existing firewall version into a new, draft firewall version.
119pub async fn clone_waf_firewall_version(configuration: &mut configuration::Configuration, params: CloneWafFirewallVersionParams) -> Result<crate::models::WafFirewallVersionResponse, Error<CloneWafFirewallVersionError>> {
120    let local_var_configuration = configuration;
121
122    // unbox the parameters
123    let firewall_id = params.firewall_id;
124    let firewall_version_number = params.firewall_version_number;
125
126
127    let local_var_client = &local_var_configuration.client;
128
129    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/clone", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
130    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
131
132    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
133        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
134    }
135    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
136        let local_var_key = local_var_apikey.key.clone();
137        let local_var_value = match local_var_apikey.prefix {
138            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
139            None => local_var_key,
140        };
141        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
142    };
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 "PUT" != "GET" && "PUT" != "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<CloneWafFirewallVersionError> = 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/// Create a new, draft firewall version.
172pub async fn create_waf_firewall_version(configuration: &mut configuration::Configuration, params: CreateWafFirewallVersionParams) -> Result<crate::models::WafFirewallVersionResponse, Error<CreateWafFirewallVersionError>> {
173    let local_var_configuration = configuration;
174
175    // unbox the parameters
176    let firewall_id = params.firewall_id;
177    let waf_firewall_version = params.waf_firewall_version;
178
179
180    let local_var_client = &local_var_configuration.client;
181
182    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id));
183    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
184
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
187    }
188    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
189        let local_var_key = local_var_apikey.key.clone();
190        let local_var_value = match local_var_apikey.prefix {
191            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
192            None => local_var_key,
193        };
194        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
195    };
196    local_var_req_builder = local_var_req_builder.json(&waf_firewall_version);
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 "POST" != "GET" && "POST" != "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        serde_json::from_str(&local_var_content).map_err(Error::from)
218    } else {
219        let local_var_entity: Option<CreateWafFirewallVersionError> = 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/// Deploy or activate a specific firewall version. If a firewall has been disabled, deploying a firewall version will automatically enable the firewall again.
226pub async fn deploy_activate_waf_firewall_version(configuration: &mut configuration::Configuration, params: DeployActivateWafFirewallVersionParams) -> Result<serde_json::Value, Error<DeployActivateWafFirewallVersionError>> {
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
233
234    let local_var_client = &local_var_configuration.client;
235
236    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}/activate", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
237    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
238
239    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
240        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
241    }
242    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
243        let local_var_key = local_var_apikey.key.clone();
244        let local_var_value = match local_var_apikey.prefix {
245            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
246            None => local_var_key,
247        };
248        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
249    };
250
251    let local_var_req = local_var_req_builder.build()?;
252    let local_var_resp = local_var_client.execute(local_var_req).await?;
253
254    if "PUT" != "GET" && "PUT" != "HEAD" {
255      let headers = local_var_resp.headers();
256      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
257          Some(v) => v.to_str().unwrap().parse().unwrap(),
258          None => configuration::DEFAULT_RATELIMIT,
259      };
260      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
261          Some(v) => v.to_str().unwrap().parse().unwrap(),
262          None => 0,
263      };
264    }
265
266    let local_var_status = local_var_resp.status();
267    let local_var_content = local_var_resp.text().await?;
268
269    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270        serde_json::from_str(&local_var_content).map_err(Error::from)
271    } else {
272        let local_var_entity: Option<DeployActivateWafFirewallVersionError> = serde_json::from_str(&local_var_content).ok();
273        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
274        Err(Error::ResponseError(local_var_error))
275    }
276}
277
278/// Get details about a specific firewall version.
279pub async fn get_waf_firewall_version(configuration: &mut configuration::Configuration, params: GetWafFirewallVersionParams) -> Result<crate::models::WafFirewallVersionResponse, Error<GetWafFirewallVersionError>> {
280    let local_var_configuration = configuration;
281
282    // unbox the parameters
283    let firewall_id = params.firewall_id;
284    let firewall_version_number = params.firewall_version_number;
285    let include = params.include;
286
287
288    let local_var_client = &local_var_configuration.client;
289
290    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
291    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
292
293    if let Some(ref local_var_str) = include {
294        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
295    }
296    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
297        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
298    }
299    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
300        let local_var_key = local_var_apikey.key.clone();
301        let local_var_value = match local_var_apikey.prefix {
302            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
303            None => local_var_key,
304        };
305        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
306    };
307
308    let local_var_req = local_var_req_builder.build()?;
309    let local_var_resp = local_var_client.execute(local_var_req).await?;
310
311    if "GET" != "GET" && "GET" != "HEAD" {
312      let headers = local_var_resp.headers();
313      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
314          Some(v) => v.to_str().unwrap().parse().unwrap(),
315          None => configuration::DEFAULT_RATELIMIT,
316      };
317      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
318          Some(v) => v.to_str().unwrap().parse().unwrap(),
319          None => 0,
320      };
321    }
322
323    let local_var_status = local_var_resp.status();
324    let local_var_content = local_var_resp.text().await?;
325
326    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
327        serde_json::from_str(&local_var_content).map_err(Error::from)
328    } else {
329        let local_var_entity: Option<GetWafFirewallVersionError> = serde_json::from_str(&local_var_content).ok();
330        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
331        Err(Error::ResponseError(local_var_error))
332    }
333}
334
335/// Get a list of firewall versions associated with a specific firewall.
336pub async fn list_waf_firewall_versions(configuration: &mut configuration::Configuration, params: ListWafFirewallVersionsParams) -> Result<crate::models::WafFirewallVersionsResponse, Error<ListWafFirewallVersionsError>> {
337    let local_var_configuration = configuration;
338
339    // unbox the parameters
340    let firewall_id = params.firewall_id;
341    let include = params.include;
342    let page_number = params.page_number;
343    let page_size = params.page_size;
344
345
346    let local_var_client = &local_var_configuration.client;
347
348    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions", 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::GET, local_var_uri_str.as_str());
350
351    if let Some(ref local_var_str) = include {
352        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
353    }
354    if let Some(ref local_var_str) = page_number {
355        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
356    }
357    if let Some(ref local_var_str) = page_size {
358        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
359    }
360    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
361        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
362    }
363    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
364        let local_var_key = local_var_apikey.key.clone();
365        let local_var_value = match local_var_apikey.prefix {
366            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
367            None => local_var_key,
368        };
369        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
370    };
371
372    let local_var_req = local_var_req_builder.build()?;
373    let local_var_resp = local_var_client.execute(local_var_req).await?;
374
375    if "GET" != "GET" && "GET" != "HEAD" {
376      let headers = local_var_resp.headers();
377      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
378          Some(v) => v.to_str().unwrap().parse().unwrap(),
379          None => configuration::DEFAULT_RATELIMIT,
380      };
381      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
382          Some(v) => v.to_str().unwrap().parse().unwrap(),
383          None => 0,
384      };
385    }
386
387    let local_var_status = local_var_resp.status();
388    let local_var_content = local_var_resp.text().await?;
389
390    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
391        serde_json::from_str(&local_var_content).map_err(Error::from)
392    } else {
393        let local_var_entity: Option<ListWafFirewallVersionsError> = serde_json::from_str(&local_var_content).ok();
394        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
395        Err(Error::ResponseError(local_var_error))
396    }
397}
398
399/// Update a specific firewall version.
400pub async fn update_waf_firewall_version(configuration: &mut configuration::Configuration, params: UpdateWafFirewallVersionParams) -> Result<crate::models::WafFirewallVersionResponse, Error<UpdateWafFirewallVersionError>> {
401    let local_var_configuration = configuration;
402
403    // unbox the parameters
404    let firewall_id = params.firewall_id;
405    let firewall_version_number = params.firewall_version_number;
406    let waf_firewall_version = params.waf_firewall_version;
407
408
409    let local_var_client = &local_var_configuration.client;
410
411    let local_var_uri_str = format!("{}/waf/firewalls/{firewall_id}/versions/{firewall_version_number}", local_var_configuration.base_path, firewall_id=crate::apis::urlencode(firewall_id), firewall_version_number=firewall_version_number);
412    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
413
414    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
415        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
416    }
417    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
418        let local_var_key = local_var_apikey.key.clone();
419        let local_var_value = match local_var_apikey.prefix {
420            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
421            None => local_var_key,
422        };
423        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
424    };
425    local_var_req_builder = local_var_req_builder.json(&waf_firewall_version);
426
427    let local_var_req = local_var_req_builder.build()?;
428    let local_var_resp = local_var_client.execute(local_var_req).await?;
429
430    if "PATCH" != "GET" && "PATCH" != "HEAD" {
431      let headers = local_var_resp.headers();
432      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
433          Some(v) => v.to_str().unwrap().parse().unwrap(),
434          None => configuration::DEFAULT_RATELIMIT,
435      };
436      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
437          Some(v) => v.to_str().unwrap().parse().unwrap(),
438          None => 0,
439      };
440    }
441
442    let local_var_status = local_var_resp.status();
443    let local_var_content = local_var_resp.text().await?;
444
445    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
446        serde_json::from_str(&local_var_content).map_err(Error::from)
447    } else {
448        let local_var_entity: Option<UpdateWafFirewallVersionError> = serde_json::from_str(&local_var_content).ok();
449        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
450        Err(Error::ResponseError(local_var_error))
451    }
452}
453