fastly_api/apis/
mutual_authentication_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_mutual_tls_authentication`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateMutualTlsAuthenticationParams {
17    pub mutual_authentication: Option<crate::models::MutualAuthentication>
18}
19
20/// struct for passing parameters to the method [`delete_mutual_tls`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteMutualTlsParams {
23    /// Alphanumeric string identifying a mutual authentication.
24    pub mutual_authentication_id: String
25}
26
27/// struct for passing parameters to the method [`get_mutual_authentication`]
28#[derive(Clone, Debug, Default)]
29pub struct GetMutualAuthenticationParams {
30    /// Alphanumeric string identifying a mutual authentication.
31    pub mutual_authentication_id: String,
32    /// Comma-separated list of related objects to include (optional). Permitted values: `tls_activations`. Including TLS activations will provide you with the TLS domain names that are related to your Mutual TLS authentication. 
33    pub include: Option<String>
34}
35
36/// struct for passing parameters to the method [`list_mutual_authentications`]
37#[derive(Clone, Debug, Default)]
38pub struct ListMutualAuthenticationsParams {
39    /// Comma-separated list of related objects to include (optional). Permitted values: `tls_activations`. Including TLS activations will provide you with the TLS domain names that are related to your Mutual TLS authentication. 
40    pub include: Option<String>,
41    /// Current page.
42    pub page_number: Option<i32>,
43    /// Number of records per page.
44    pub page_size: Option<i32>
45}
46
47/// struct for passing parameters to the method [`patch_mutual_authentication`]
48#[derive(Clone, Debug, Default)]
49pub struct PatchMutualAuthenticationParams {
50    /// Alphanumeric string identifying a mutual authentication.
51    pub mutual_authentication_id: String,
52    pub mutual_authentication: Option<crate::models::MutualAuthentication>
53}
54
55
56/// struct for typed errors of method [`create_mutual_tls_authentication`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum CreateMutualTlsAuthenticationError {
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`delete_mutual_tls`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum DeleteMutualTlsError {
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`get_mutual_authentication`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum GetMutualAuthenticationError {
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`list_mutual_authentications`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ListMutualAuthenticationsError {
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`patch_mutual_authentication`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum PatchMutualAuthenticationError {
88    UnknownValue(serde_json::Value),
89}
90
91
92/// Create a mutual authentication using a bundle of certificates to enable client-to-server mutual TLS.
93pub async fn create_mutual_tls_authentication(configuration: &mut configuration::Configuration, params: CreateMutualTlsAuthenticationParams) -> Result<crate::models::MutualAuthenticationResponse, Error<CreateMutualTlsAuthenticationError>> {
94    let local_var_configuration = configuration;
95
96    // unbox the parameters
97    let mutual_authentication = params.mutual_authentication;
98
99
100    let local_var_client = &local_var_configuration.client;
101
102    let local_var_uri_str = format!("{}/tls/mutual_authentications", local_var_configuration.base_path);
103    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
104
105    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107    }
108    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
109        let local_var_key = local_var_apikey.key.clone();
110        let local_var_value = match local_var_apikey.prefix {
111            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
112            None => local_var_key,
113        };
114        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
115    };
116    local_var_req_builder = local_var_req_builder.json(&mutual_authentication);
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    if "POST" != "GET" && "POST" != "HEAD" {
122      let headers = local_var_resp.headers();
123      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
124          Some(v) => v.to_str().unwrap().parse().unwrap(),
125          None => configuration::DEFAULT_RATELIMIT,
126      };
127      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
128          Some(v) => v.to_str().unwrap().parse().unwrap(),
129          None => 0,
130      };
131    }
132
133    let local_var_status = local_var_resp.status();
134    let local_var_content = local_var_resp.text().await?;
135
136    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137        serde_json::from_str(&local_var_content).map_err(Error::from)
138    } else {
139        let local_var_entity: Option<CreateMutualTlsAuthenticationError> = serde_json::from_str(&local_var_content).ok();
140        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141        Err(Error::ResponseError(local_var_error))
142    }
143}
144
145/// Remove a Mutual TLS authentication
146pub async fn delete_mutual_tls(configuration: &mut configuration::Configuration, params: DeleteMutualTlsParams) -> Result<(), Error<DeleteMutualTlsError>> {
147    let local_var_configuration = configuration;
148
149    // unbox the parameters
150    let mutual_authentication_id = params.mutual_authentication_id;
151
152
153    let local_var_client = &local_var_configuration.client;
154
155    let local_var_uri_str = format!("{}/tls/mutual_authentications/{mutual_authentication_id}", local_var_configuration.base_path, mutual_authentication_id=crate::apis::urlencode(mutual_authentication_id));
156    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
157
158    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
160    }
161    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
162        let local_var_key = local_var_apikey.key.clone();
163        let local_var_value = match local_var_apikey.prefix {
164            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
165            None => local_var_key,
166        };
167        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
168    };
169
170    let local_var_req = local_var_req_builder.build()?;
171    let local_var_resp = local_var_client.execute(local_var_req).await?;
172
173    if "DELETE" != "GET" && "DELETE" != "HEAD" {
174      let headers = local_var_resp.headers();
175      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
176          Some(v) => v.to_str().unwrap().parse().unwrap(),
177          None => configuration::DEFAULT_RATELIMIT,
178      };
179      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
180          Some(v) => v.to_str().unwrap().parse().unwrap(),
181          None => 0,
182      };
183    }
184
185    let local_var_status = local_var_resp.status();
186    let local_var_content = local_var_resp.text().await?;
187
188    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189        Ok(())
190    } else {
191        let local_var_entity: Option<DeleteMutualTlsError> = serde_json::from_str(&local_var_content).ok();
192        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
193        Err(Error::ResponseError(local_var_error))
194    }
195}
196
197/// Show a Mutual Authentication.
198pub async fn get_mutual_authentication(configuration: &mut configuration::Configuration, params: GetMutualAuthenticationParams) -> Result<crate::models::MutualAuthenticationResponse, Error<GetMutualAuthenticationError>> {
199    let local_var_configuration = configuration;
200
201    // unbox the parameters
202    let mutual_authentication_id = params.mutual_authentication_id;
203    let include = params.include;
204
205
206    let local_var_client = &local_var_configuration.client;
207
208    let local_var_uri_str = format!("{}/tls/mutual_authentications/{mutual_authentication_id}", local_var_configuration.base_path, mutual_authentication_id=crate::apis::urlencode(mutual_authentication_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_str) = include {
212        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
213    }
214    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
216    }
217    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
218        let local_var_key = local_var_apikey.key.clone();
219        let local_var_value = match local_var_apikey.prefix {
220            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
221            None => local_var_key,
222        };
223        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
224    };
225
226    let local_var_req = local_var_req_builder.build()?;
227    let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229    if "GET" != "GET" && "GET" != "HEAD" {
230      let headers = local_var_resp.headers();
231      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
232          Some(v) => v.to_str().unwrap().parse().unwrap(),
233          None => configuration::DEFAULT_RATELIMIT,
234      };
235      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
236          Some(v) => v.to_str().unwrap().parse().unwrap(),
237          None => 0,
238      };
239    }
240
241    let local_var_status = local_var_resp.status();
242    let local_var_content = local_var_resp.text().await?;
243
244    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245        serde_json::from_str(&local_var_content).map_err(Error::from)
246    } else {
247        let local_var_entity: Option<GetMutualAuthenticationError> = serde_json::from_str(&local_var_content).ok();
248        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
249        Err(Error::ResponseError(local_var_error))
250    }
251}
252
253/// List all mutual authentications.
254pub async fn list_mutual_authentications(configuration: &mut configuration::Configuration, params: ListMutualAuthenticationsParams) -> Result<crate::models::MutualAuthenticationsResponse, Error<ListMutualAuthenticationsError>> {
255    let local_var_configuration = configuration;
256
257    // unbox the parameters
258    let include = params.include;
259    let page_number = params.page_number;
260    let page_size = params.page_size;
261
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/tls/mutual_authentications", local_var_configuration.base_path);
266    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_str) = include {
269        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
270    }
271    if let Some(ref local_var_str) = page_number {
272        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
273    }
274    if let Some(ref local_var_str) = page_size {
275        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
276    }
277    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
278        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
279    }
280    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
281        let local_var_key = local_var_apikey.key.clone();
282        let local_var_value = match local_var_apikey.prefix {
283            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
284            None => local_var_key,
285        };
286        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
287    };
288
289    let local_var_req = local_var_req_builder.build()?;
290    let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292    if "GET" != "GET" && "GET" != "HEAD" {
293      let headers = local_var_resp.headers();
294      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
295          Some(v) => v.to_str().unwrap().parse().unwrap(),
296          None => configuration::DEFAULT_RATELIMIT,
297      };
298      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
299          Some(v) => v.to_str().unwrap().parse().unwrap(),
300          None => 0,
301      };
302    }
303
304    let local_var_status = local_var_resp.status();
305    let local_var_content = local_var_resp.text().await?;
306
307    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
308        serde_json::from_str(&local_var_content).map_err(Error::from)
309    } else {
310        let local_var_entity: Option<ListMutualAuthenticationsError> = serde_json::from_str(&local_var_content).ok();
311        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
312        Err(Error::ResponseError(local_var_error))
313    }
314}
315
316/// Update a Mutual Authentication.
317pub async fn patch_mutual_authentication(configuration: &mut configuration::Configuration, params: PatchMutualAuthenticationParams) -> Result<crate::models::MutualAuthenticationResponse, Error<PatchMutualAuthenticationError>> {
318    let local_var_configuration = configuration;
319
320    // unbox the parameters
321    let mutual_authentication_id = params.mutual_authentication_id;
322    let mutual_authentication = params.mutual_authentication;
323
324
325    let local_var_client = &local_var_configuration.client;
326
327    let local_var_uri_str = format!("{}/tls/mutual_authentications/{mutual_authentication_id}", local_var_configuration.base_path, mutual_authentication_id=crate::apis::urlencode(mutual_authentication_id));
328    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
329
330    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
331        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
332    }
333    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
334        let local_var_key = local_var_apikey.key.clone();
335        let local_var_value = match local_var_apikey.prefix {
336            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
337            None => local_var_key,
338        };
339        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
340    };
341    local_var_req_builder = local_var_req_builder.json(&mutual_authentication);
342
343    let local_var_req = local_var_req_builder.build()?;
344    let local_var_resp = local_var_client.execute(local_var_req).await?;
345
346    if "PATCH" != "GET" && "PATCH" != "HEAD" {
347      let headers = local_var_resp.headers();
348      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
349          Some(v) => v.to_str().unwrap().parse().unwrap(),
350          None => configuration::DEFAULT_RATELIMIT,
351      };
352      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
353          Some(v) => v.to_str().unwrap().parse().unwrap(),
354          None => 0,
355      };
356    }
357
358    let local_var_status = local_var_resp.status();
359    let local_var_content = local_var_resp.text().await?;
360
361    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
362        serde_json::from_str(&local_var_content).map_err(Error::from)
363    } else {
364        let local_var_entity: Option<PatchMutualAuthenticationError> = serde_json::from_str(&local_var_content).ok();
365        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
366        Err(Error::ResponseError(local_var_error))
367    }
368}
369