fastly_api/apis/
service_authorizations_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_service_authorization`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateServiceAuthorizationParams {
17    pub service_authorization: Option<crate::models::ServiceAuthorization>
18}
19
20/// struct for passing parameters to the method [`delete_service_authorization`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteServiceAuthorizationParams {
23    /// Alphanumeric string identifying a service authorization.
24    pub service_authorization_id: String
25}
26
27/// struct for passing parameters to the method [`delete_service_authorization2`]
28#[derive(Clone, Debug, Default)]
29pub struct DeleteServiceAuthorization2Params {
30    pub request_body: Option<::std::collections::HashMap<String, serde_json::Value>>
31}
32
33/// struct for passing parameters to the method [`list_service_authorization`]
34#[derive(Clone, Debug, Default)]
35pub struct ListServiceAuthorizationParams {
36    /// Current page.
37    pub page_number: Option<i32>,
38    /// Number of records per page.
39    pub page_size: Option<i32>
40}
41
42/// struct for passing parameters to the method [`show_service_authorization`]
43#[derive(Clone, Debug, Default)]
44pub struct ShowServiceAuthorizationParams {
45    /// Alphanumeric string identifying a service authorization.
46    pub service_authorization_id: String
47}
48
49/// struct for passing parameters to the method [`update_service_authorization`]
50#[derive(Clone, Debug, Default)]
51pub struct UpdateServiceAuthorizationParams {
52    /// Alphanumeric string identifying a service authorization.
53    pub service_authorization_id: String,
54    pub service_authorization: Option<crate::models::ServiceAuthorization>
55}
56
57/// struct for passing parameters to the method [`update_service_authorization2`]
58#[derive(Clone, Debug, Default)]
59pub struct UpdateServiceAuthorization2Params {
60    pub request_body: Option<::std::collections::HashMap<String, serde_json::Value>>
61}
62
63
64/// struct for typed errors of method [`create_service_authorization`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum CreateServiceAuthorizationError {
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`delete_service_authorization`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum DeleteServiceAuthorizationError {
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`delete_service_authorization2`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum DeleteServiceAuthorization2Error {
82    UnknownValue(serde_json::Value),
83}
84
85/// struct for typed errors of method [`list_service_authorization`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ListServiceAuthorizationError {
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`show_service_authorization`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum ShowServiceAuthorizationError {
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`update_service_authorization`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum UpdateServiceAuthorizationError {
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`update_service_authorization2`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum UpdateServiceAuthorization2Error {
110    UnknownValue(serde_json::Value),
111}
112
113
114/// Create service authorization.
115pub async fn create_service_authorization(configuration: &mut configuration::Configuration, params: CreateServiceAuthorizationParams) -> Result<crate::models::ServiceAuthorizationResponse, Error<CreateServiceAuthorizationError>> {
116    let local_var_configuration = configuration;
117
118    // unbox the parameters
119    let service_authorization = params.service_authorization;
120
121
122    let local_var_client = &local_var_configuration.client;
123
124    let local_var_uri_str = format!("{}/service-authorizations", local_var_configuration.base_path);
125    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
126
127    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
128        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
129    }
130    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
131        let local_var_key = local_var_apikey.key.clone();
132        let local_var_value = match local_var_apikey.prefix {
133            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
134            None => local_var_key,
135        };
136        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
137    };
138    local_var_req_builder = local_var_req_builder.json(&service_authorization);
139
140    let local_var_req = local_var_req_builder.build()?;
141    let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143    if "POST" != "GET" && "POST" != "HEAD" {
144      let headers = local_var_resp.headers();
145      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
146          Some(v) => v.to_str().unwrap().parse().unwrap(),
147          None => configuration::DEFAULT_RATELIMIT,
148      };
149      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
150          Some(v) => v.to_str().unwrap().parse().unwrap(),
151          None => 0,
152      };
153    }
154
155    let local_var_status = local_var_resp.status();
156    let local_var_content = local_var_resp.text().await?;
157
158    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159        serde_json::from_str(&local_var_content).map_err(Error::from)
160    } else {
161        let local_var_entity: Option<CreateServiceAuthorizationError> = serde_json::from_str(&local_var_content).ok();
162        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
163        Err(Error::ResponseError(local_var_error))
164    }
165}
166
167/// Delete service authorization.
168pub async fn delete_service_authorization(configuration: &mut configuration::Configuration, params: DeleteServiceAuthorizationParams) -> Result<(), Error<DeleteServiceAuthorizationError>> {
169    let local_var_configuration = configuration;
170
171    // unbox the parameters
172    let service_authorization_id = params.service_authorization_id;
173
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!("{}/service-authorizations/{service_authorization_id}", local_var_configuration.base_path, service_authorization_id=crate::apis::urlencode(service_authorization_id));
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        Ok(())
212    } else {
213        let local_var_entity: Option<DeleteServiceAuthorizationError> = 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/// Delete service authorizations.
220pub async fn delete_service_authorization2(configuration: &mut configuration::Configuration, params: DeleteServiceAuthorization2Params) -> Result<crate::models::InlineResponse2009, Error<DeleteServiceAuthorization2Error>> {
221    let local_var_configuration = configuration;
222
223    // unbox the parameters
224    let request_body = params.request_body;
225
226
227    let local_var_client = &local_var_configuration.client;
228
229    let local_var_uri_str = format!("{}/service-authorizations", local_var_configuration.base_path);
230    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
231
232    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
233        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
234    }
235    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
236        let local_var_key = local_var_apikey.key.clone();
237        let local_var_value = match local_var_apikey.prefix {
238            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
239            None => local_var_key,
240        };
241        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
242    };
243    local_var_req_builder = local_var_req_builder.json(&request_body);
244
245    let local_var_req = local_var_req_builder.build()?;
246    let local_var_resp = local_var_client.execute(local_var_req).await?;
247
248    if "DELETE" != "GET" && "DELETE" != "HEAD" {
249      let headers = local_var_resp.headers();
250      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
251          Some(v) => v.to_str().unwrap().parse().unwrap(),
252          None => configuration::DEFAULT_RATELIMIT,
253      };
254      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
255          Some(v) => v.to_str().unwrap().parse().unwrap(),
256          None => 0,
257      };
258    }
259
260    let local_var_status = local_var_resp.status();
261    let local_var_content = local_var_resp.text().await?;
262
263    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264        serde_json::from_str(&local_var_content).map_err(Error::from)
265    } else {
266        let local_var_entity: Option<DeleteServiceAuthorization2Error> = serde_json::from_str(&local_var_content).ok();
267        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
268        Err(Error::ResponseError(local_var_error))
269    }
270}
271
272/// List service authorizations.
273pub async fn list_service_authorization(configuration: &mut configuration::Configuration, params: ListServiceAuthorizationParams) -> Result<crate::models::ServiceAuthorizationsResponse, Error<ListServiceAuthorizationError>> {
274    let local_var_configuration = configuration;
275
276    // unbox the parameters
277    let page_number = params.page_number;
278    let page_size = params.page_size;
279
280
281    let local_var_client = &local_var_configuration.client;
282
283    let local_var_uri_str = format!("{}/service-authorizations", local_var_configuration.base_path);
284    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
285
286    if let Some(ref local_var_str) = page_number {
287        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
288    }
289    if let Some(ref local_var_str) = page_size {
290        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
291    }
292    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
293        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
294    }
295    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
296        let local_var_key = local_var_apikey.key.clone();
297        let local_var_value = match local_var_apikey.prefix {
298            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
299            None => local_var_key,
300        };
301        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
302    };
303
304    let local_var_req = local_var_req_builder.build()?;
305    let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307    if "GET" != "GET" && "GET" != "HEAD" {
308      let headers = local_var_resp.headers();
309      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
310          Some(v) => v.to_str().unwrap().parse().unwrap(),
311          None => configuration::DEFAULT_RATELIMIT,
312      };
313      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
314          Some(v) => v.to_str().unwrap().parse().unwrap(),
315          None => 0,
316      };
317    }
318
319    let local_var_status = local_var_resp.status();
320    let local_var_content = local_var_resp.text().await?;
321
322    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
323        serde_json::from_str(&local_var_content).map_err(Error::from)
324    } else {
325        let local_var_entity: Option<ListServiceAuthorizationError> = serde_json::from_str(&local_var_content).ok();
326        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
327        Err(Error::ResponseError(local_var_error))
328    }
329}
330
331/// Show service authorization.
332pub async fn show_service_authorization(configuration: &mut configuration::Configuration, params: ShowServiceAuthorizationParams) -> Result<crate::models::ServiceAuthorizationResponse, Error<ShowServiceAuthorizationError>> {
333    let local_var_configuration = configuration;
334
335    // unbox the parameters
336    let service_authorization_id = params.service_authorization_id;
337
338
339    let local_var_client = &local_var_configuration.client;
340
341    let local_var_uri_str = format!("{}/service-authorizations/{service_authorization_id}", local_var_configuration.base_path, service_authorization_id=crate::apis::urlencode(service_authorization_id));
342    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
343
344    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
345        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
346    }
347    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
348        let local_var_key = local_var_apikey.key.clone();
349        let local_var_value = match local_var_apikey.prefix {
350            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
351            None => local_var_key,
352        };
353        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
354    };
355
356    let local_var_req = local_var_req_builder.build()?;
357    let local_var_resp = local_var_client.execute(local_var_req).await?;
358
359    if "GET" != "GET" && "GET" != "HEAD" {
360      let headers = local_var_resp.headers();
361      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
362          Some(v) => v.to_str().unwrap().parse().unwrap(),
363          None => configuration::DEFAULT_RATELIMIT,
364      };
365      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
366          Some(v) => v.to_str().unwrap().parse().unwrap(),
367          None => 0,
368      };
369    }
370
371    let local_var_status = local_var_resp.status();
372    let local_var_content = local_var_resp.text().await?;
373
374    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
375        serde_json::from_str(&local_var_content).map_err(Error::from)
376    } else {
377        let local_var_entity: Option<ShowServiceAuthorizationError> = serde_json::from_str(&local_var_content).ok();
378        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
379        Err(Error::ResponseError(local_var_error))
380    }
381}
382
383/// Update service authorization.
384pub async fn update_service_authorization(configuration: &mut configuration::Configuration, params: UpdateServiceAuthorizationParams) -> Result<crate::models::ServiceAuthorizationResponse, Error<UpdateServiceAuthorizationError>> {
385    let local_var_configuration = configuration;
386
387    // unbox the parameters
388    let service_authorization_id = params.service_authorization_id;
389    let service_authorization = params.service_authorization;
390
391
392    let local_var_client = &local_var_configuration.client;
393
394    let local_var_uri_str = format!("{}/service-authorizations/{service_authorization_id}", local_var_configuration.base_path, service_authorization_id=crate::apis::urlencode(service_authorization_id));
395    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
396
397    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
398        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
399    }
400    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
401        let local_var_key = local_var_apikey.key.clone();
402        let local_var_value = match local_var_apikey.prefix {
403            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
404            None => local_var_key,
405        };
406        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
407    };
408    local_var_req_builder = local_var_req_builder.json(&service_authorization);
409
410    let local_var_req = local_var_req_builder.build()?;
411    let local_var_resp = local_var_client.execute(local_var_req).await?;
412
413    if "PATCH" != "GET" && "PATCH" != "HEAD" {
414      let headers = local_var_resp.headers();
415      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
416          Some(v) => v.to_str().unwrap().parse().unwrap(),
417          None => configuration::DEFAULT_RATELIMIT,
418      };
419      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
420          Some(v) => v.to_str().unwrap().parse().unwrap(),
421          None => 0,
422      };
423    }
424
425    let local_var_status = local_var_resp.status();
426    let local_var_content = local_var_resp.text().await?;
427
428    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
429        serde_json::from_str(&local_var_content).map_err(Error::from)
430    } else {
431        let local_var_entity: Option<UpdateServiceAuthorizationError> = serde_json::from_str(&local_var_content).ok();
432        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
433        Err(Error::ResponseError(local_var_error))
434    }
435}
436
437/// Update service authorizations.
438pub async fn update_service_authorization2(configuration: &mut configuration::Configuration, params: UpdateServiceAuthorization2Params) -> Result<crate::models::ServiceAuthorizationsResponse, Error<UpdateServiceAuthorization2Error>> {
439    let local_var_configuration = configuration;
440
441    // unbox the parameters
442    let request_body = params.request_body;
443
444
445    let local_var_client = &local_var_configuration.client;
446
447    let local_var_uri_str = format!("{}/service-authorizations", local_var_configuration.base_path);
448    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
449
450    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
451        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
452    }
453    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
454        let local_var_key = local_var_apikey.key.clone();
455        let local_var_value = match local_var_apikey.prefix {
456            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
457            None => local_var_key,
458        };
459        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
460    };
461    local_var_req_builder = local_var_req_builder.json(&request_body);
462
463    let local_var_req = local_var_req_builder.build()?;
464    let local_var_resp = local_var_client.execute(local_var_req).await?;
465
466    if "PATCH" != "GET" && "PATCH" != "HEAD" {
467      let headers = local_var_resp.headers();
468      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
469          Some(v) => v.to_str().unwrap().parse().unwrap(),
470          None => configuration::DEFAULT_RATELIMIT,
471      };
472      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
473          Some(v) => v.to_str().unwrap().parse().unwrap(),
474          None => 0,
475      };
476    }
477
478    let local_var_status = local_var_resp.status();
479    let local_var_content = local_var_resp.text().await?;
480
481    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
482        serde_json::from_str(&local_var_content).map_err(Error::from)
483    } else {
484        let local_var_entity: Option<UpdateServiceAuthorization2Error> = serde_json::from_str(&local_var_content).ok();
485        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
486        Err(Error::ResponseError(local_var_error))
487    }
488}
489