Skip to main content

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