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