fastly_api/apis/
acl_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_acl`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateAclParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// Name for the ACL. Must start with an alphanumeric character and contain only alphanumeric characters, underscores, and whitespace.
22    pub name: Option<String>
23}
24
25/// struct for passing parameters to the method [`delete_acl`]
26#[derive(Clone, Debug, Default)]
27pub struct DeleteAclParams {
28    /// Alphanumeric string identifying the service.
29    pub service_id: String,
30    /// Integer identifying a service version.
31    pub version_id: i32,
32    /// Name for the ACL. Must start with an alphanumeric character and contain only alphanumeric characters, underscores, and whitespace.
33    pub acl_name: String
34}
35
36/// struct for passing parameters to the method [`get_acl`]
37#[derive(Clone, Debug, Default)]
38pub struct GetAclParams {
39    /// Alphanumeric string identifying the service.
40    pub service_id: String,
41    /// Integer identifying a service version.
42    pub version_id: i32,
43    /// Name for the ACL. Must start with an alphanumeric character and contain only alphanumeric characters, underscores, and whitespace.
44    pub acl_name: String
45}
46
47/// struct for passing parameters to the method [`list_acls`]
48#[derive(Clone, Debug, Default)]
49pub struct ListAclsParams {
50    /// Alphanumeric string identifying the service.
51    pub service_id: String,
52    /// Integer identifying a service version.
53    pub version_id: i32
54}
55
56/// struct for passing parameters to the method [`update_acl`]
57#[derive(Clone, Debug, Default)]
58pub struct UpdateAclParams {
59    /// Alphanumeric string identifying the service.
60    pub service_id: String,
61    /// Integer identifying a service version.
62    pub version_id: i32,
63    /// Name for the ACL. Must start with an alphanumeric character and contain only alphanumeric characters, underscores, and whitespace.
64    pub acl_name: String,
65    /// Name for the ACL. Must start with an alphanumeric character and contain only alphanumeric characters, underscores, and whitespace.
66    pub name: Option<String>
67}
68
69
70/// struct for typed errors of method [`create_acl`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum CreateAclError {
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`delete_acl`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum DeleteAclError {
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`get_acl`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum GetAclError {
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`list_acls`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum ListAclsError {
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`update_acl`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum UpdateAclError {
102    UnknownValue(serde_json::Value),
103}
104
105
106/// Create a new ACL attached to the specified service version. A new, empty ACL must be attached to a draft version of a service. The version associated with the ACL must be activated to be used.
107pub async fn create_acl(configuration: &mut configuration::Configuration, params: CreateAclParams) -> Result<crate::models::AclResponse, Error<CreateAclError>> {
108    let local_var_configuration = configuration;
109
110    // unbox the parameters
111    let service_id = params.service_id;
112    let version_id = params.version_id;
113    let name = params.name;
114
115
116    let local_var_client = &local_var_configuration.client;
117
118    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/acl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
119    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
122        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
123    }
124    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
125        let local_var_key = local_var_apikey.key.clone();
126        let local_var_value = match local_var_apikey.prefix {
127            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
128            None => local_var_key,
129        };
130        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
131    };
132    let mut local_var_form_params = std::collections::HashMap::new();
133    if let Some(local_var_param_value) = name {
134        local_var_form_params.insert("name", local_var_param_value.to_string());
135    }
136    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
137
138    let local_var_req = local_var_req_builder.build()?;
139    let local_var_resp = local_var_client.execute(local_var_req).await?;
140
141    if "POST" != "GET" && "POST" != "HEAD" {
142      let headers = local_var_resp.headers();
143      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
144          Some(v) => v.to_str().unwrap().parse().unwrap(),
145          None => configuration::DEFAULT_RATELIMIT,
146      };
147      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
148          Some(v) => v.to_str().unwrap().parse().unwrap(),
149          None => 0,
150      };
151    }
152
153    let local_var_status = local_var_resp.status();
154    let local_var_content = local_var_resp.text().await?;
155
156    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
157        serde_json::from_str(&local_var_content).map_err(Error::from)
158    } else {
159        let local_var_entity: Option<CreateAclError> = serde_json::from_str(&local_var_content).ok();
160        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
161        Err(Error::ResponseError(local_var_error))
162    }
163}
164
165/// Delete an ACL from the specified service version. To remove an ACL from use, the ACL must be deleted from a draft version and the version without the ACL must be activated.
166pub async fn delete_acl(configuration: &mut configuration::Configuration, params: DeleteAclParams) -> Result<crate::models::InlineResponse200, Error<DeleteAclError>> {
167    let local_var_configuration = configuration;
168
169    // unbox the parameters
170    let service_id = params.service_id;
171    let version_id = params.version_id;
172    let acl_name = params.acl_name;
173
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/acl/{acl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, acl_name=crate::apis::urlencode(acl_name));
178    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
179
180    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
181        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
182    }
183    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
184        let local_var_key = local_var_apikey.key.clone();
185        let local_var_value = match local_var_apikey.prefix {
186            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
187            None => local_var_key,
188        };
189        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
190    };
191
192    let local_var_req = local_var_req_builder.build()?;
193    let local_var_resp = local_var_client.execute(local_var_req).await?;
194
195    if "DELETE" != "GET" && "DELETE" != "HEAD" {
196      let headers = local_var_resp.headers();
197      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
198          Some(v) => v.to_str().unwrap().parse().unwrap(),
199          None => configuration::DEFAULT_RATELIMIT,
200      };
201      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
202          Some(v) => v.to_str().unwrap().parse().unwrap(),
203          None => 0,
204      };
205    }
206
207    let local_var_status = local_var_resp.status();
208    let local_var_content = local_var_resp.text().await?;
209
210    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
211        serde_json::from_str(&local_var_content).map_err(Error::from)
212    } else {
213        let local_var_entity: Option<DeleteAclError> = serde_json::from_str(&local_var_content).ok();
214        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
215        Err(Error::ResponseError(local_var_error))
216    }
217}
218
219/// Retrieve a single ACL by name for the version and service.
220pub async fn get_acl(configuration: &mut configuration::Configuration, params: GetAclParams) -> Result<crate::models::AclResponse, Error<GetAclError>> {
221    let local_var_configuration = configuration;
222
223    // unbox the parameters
224    let service_id = params.service_id;
225    let version_id = params.version_id;
226    let acl_name = params.acl_name;
227
228
229    let local_var_client = &local_var_configuration.client;
230
231    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/acl/{acl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, acl_name=crate::apis::urlencode(acl_name));
232    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
233
234    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
235        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
236    }
237    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
238        let local_var_key = local_var_apikey.key.clone();
239        let local_var_value = match local_var_apikey.prefix {
240            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
241            None => local_var_key,
242        };
243        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
244    };
245
246    let local_var_req = local_var_req_builder.build()?;
247    let local_var_resp = local_var_client.execute(local_var_req).await?;
248
249    if "GET" != "GET" && "GET" != "HEAD" {
250      let headers = local_var_resp.headers();
251      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
252          Some(v) => v.to_str().unwrap().parse().unwrap(),
253          None => configuration::DEFAULT_RATELIMIT,
254      };
255      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
256          Some(v) => v.to_str().unwrap().parse().unwrap(),
257          None => 0,
258      };
259    }
260
261    let local_var_status = local_var_resp.status();
262    let local_var_content = local_var_resp.text().await?;
263
264    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
265        serde_json::from_str(&local_var_content).map_err(Error::from)
266    } else {
267        let local_var_entity: Option<GetAclError> = serde_json::from_str(&local_var_content).ok();
268        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
269        Err(Error::ResponseError(local_var_error))
270    }
271}
272
273/// List ACLs.
274pub async fn list_acls(configuration: &mut configuration::Configuration, params: ListAclsParams) -> Result<Vec<crate::models::AclResponse>, Error<ListAclsError>> {
275    let local_var_configuration = configuration;
276
277    // unbox the parameters
278    let service_id = params.service_id;
279    let version_id = params.version_id;
280
281
282    let local_var_client = &local_var_configuration.client;
283
284    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/acl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
285    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
286
287    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
288        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289    }
290    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
291        let local_var_key = local_var_apikey.key.clone();
292        let local_var_value = match local_var_apikey.prefix {
293            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
294            None => local_var_key,
295        };
296        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
297    };
298
299    let local_var_req = local_var_req_builder.build()?;
300    let local_var_resp = local_var_client.execute(local_var_req).await?;
301
302    if "GET" != "GET" && "GET" != "HEAD" {
303      let headers = local_var_resp.headers();
304      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
305          Some(v) => v.to_str().unwrap().parse().unwrap(),
306          None => configuration::DEFAULT_RATELIMIT,
307      };
308      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
309          Some(v) => v.to_str().unwrap().parse().unwrap(),
310          None => 0,
311      };
312    }
313
314    let local_var_status = local_var_resp.status();
315    let local_var_content = local_var_resp.text().await?;
316
317    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
318        serde_json::from_str(&local_var_content).map_err(Error::from)
319    } else {
320        let local_var_entity: Option<ListAclsError> = serde_json::from_str(&local_var_content).ok();
321        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
322        Err(Error::ResponseError(local_var_error))
323    }
324}
325
326/// Update an ACL for a particular service and version.
327pub async fn update_acl(configuration: &mut configuration::Configuration, params: UpdateAclParams) -> Result<crate::models::AclResponse, Error<UpdateAclError>> {
328    let local_var_configuration = configuration;
329
330    // unbox the parameters
331    let service_id = params.service_id;
332    let version_id = params.version_id;
333    let acl_name = params.acl_name;
334    let name = params.name;
335
336
337    let local_var_client = &local_var_configuration.client;
338
339    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/acl/{acl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, acl_name=crate::apis::urlencode(acl_name));
340    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
341
342    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
343        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
344    }
345    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
346        let local_var_key = local_var_apikey.key.clone();
347        let local_var_value = match local_var_apikey.prefix {
348            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
349            None => local_var_key,
350        };
351        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
352    };
353    let mut local_var_form_params = std::collections::HashMap::new();
354    if let Some(local_var_param_value) = name {
355        local_var_form_params.insert("name", local_var_param_value.to_string());
356    }
357    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
358
359    let local_var_req = local_var_req_builder.build()?;
360    let local_var_resp = local_var_client.execute(local_var_req).await?;
361
362    if "PUT" != "GET" && "PUT" != "HEAD" {
363      let headers = local_var_resp.headers();
364      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
365          Some(v) => v.to_str().unwrap().parse().unwrap(),
366          None => configuration::DEFAULT_RATELIMIT,
367      };
368      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
369          Some(v) => v.to_str().unwrap().parse().unwrap(),
370          None => 0,
371      };
372    }
373
374    let local_var_status = local_var_resp.status();
375    let local_var_content = local_var_resp.text().await?;
376
377    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
378        serde_json::from_str(&local_var_content).map_err(Error::from)
379    } else {
380        let local_var_entity: Option<UpdateAclError> = serde_json::from_str(&local_var_content).ok();
381        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
382        Err(Error::ResponseError(local_var_error))
383    }
384}
385