1use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14#[derive(Clone, Debug, Default)]
16pub struct CreateMutualTlsAuthenticationParams {
17 pub mutual_authentication: Option<crate::models::MutualAuthentication>
18}
19
20#[derive(Clone, Debug, Default)]
22pub struct DeleteMutualTlsParams {
23 pub mutual_authentication_id: String
25}
26
27#[derive(Clone, Debug, Default)]
29pub struct GetMutualAuthenticationParams {
30 pub mutual_authentication_id: String,
32 pub include: Option<String>
34}
35
36#[derive(Clone, Debug, Default)]
38pub struct ListMutualAuthenticationsParams {
39 pub include: Option<String>,
41 pub page_number: Option<i32>,
43 pub page_size: Option<i32>
45}
46
47#[derive(Clone, Debug, Default)]
49pub struct PatchMutualAuthenticationParams {
50 pub mutual_authentication_id: String,
52 pub mutual_authentication: Option<crate::models::MutualAuthentication>
53}
54
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum CreateMutualTlsAuthenticationError {
60 UnknownValue(serde_json::Value),
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum DeleteMutualTlsError {
67 UnknownValue(serde_json::Value),
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum GetMutualAuthenticationError {
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ListMutualAuthenticationsError {
81 UnknownValue(serde_json::Value),
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum PatchMutualAuthenticationError {
88 UnknownValue(serde_json::Value),
89}
90
91
92pub 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 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
145pub async fn delete_mutual_tls(configuration: &mut configuration::Configuration, params: DeleteMutualTlsParams) -> Result<(), Error<DeleteMutualTlsError>> {
147 let local_var_configuration = configuration;
148
149 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
197pub 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 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
253pub 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 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
316pub 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 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