1use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14#[derive(Clone, Debug, Default)]
16pub struct DisableProductDdosProtectionParams {
17 pub service_id: String
19}
20
21#[derive(Clone, Debug, Default)]
23pub struct EnableProductDdosProtectionParams {
24 pub service_id: String,
26 pub ddos_protection_request_enable_mode: Option<crate::models::DdosProtectionRequestEnableMode>
27}
28
29#[derive(Clone, Debug, Default)]
31pub struct GetProductDdosProtectionParams {
32 pub service_id: String
34}
35
36#[derive(Clone, Debug, Default)]
38pub struct GetProductDdosProtectionConfigurationParams {
39 pub service_id: String
41}
42
43#[derive(Clone, Debug, Default)]
45pub struct SetProductDdosProtectionConfigurationParams {
46 pub service_id: String,
48 pub ddos_protection_request_update_configuration: Option<crate::models::DdosProtectionRequestUpdateConfiguration>
49}
50
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DisableProductDdosProtectionError {
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum EnableProductDdosProtectionError {
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetProductDdosProtectionError {
70 UnknownValue(serde_json::Value),
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum GetProductDdosProtectionConfigurationError {
77 UnknownValue(serde_json::Value),
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetServicesProductDdosProtectionError {
84 UnknownValue(serde_json::Value),
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum SetProductDdosProtectionConfigurationError {
91 UnknownValue(serde_json::Value),
92}
93
94
95pub async fn disable_product_ddos_protection(configuration: &mut configuration::Configuration, params: DisableProductDdosProtectionParams) -> Result<(), Error<DisableProductDdosProtectionError>> {
97 let local_var_configuration = configuration;
98
99 let service_id = params.service_id;
101
102
103 let local_var_client = &local_var_configuration.client;
104
105 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
106 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
107
108 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110 }
111 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
112 let local_var_key = local_var_apikey.key.clone();
113 let local_var_value = match local_var_apikey.prefix {
114 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
115 None => local_var_key,
116 };
117 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
118 };
119
120 let local_var_req = local_var_req_builder.build()?;
121 let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123 if "DELETE" != "GET" && "DELETE" != "HEAD" {
124 let headers = local_var_resp.headers();
125 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
126 Some(v) => v.to_str().unwrap().parse().unwrap(),
127 None => configuration::DEFAULT_RATELIMIT,
128 };
129 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
130 Some(v) => v.to_str().unwrap().parse().unwrap(),
131 None => 0,
132 };
133 }
134
135 let local_var_status = local_var_resp.status();
136 let local_var_content = local_var_resp.text().await?;
137
138 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139 Ok(())
140 } else {
141 let local_var_entity: Option<DisableProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
142 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
143 Err(Error::ResponseError(local_var_error))
144 }
145}
146
147pub async fn enable_product_ddos_protection(configuration: &mut configuration::Configuration, params: EnableProductDdosProtectionParams) -> Result<crate::models::DdosProtectionResponseEnable, Error<EnableProductDdosProtectionError>> {
149 let local_var_configuration = configuration;
150
151 let service_id = params.service_id;
153 let ddos_protection_request_enable_mode = params.ddos_protection_request_enable_mode;
154
155
156 let local_var_client = &local_var_configuration.client;
157
158 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
159 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
160
161 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163 }
164 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
165 let local_var_key = local_var_apikey.key.clone();
166 let local_var_value = match local_var_apikey.prefix {
167 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
168 None => local_var_key,
169 };
170 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
171 };
172 local_var_req_builder = local_var_req_builder.json(&ddos_protection_request_enable_mode);
173
174 let local_var_req = local_var_req_builder.build()?;
175 let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177 if "PUT" != "GET" && "PUT" != "HEAD" {
178 let headers = local_var_resp.headers();
179 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
180 Some(v) => v.to_str().unwrap().parse().unwrap(),
181 None => configuration::DEFAULT_RATELIMIT,
182 };
183 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
184 Some(v) => v.to_str().unwrap().parse().unwrap(),
185 None => 0,
186 };
187 }
188
189 let local_var_status = local_var_resp.status();
190 let local_var_content = local_var_resp.text().await?;
191
192 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
193 serde_json::from_str(&local_var_content).map_err(Error::from)
194 } else {
195 let local_var_entity: Option<EnableProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
196 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
197 Err(Error::ResponseError(local_var_error))
198 }
199}
200
201pub async fn get_product_ddos_protection(configuration: &mut configuration::Configuration, params: GetProductDdosProtectionParams) -> Result<crate::models::DdosProtectionResponseEnable, Error<GetProductDdosProtectionError>> {
203 let local_var_configuration = configuration;
204
205 let service_id = params.service_id;
207
208
209 let local_var_client = &local_var_configuration.client;
210
211 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
212 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216 }
217 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
218 let local_var_key = local_var_apikey.key.clone();
219 let local_var_value = match local_var_apikey.prefix {
220 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
221 None => local_var_key,
222 };
223 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
224 };
225
226 let local_var_req = local_var_req_builder.build()?;
227 let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229 if "GET" != "GET" && "GET" != "HEAD" {
230 let headers = local_var_resp.headers();
231 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
232 Some(v) => v.to_str().unwrap().parse().unwrap(),
233 None => configuration::DEFAULT_RATELIMIT,
234 };
235 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
236 Some(v) => v.to_str().unwrap().parse().unwrap(),
237 None => 0,
238 };
239 }
240
241 let local_var_status = local_var_resp.status();
242 let local_var_content = local_var_resp.text().await?;
243
244 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245 serde_json::from_str(&local_var_content).map_err(Error::from)
246 } else {
247 let local_var_entity: Option<GetProductDdosProtectionError> = serde_json::from_str(&local_var_content).ok();
248 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
249 Err(Error::ResponseError(local_var_error))
250 }
251}
252
253pub async fn get_product_ddos_protection_configuration(configuration: &mut configuration::Configuration, params: GetProductDdosProtectionConfigurationParams) -> Result<crate::models::DdosProtectionResponseConfigure, Error<GetProductDdosProtectionConfigurationError>> {
255 let local_var_configuration = configuration;
256
257 let service_id = params.service_id;
259
260
261 let local_var_client = &local_var_configuration.client;
262
263 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}/configuration", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
264 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
265
266 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268 }
269 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
270 let local_var_key = local_var_apikey.key.clone();
271 let local_var_value = match local_var_apikey.prefix {
272 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
273 None => local_var_key,
274 };
275 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
276 };
277
278 let local_var_req = local_var_req_builder.build()?;
279 let local_var_resp = local_var_client.execute(local_var_req).await?;
280
281 if "GET" != "GET" && "GET" != "HEAD" {
282 let headers = local_var_resp.headers();
283 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
284 Some(v) => v.to_str().unwrap().parse().unwrap(),
285 None => configuration::DEFAULT_RATELIMIT,
286 };
287 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
288 Some(v) => v.to_str().unwrap().parse().unwrap(),
289 None => 0,
290 };
291 }
292
293 let local_var_status = local_var_resp.status();
294 let local_var_content = local_var_resp.text().await?;
295
296 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
297 serde_json::from_str(&local_var_content).map_err(Error::from)
298 } else {
299 let local_var_entity: Option<GetProductDdosProtectionConfigurationError> = serde_json::from_str(&local_var_content).ok();
300 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
301 Err(Error::ResponseError(local_var_error))
302 }
303}
304
305pub async fn get_services_product_ddos_protection(configuration: &mut configuration::Configuration) -> Result<crate::models::DdosProtectionResponseBodyGetAllServices, Error<GetServicesProductDdosProtectionError>> {
307 let local_var_configuration = configuration;
308
309 let local_var_client = &local_var_configuration.client;
313
314 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services", local_var_configuration.base_path);
315 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
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<GetServicesProductDdosProtectionError> = 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
356pub async fn set_product_ddos_protection_configuration(configuration: &mut configuration::Configuration, params: SetProductDdosProtectionConfigurationParams) -> Result<crate::models::DdosProtectionResponseConfigure, Error<SetProductDdosProtectionConfigurationError>> {
358 let local_var_configuration = configuration;
359
360 let service_id = params.service_id;
362 let ddos_protection_request_update_configuration = params.ddos_protection_request_update_configuration;
363
364
365 let local_var_client = &local_var_configuration.client;
366
367 let local_var_uri_str = format!("{}/enabled-products/v1/ddos_protection/services/{service_id}/configuration", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
368 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
369
370 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
371 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
372 }
373 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
374 let local_var_key = local_var_apikey.key.clone();
375 let local_var_value = match local_var_apikey.prefix {
376 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
377 None => local_var_key,
378 };
379 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
380 };
381 local_var_req_builder = local_var_req_builder.json(&ddos_protection_request_update_configuration);
382
383 let local_var_req = local_var_req_builder.build()?;
384 let local_var_resp = local_var_client.execute(local_var_req).await?;
385
386 if "PATCH" != "GET" && "PATCH" != "HEAD" {
387 let headers = local_var_resp.headers();
388 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
389 Some(v) => v.to_str().unwrap().parse().unwrap(),
390 None => configuration::DEFAULT_RATELIMIT,
391 };
392 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
393 Some(v) => v.to_str().unwrap().parse().unwrap(),
394 None => 0,
395 };
396 }
397
398 let local_var_status = local_var_resp.status();
399 let local_var_content = local_var_resp.text().await?;
400
401 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
402 serde_json::from_str(&local_var_content).map_err(Error::from)
403 } else {
404 let local_var_entity: Option<SetProductDdosProtectionConfigurationError> = serde_json::from_str(&local_var_content).ok();
405 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
406 Err(Error::ResponseError(local_var_error))
407 }
408}
409