fastly_api/apis/
acl_entry_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 [`bulk_update_acl_entries`]
15#[derive(Clone, Debug, Default)]
16pub struct BulkUpdateAclEntriesParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Alphanumeric string identifying a ACL.
20    pub acl_id: String,
21    pub bulk_update_acl_entries_request: Option<crate::models::BulkUpdateAclEntriesRequest>
22}
23
24/// struct for passing parameters to the method [`create_acl_entry`]
25#[derive(Clone, Debug, Default)]
26pub struct CreateAclEntryParams {
27    /// Alphanumeric string identifying the service.
28    pub service_id: String,
29    /// Alphanumeric string identifying a ACL.
30    pub acl_id: String,
31    pub acl_entry: Option<crate::models::AclEntry>
32}
33
34/// struct for passing parameters to the method [`delete_acl_entry`]
35#[derive(Clone, Debug, Default)]
36pub struct DeleteAclEntryParams {
37    /// Alphanumeric string identifying the service.
38    pub service_id: String,
39    /// Alphanumeric string identifying a ACL.
40    pub acl_id: String,
41    /// Alphanumeric string identifying an ACL Entry.
42    pub acl_entry_id: String
43}
44
45/// struct for passing parameters to the method [`get_acl_entry`]
46#[derive(Clone, Debug, Default)]
47pub struct GetAclEntryParams {
48    /// Alphanumeric string identifying the service.
49    pub service_id: String,
50    /// Alphanumeric string identifying a ACL.
51    pub acl_id: String,
52    /// Alphanumeric string identifying an ACL Entry.
53    pub acl_entry_id: String
54}
55
56/// struct for passing parameters to the method [`list_acl_entries`]
57#[derive(Clone, Debug, Default)]
58pub struct ListAclEntriesParams {
59    /// Alphanumeric string identifying the service.
60    pub service_id: String,
61    /// Alphanumeric string identifying a ACL.
62    pub acl_id: String,
63    /// Current page.
64    pub page: Option<i32>,
65    /// Number of records per page.
66    pub per_page: Option<i32>,
67    /// Field on which to sort.
68    pub sort: Option<String>,
69    /// Direction in which to sort results.
70    pub direction: Option<String>
71}
72
73/// struct for passing parameters to the method [`update_acl_entry`]
74#[derive(Clone, Debug, Default)]
75pub struct UpdateAclEntryParams {
76    /// Alphanumeric string identifying the service.
77    pub service_id: String,
78    /// Alphanumeric string identifying a ACL.
79    pub acl_id: String,
80    /// Alphanumeric string identifying an ACL Entry.
81    pub acl_entry_id: String,
82    pub acl_entry: Option<crate::models::AclEntry>
83}
84
85
86/// struct for typed errors of method [`bulk_update_acl_entries`]
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum BulkUpdateAclEntriesError {
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`create_acl_entry`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum CreateAclEntryError {
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`delete_acl_entry`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum DeleteAclEntryError {
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`get_acl_entry`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetAclEntryError {
111    UnknownValue(serde_json::Value),
112}
113
114/// struct for typed errors of method [`list_acl_entries`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum ListAclEntriesError {
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`update_acl_entry`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum UpdateAclEntryError {
125    UnknownValue(serde_json::Value),
126}
127
128
129/// Update multiple ACL entries on the same ACL. For faster updates to your service, group your changes into large batches. The maximum batch size is 1000 entries. [Contact support](https://support.fastly.com/) to discuss raising this limit.
130pub async fn bulk_update_acl_entries(configuration: &mut configuration::Configuration, params: BulkUpdateAclEntriesParams) -> Result<crate::models::InlineResponse200, Error<BulkUpdateAclEntriesError>> {
131    let local_var_configuration = configuration;
132
133    // unbox the parameters
134    let service_id = params.service_id;
135    let acl_id = params.acl_id;
136    let bulk_update_acl_entries_request = params.bulk_update_acl_entries_request;
137
138
139    let local_var_client = &local_var_configuration.client;
140
141    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entries", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id));
142    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
143
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
148        let local_var_key = local_var_apikey.key.clone();
149        let local_var_value = match local_var_apikey.prefix {
150            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
151            None => local_var_key,
152        };
153        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
154    };
155    local_var_req_builder = local_var_req_builder.json(&bulk_update_acl_entries_request);
156
157    let local_var_req = local_var_req_builder.build()?;
158    let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160    if "PATCH" != "GET" && "PATCH" != "HEAD" {
161      let headers = local_var_resp.headers();
162      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
163          Some(v) => v.to_str().unwrap().parse().unwrap(),
164          None => configuration::DEFAULT_RATELIMIT,
165      };
166      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
167          Some(v) => v.to_str().unwrap().parse().unwrap(),
168          None => 0,
169      };
170    }
171
172    let local_var_status = local_var_resp.status();
173    let local_var_content = local_var_resp.text().await?;
174
175    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176        serde_json::from_str(&local_var_content).map_err(Error::from)
177    } else {
178        let local_var_entity: Option<BulkUpdateAclEntriesError> = serde_json::from_str(&local_var_content).ok();
179        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180        Err(Error::ResponseError(local_var_error))
181    }
182}
183
184/// Add an ACL entry to an ACL.
185pub async fn create_acl_entry(configuration: &mut configuration::Configuration, params: CreateAclEntryParams) -> Result<crate::models::AclEntryResponse, Error<CreateAclEntryError>> {
186    let local_var_configuration = configuration;
187
188    // unbox the parameters
189    let service_id = params.service_id;
190    let acl_id = params.acl_id;
191    let acl_entry = params.acl_entry;
192
193
194    let local_var_client = &local_var_configuration.client;
195
196    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entry", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id));
197    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
198
199    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
200        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
201    }
202    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
203        let local_var_key = local_var_apikey.key.clone();
204        let local_var_value = match local_var_apikey.prefix {
205            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
206            None => local_var_key,
207        };
208        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
209    };
210    local_var_req_builder = local_var_req_builder.json(&acl_entry);
211
212    let local_var_req = local_var_req_builder.build()?;
213    let local_var_resp = local_var_client.execute(local_var_req).await?;
214
215    if "POST" != "GET" && "POST" != "HEAD" {
216      let headers = local_var_resp.headers();
217      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
218          Some(v) => v.to_str().unwrap().parse().unwrap(),
219          None => configuration::DEFAULT_RATELIMIT,
220      };
221      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
222          Some(v) => v.to_str().unwrap().parse().unwrap(),
223          None => 0,
224      };
225    }
226
227    let local_var_status = local_var_resp.status();
228    let local_var_content = local_var_resp.text().await?;
229
230    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
231        serde_json::from_str(&local_var_content).map_err(Error::from)
232    } else {
233        let local_var_entity: Option<CreateAclEntryError> = serde_json::from_str(&local_var_content).ok();
234        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
235        Err(Error::ResponseError(local_var_error))
236    }
237}
238
239/// Delete an ACL entry from a specified ACL.
240pub async fn delete_acl_entry(configuration: &mut configuration::Configuration, params: DeleteAclEntryParams) -> Result<crate::models::InlineResponse200, Error<DeleteAclEntryError>> {
241    let local_var_configuration = configuration;
242
243    // unbox the parameters
244    let service_id = params.service_id;
245    let acl_id = params.acl_id;
246    let acl_entry_id = params.acl_entry_id;
247
248
249    let local_var_client = &local_var_configuration.client;
250
251    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entry/{acl_entry_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id), acl_entry_id=crate::apis::urlencode(acl_entry_id));
252    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
253
254    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
255        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
256    }
257    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
258        let local_var_key = local_var_apikey.key.clone();
259        let local_var_value = match local_var_apikey.prefix {
260            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
261            None => local_var_key,
262        };
263        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
264    };
265
266    let local_var_req = local_var_req_builder.build()?;
267    let local_var_resp = local_var_client.execute(local_var_req).await?;
268
269    if "DELETE" != "GET" && "DELETE" != "HEAD" {
270      let headers = local_var_resp.headers();
271      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
272          Some(v) => v.to_str().unwrap().parse().unwrap(),
273          None => configuration::DEFAULT_RATELIMIT,
274      };
275      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
276          Some(v) => v.to_str().unwrap().parse().unwrap(),
277          None => 0,
278      };
279    }
280
281    let local_var_status = local_var_resp.status();
282    let local_var_content = local_var_resp.text().await?;
283
284    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
285        serde_json::from_str(&local_var_content).map_err(Error::from)
286    } else {
287        let local_var_entity: Option<DeleteAclEntryError> = serde_json::from_str(&local_var_content).ok();
288        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
289        Err(Error::ResponseError(local_var_error))
290    }
291}
292
293/// Retrieve a single ACL entry.
294pub async fn get_acl_entry(configuration: &mut configuration::Configuration, params: GetAclEntryParams) -> Result<crate::models::AclEntryResponse, Error<GetAclEntryError>> {
295    let local_var_configuration = configuration;
296
297    // unbox the parameters
298    let service_id = params.service_id;
299    let acl_id = params.acl_id;
300    let acl_entry_id = params.acl_entry_id;
301
302
303    let local_var_client = &local_var_configuration.client;
304
305    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entry/{acl_entry_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id), acl_entry_id=crate::apis::urlencode(acl_entry_id));
306    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
307
308    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
309        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
310    }
311    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
312        let local_var_key = local_var_apikey.key.clone();
313        let local_var_value = match local_var_apikey.prefix {
314            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
315            None => local_var_key,
316        };
317        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
318    };
319
320    let local_var_req = local_var_req_builder.build()?;
321    let local_var_resp = local_var_client.execute(local_var_req).await?;
322
323    if "GET" != "GET" && "GET" != "HEAD" {
324      let headers = local_var_resp.headers();
325      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
326          Some(v) => v.to_str().unwrap().parse().unwrap(),
327          None => configuration::DEFAULT_RATELIMIT,
328      };
329      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
330          Some(v) => v.to_str().unwrap().parse().unwrap(),
331          None => 0,
332      };
333    }
334
335    let local_var_status = local_var_resp.status();
336    let local_var_content = local_var_resp.text().await?;
337
338    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
339        serde_json::from_str(&local_var_content).map_err(Error::from)
340    } else {
341        let local_var_entity: Option<GetAclEntryError> = serde_json::from_str(&local_var_content).ok();
342        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
343        Err(Error::ResponseError(local_var_error))
344    }
345}
346
347/// List ACL entries for a specified ACL.
348pub async fn list_acl_entries(configuration: &mut configuration::Configuration, params: ListAclEntriesParams) -> Result<Vec<crate::models::AclEntryResponse>, Error<ListAclEntriesError>> {
349    let local_var_configuration = configuration;
350
351    // unbox the parameters
352    let service_id = params.service_id;
353    let acl_id = params.acl_id;
354    let page = params.page;
355    let per_page = params.per_page;
356    let sort = params.sort;
357    let direction = params.direction;
358
359
360    let local_var_client = &local_var_configuration.client;
361
362    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entries", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id));
363    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
364
365    if let Some(ref local_var_str) = page {
366        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
367    }
368    if let Some(ref local_var_str) = per_page {
369        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
370    }
371    if let Some(ref local_var_str) = sort {
372        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
373    }
374    if let Some(ref local_var_str) = direction {
375        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
376    }
377    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
378        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
379    }
380    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
381        let local_var_key = local_var_apikey.key.clone();
382        let local_var_value = match local_var_apikey.prefix {
383            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
384            None => local_var_key,
385        };
386        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
387    };
388
389    let local_var_req = local_var_req_builder.build()?;
390    let local_var_resp = local_var_client.execute(local_var_req).await?;
391
392    if "GET" != "GET" && "GET" != "HEAD" {
393      let headers = local_var_resp.headers();
394      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
395          Some(v) => v.to_str().unwrap().parse().unwrap(),
396          None => configuration::DEFAULT_RATELIMIT,
397      };
398      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
399          Some(v) => v.to_str().unwrap().parse().unwrap(),
400          None => 0,
401      };
402    }
403
404    let local_var_status = local_var_resp.status();
405    let local_var_content = local_var_resp.text().await?;
406
407    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
408        serde_json::from_str(&local_var_content).map_err(Error::from)
409    } else {
410        let local_var_entity: Option<ListAclEntriesError> = serde_json::from_str(&local_var_content).ok();
411        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
412        Err(Error::ResponseError(local_var_error))
413    }
414}
415
416/// Update an ACL entry for a specified ACL.
417pub async fn update_acl_entry(configuration: &mut configuration::Configuration, params: UpdateAclEntryParams) -> Result<crate::models::AclEntryResponse, Error<UpdateAclEntryError>> {
418    let local_var_configuration = configuration;
419
420    // unbox the parameters
421    let service_id = params.service_id;
422    let acl_id = params.acl_id;
423    let acl_entry_id = params.acl_entry_id;
424    let acl_entry = params.acl_entry;
425
426
427    let local_var_client = &local_var_configuration.client;
428
429    let local_var_uri_str = format!("{}/service/{service_id}/acl/{acl_id}/entry/{acl_entry_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), acl_id=crate::apis::urlencode(acl_id), acl_entry_id=crate::apis::urlencode(acl_entry_id));
430    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
431
432    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
433        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
434    }
435    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
436        let local_var_key = local_var_apikey.key.clone();
437        let local_var_value = match local_var_apikey.prefix {
438            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
439            None => local_var_key,
440        };
441        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
442    };
443    local_var_req_builder = local_var_req_builder.json(&acl_entry);
444
445    let local_var_req = local_var_req_builder.build()?;
446    let local_var_resp = local_var_client.execute(local_var_req).await?;
447
448    if "PATCH" != "GET" && "PATCH" != "HEAD" {
449      let headers = local_var_resp.headers();
450      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
451          Some(v) => v.to_str().unwrap().parse().unwrap(),
452          None => configuration::DEFAULT_RATELIMIT,
453      };
454      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
455          Some(v) => v.to_str().unwrap().parse().unwrap(),
456          None => 0,
457      };
458    }
459
460    let local_var_status = local_var_resp.status();
461    let local_var_content = local_var_resp.text().await?;
462
463    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
464        serde_json::from_str(&local_var_content).map_err(Error::from)
465    } else {
466        let local_var_entity: Option<UpdateAclEntryError> = serde_json::from_str(&local_var_content).ok();
467        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
468        Err(Error::ResponseError(local_var_error))
469    }
470}
471