fastly_api/apis/
legacy_waf_owasp_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_owasp_settings`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateOwaspSettingsParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Alphanumeric string identifying a Firewall.
20    pub firewall_id: String,
21    pub request_body: Option<::std::collections::HashMap<String, serde_json::Value>>
22}
23
24/// struct for passing parameters to the method [`get_owasp_settings`]
25#[derive(Clone, Debug, Default)]
26pub struct GetOwaspSettingsParams {
27    /// Alphanumeric string identifying the service.
28    pub service_id: String,
29    /// Alphanumeric string identifying a Firewall.
30    pub firewall_id: String
31}
32
33/// struct for passing parameters to the method [`update_owasp_settings`]
34#[derive(Clone, Debug, Default)]
35pub struct UpdateOwaspSettingsParams {
36    /// Alphanumeric string identifying the service.
37    pub service_id: String,
38    /// Alphanumeric string identifying a Firewall.
39    pub firewall_id: String,
40    pub request_body: Option<::std::collections::HashMap<String, serde_json::Value>>
41}
42
43
44/// struct for typed errors of method [`create_owasp_settings`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum CreateOwaspSettingsError {
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`get_owasp_settings`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetOwaspSettingsError {
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`update_owasp_settings`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdateOwaspSettingsError {
62    UnknownValue(serde_json::Value),
63}
64
65
66/// Create an OWASP settings object for a particular service and firewall.
67pub async fn create_owasp_settings(configuration: &mut configuration::Configuration, params: CreateOwaspSettingsParams) -> Result<serde_json::Value, Error<CreateOwaspSettingsError>> {
68    let local_var_configuration = configuration;
69
70    // unbox the parameters
71    let service_id = params.service_id;
72    let firewall_id = params.firewall_id;
73    let request_body = params.request_body;
74
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/service/{service_id}/wafs/{firewall_id}/owasp", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), firewall_id=crate::apis::urlencode(firewall_id));
79    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
80
81    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
82        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
85        let local_var_key = local_var_apikey.key.clone();
86        let local_var_value = match local_var_apikey.prefix {
87            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
88            None => local_var_key,
89        };
90        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
91    };
92    local_var_req_builder = local_var_req_builder.json(&request_body);
93
94    let local_var_req = local_var_req_builder.build()?;
95    let local_var_resp = local_var_client.execute(local_var_req).await?;
96
97    if "POST" != "GET" && "POST" != "HEAD" {
98      let headers = local_var_resp.headers();
99      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
100          Some(v) => v.to_str().unwrap().parse().unwrap(),
101          None => configuration::DEFAULT_RATELIMIT,
102      };
103      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
104          Some(v) => v.to_str().unwrap().parse().unwrap(),
105          None => 0,
106      };
107    }
108
109    let local_var_status = local_var_resp.status();
110    let local_var_content = local_var_resp.text().await?;
111
112    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113        serde_json::from_str(&local_var_content).map_err(Error::from)
114    } else {
115        let local_var_entity: Option<CreateOwaspSettingsError> = serde_json::from_str(&local_var_content).ok();
116        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117        Err(Error::ResponseError(local_var_error))
118    }
119}
120
121/// Get the OWASP settings object for a particular service and firewall.
122pub async fn get_owasp_settings(configuration: &mut configuration::Configuration, params: GetOwaspSettingsParams) -> Result<serde_json::Value, Error<GetOwaspSettingsError>> {
123    let local_var_configuration = configuration;
124
125    // unbox the parameters
126    let service_id = params.service_id;
127    let firewall_id = params.firewall_id;
128
129
130    let local_var_client = &local_var_configuration.client;
131
132    let local_var_uri_str = format!("{}/service/{service_id}/wafs/{firewall_id}/owasp", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), firewall_id=crate::apis::urlencode(firewall_id));
133    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
134
135    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
139        let local_var_key = local_var_apikey.key.clone();
140        let local_var_value = match local_var_apikey.prefix {
141            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
142            None => local_var_key,
143        };
144        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
145    };
146
147    let local_var_req = local_var_req_builder.build()?;
148    let local_var_resp = local_var_client.execute(local_var_req).await?;
149
150    if "GET" != "GET" && "GET" != "HEAD" {
151      let headers = local_var_resp.headers();
152      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
153          Some(v) => v.to_str().unwrap().parse().unwrap(),
154          None => configuration::DEFAULT_RATELIMIT,
155      };
156      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
157          Some(v) => v.to_str().unwrap().parse().unwrap(),
158          None => 0,
159      };
160    }
161
162    let local_var_status = local_var_resp.status();
163    let local_var_content = local_var_resp.text().await?;
164
165    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166        serde_json::from_str(&local_var_content).map_err(Error::from)
167    } else {
168        let local_var_entity: Option<GetOwaspSettingsError> = serde_json::from_str(&local_var_content).ok();
169        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
170        Err(Error::ResponseError(local_var_error))
171    }
172}
173
174/// Update the OWASP settings object for a particular service and firewall.
175pub async fn update_owasp_settings(configuration: &mut configuration::Configuration, params: UpdateOwaspSettingsParams) -> Result<serde_json::Value, Error<UpdateOwaspSettingsError>> {
176    let local_var_configuration = configuration;
177
178    // unbox the parameters
179    let service_id = params.service_id;
180    let firewall_id = params.firewall_id;
181    let request_body = params.request_body;
182
183
184    let local_var_client = &local_var_configuration.client;
185
186    let local_var_uri_str = format!("{}/service/{service_id}/wafs/{firewall_id}/owasp", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), firewall_id=crate::apis::urlencode(firewall_id));
187    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
188
189    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
190        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191    }
192    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
193        let local_var_key = local_var_apikey.key.clone();
194        let local_var_value = match local_var_apikey.prefix {
195            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
196            None => local_var_key,
197        };
198        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
199    };
200    local_var_req_builder = local_var_req_builder.json(&request_body);
201
202    let local_var_req = local_var_req_builder.build()?;
203    let local_var_resp = local_var_client.execute(local_var_req).await?;
204
205    if "PATCH" != "GET" && "PATCH" != "HEAD" {
206      let headers = local_var_resp.headers();
207      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
208          Some(v) => v.to_str().unwrap().parse().unwrap(),
209          None => configuration::DEFAULT_RATELIMIT,
210      };
211      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
212          Some(v) => v.to_str().unwrap().parse().unwrap(),
213          None => 0,
214      };
215    }
216
217    let local_var_status = local_var_resp.status();
218    let local_var_content = local_var_resp.text().await?;
219
220    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221        serde_json::from_str(&local_var_content).map_err(Error::from)
222    } else {
223        let local_var_entity: Option<UpdateOwaspSettingsError> = serde_json::from_str(&local_var_content).ok();
224        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
225        Err(Error::ResponseError(local_var_error))
226    }
227}
228