Skip to main content

fastly_api/apis/
ai_runtime_control_virtual_keys_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 [`arc_create_virtual_key`]
15#[derive(Clone, Debug, Default)]
16pub struct ArcCreateVirtualKeyParams {
17    pub arc_virtual_key: crate::models::ArcVirtualKey
18}
19
20/// struct for passing parameters to the method [`arc_delete_virtual_key`]
21#[derive(Clone, Debug, Default)]
22pub struct ArcDeleteVirtualKeyParams {
23    /// The ID of the virtual key.
24    pub key_id: String
25}
26
27/// struct for passing parameters to the method [`arc_get_virtual_key`]
28#[derive(Clone, Debug, Default)]
29pub struct ArcGetVirtualKeyParams {
30    /// The ID of the virtual key.
31    pub key_id: String
32}
33
34/// struct for passing parameters to the method [`arc_get_virtual_key_failover`]
35#[derive(Clone, Debug, Default)]
36pub struct ArcGetVirtualKeyFailoverParams {
37    /// The ID of the virtual key.
38    pub key_id: String
39}
40
41/// struct for passing parameters to the method [`arc_list_virtual_keys`]
42#[derive(Clone, Debug, Default)]
43pub struct ArcListVirtualKeysParams {
44    /// Include deleted virtual keys in the results.
45    pub include_deleted: Option<bool>,
46    /// Filter results to virtual keys whose name contains this substring.
47    pub search: Option<String>,
48    /// Cursor for pagination. Use the `next_cursor` value from a previous response to request the next page of results, or the `prev_cursor` value to request the previous page. 
49    pub cursor: Option<String>,
50    /// Limit how many results are returned.
51    pub limit: Option<i32>,
52    /// Sort field. Prefix with `-` for descending order (e.g., `sort=-created_at`). 
53    pub sort: Option<String>
54}
55
56/// struct for passing parameters to the method [`arc_rotate_virtual_key`]
57#[derive(Clone, Debug, Default)]
58pub struct ArcRotateVirtualKeyParams {
59    /// The ID of the virtual key.
60    pub key_id: String,
61    pub arc_rotate_virtual_key_request: Option<crate::models::ArcRotateVirtualKeyRequest>
62}
63
64/// struct for passing parameters to the method [`arc_update_virtual_key`]
65#[derive(Clone, Debug, Default)]
66pub struct ArcUpdateVirtualKeyParams {
67    /// The ID of the virtual key.
68    pub key_id: String,
69    pub arc_update_virtual_key_request: crate::models::ArcUpdateVirtualKeyRequest
70}
71
72/// struct for passing parameters to the method [`arc_update_virtual_key_failover`]
73#[derive(Clone, Debug, Default)]
74pub struct ArcUpdateVirtualKeyFailoverParams {
75    /// The ID of the virtual key.
76    pub key_id: String,
77    pub arc_virtual_key_failover_request: crate::models::ArcVirtualKeyFailoverRequest
78}
79
80
81/// struct for typed errors of method [`arc_create_virtual_key`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ArcCreateVirtualKeyError {
85    Status400(crate::models::ArcError),
86    Status401(crate::models::ArcError),
87    Status403(crate::models::ArcError),
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`arc_delete_virtual_key`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum ArcDeleteVirtualKeyError {
95    Status401(crate::models::ArcError),
96    Status403(crate::models::ArcError),
97    Status404(crate::models::ArcError),
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`arc_get_virtual_key`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum ArcGetVirtualKeyError {
105    Status401(crate::models::ArcError),
106    Status403(crate::models::ArcError),
107    Status404(crate::models::ArcError),
108    UnknownValue(serde_json::Value),
109}
110
111/// struct for typed errors of method [`arc_get_virtual_key_failover`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum ArcGetVirtualKeyFailoverError {
115    Status401(crate::models::ArcError),
116    Status403(crate::models::ArcError),
117    Status404(crate::models::ArcError),
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`arc_list_virtual_keys`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum ArcListVirtualKeysError {
125    Status401(crate::models::ArcError),
126    Status403(crate::models::ArcError),
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`arc_rotate_virtual_key`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum ArcRotateVirtualKeyError {
134    Status400(crate::models::ArcError),
135    Status401(crate::models::ArcError),
136    Status403(crate::models::ArcError),
137    Status404(crate::models::ArcError),
138    UnknownValue(serde_json::Value),
139}
140
141/// struct for typed errors of method [`arc_update_virtual_key`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum ArcUpdateVirtualKeyError {
145    Status400(crate::models::ArcError),
146    Status401(crate::models::ArcError),
147    Status403(crate::models::ArcError),
148    Status404(crate::models::ArcError),
149    UnknownValue(serde_json::Value),
150}
151
152/// struct for typed errors of method [`arc_update_virtual_key_failover`]
153#[derive(Debug, Clone, Serialize, Deserialize)]
154#[serde(untagged)]
155pub enum ArcUpdateVirtualKeyFailoverError {
156    Status400(crate::models::ArcError),
157    Status401(crate::models::ArcError),
158    Status403(crate::models::ArcError),
159    Status404(crate::models::ArcError),
160    UnknownValue(serde_json::Value),
161}
162
163
164/// Create a new virtual key for authenticating requests through the AI Runtime Control gateway.
165pub async fn arc_create_virtual_key(configuration: &mut configuration::Configuration, params: ArcCreateVirtualKeyParams) -> Result<crate::models::ArcCreateVirtualKeyResponse, Error<ArcCreateVirtualKeyError>> {
166    let local_var_configuration = configuration;
167
168    // unbox the parameters
169    let arc_virtual_key = params.arc_virtual_key;
170
171
172    let local_var_client = &local_var_configuration.client;
173
174    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys", local_var_configuration.base_path);
175    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
176
177    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
178        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
179    }
180    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
181        let local_var_key = local_var_apikey.key.clone();
182        let local_var_value = match local_var_apikey.prefix {
183            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
184            None => local_var_key,
185        };
186        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
187    };
188    local_var_req_builder = local_var_req_builder.json(&arc_virtual_key);
189
190    let local_var_req = local_var_req_builder.build()?;
191    let local_var_resp = local_var_client.execute(local_var_req).await?;
192
193    if "POST" != "GET" && "POST" != "HEAD" {
194      let headers = local_var_resp.headers();
195      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
196          Some(v) => v.to_str().unwrap().parse().unwrap(),
197          None => configuration::DEFAULT_RATELIMIT,
198      };
199      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
200          Some(v) => v.to_str().unwrap().parse().unwrap(),
201          None => 0,
202      };
203    }
204
205    let local_var_status = local_var_resp.status();
206    let local_var_content = local_var_resp.text().await?;
207
208    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
209        serde_json::from_str(&local_var_content).map_err(Error::from)
210    } else {
211        let local_var_entity: Option<ArcCreateVirtualKeyError> = serde_json::from_str(&local_var_content).ok();
212        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
213        Err(Error::ResponseError(local_var_error))
214    }
215}
216
217/// Delete a virtual key. This also deletes any security configuration associated with the key.
218pub async fn arc_delete_virtual_key(configuration: &mut configuration::Configuration, params: ArcDeleteVirtualKeyParams) -> Result<(), Error<ArcDeleteVirtualKeyError>> {
219    let local_var_configuration = configuration;
220
221    // unbox the parameters
222    let key_id = params.key_id;
223
224
225    let local_var_client = &local_var_configuration.client;
226
227    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
228    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
229
230    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
231        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
232    }
233    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
234        let local_var_key = local_var_apikey.key.clone();
235        let local_var_value = match local_var_apikey.prefix {
236            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
237            None => local_var_key,
238        };
239        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
240    };
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    if "DELETE" != "GET" && "DELETE" != "HEAD" {
246      let headers = local_var_resp.headers();
247      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
248          Some(v) => v.to_str().unwrap().parse().unwrap(),
249          None => configuration::DEFAULT_RATELIMIT,
250      };
251      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
252          Some(v) => v.to_str().unwrap().parse().unwrap(),
253          None => 0,
254      };
255    }
256
257    let local_var_status = local_var_resp.status();
258    let local_var_content = local_var_resp.text().await?;
259
260    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
261        Ok(())
262    } else {
263        let local_var_entity: Option<ArcDeleteVirtualKeyError> = serde_json::from_str(&local_var_content).ok();
264        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
265        Err(Error::ResponseError(local_var_error))
266    }
267}
268
269/// Retrieve a single virtual key.
270pub async fn arc_get_virtual_key(configuration: &mut configuration::Configuration, params: ArcGetVirtualKeyParams) -> Result<crate::models::ArcVirtualKeyResponse, Error<ArcGetVirtualKeyError>> {
271    let local_var_configuration = configuration;
272
273    // unbox the parameters
274    let key_id = params.key_id;
275
276
277    let local_var_client = &local_var_configuration.client;
278
279    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
280    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
281
282    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284    }
285    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
286        let local_var_key = local_var_apikey.key.clone();
287        let local_var_value = match local_var_apikey.prefix {
288            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
289            None => local_var_key,
290        };
291        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
292    };
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    if "GET" != "GET" && "GET" != "HEAD" {
298      let headers = local_var_resp.headers();
299      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
300          Some(v) => v.to_str().unwrap().parse().unwrap(),
301          None => configuration::DEFAULT_RATELIMIT,
302      };
303      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
304          Some(v) => v.to_str().unwrap().parse().unwrap(),
305          None => 0,
306      };
307    }
308
309    let local_var_status = local_var_resp.status();
310    let local_var_content = local_var_resp.text().await?;
311
312    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
313        serde_json::from_str(&local_var_content).map_err(Error::from)
314    } else {
315        let local_var_entity: Option<ArcGetVirtualKeyError> = serde_json::from_str(&local_var_content).ok();
316        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
317        Err(Error::ResponseError(local_var_error))
318    }
319}
320
321/// Retrieve the failover policy for a virtual key. A failover policy lists alternate provider connections to retry a request against, and which error conditions trigger a retry.  Failover is a per-account feature. If it isn't enabled on your account, this endpoint returns a 404 response. 
322pub async fn arc_get_virtual_key_failover(configuration: &mut configuration::Configuration, params: ArcGetVirtualKeyFailoverParams) -> Result<crate::models::ArcVirtualKeyFailoverResponse, Error<ArcGetVirtualKeyFailoverError>> {
323    let local_var_configuration = configuration;
324
325    // unbox the parameters
326    let key_id = params.key_id;
327
328
329    let local_var_client = &local_var_configuration.client;
330
331    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}/failover", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
332    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
333
334    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
335        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
336    }
337    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
338        let local_var_key = local_var_apikey.key.clone();
339        let local_var_value = match local_var_apikey.prefix {
340            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
341            None => local_var_key,
342        };
343        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
344    };
345
346    let local_var_req = local_var_req_builder.build()?;
347    let local_var_resp = local_var_client.execute(local_var_req).await?;
348
349    if "GET" != "GET" && "GET" != "HEAD" {
350      let headers = local_var_resp.headers();
351      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
352          Some(v) => v.to_str().unwrap().parse().unwrap(),
353          None => configuration::DEFAULT_RATELIMIT,
354      };
355      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
356          Some(v) => v.to_str().unwrap().parse().unwrap(),
357          None => 0,
358      };
359    }
360
361    let local_var_status = local_var_resp.status();
362    let local_var_content = local_var_resp.text().await?;
363
364    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
365        serde_json::from_str(&local_var_content).map_err(Error::from)
366    } else {
367        let local_var_entity: Option<ArcGetVirtualKeyFailoverError> = serde_json::from_str(&local_var_content).ok();
368        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
369        Err(Error::ResponseError(local_var_error))
370    }
371}
372
373/// List the virtual keys belonging to your account.
374pub async fn arc_list_virtual_keys(configuration: &mut configuration::Configuration, params: ArcListVirtualKeysParams) -> Result<crate::models::ArcVirtualKeysResponse, Error<ArcListVirtualKeysError>> {
375    let local_var_configuration = configuration;
376
377    // unbox the parameters
378    let include_deleted = params.include_deleted;
379    let search = params.search;
380    let cursor = params.cursor;
381    let limit = params.limit;
382    let sort = params.sort;
383
384
385    let local_var_client = &local_var_configuration.client;
386
387    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys", local_var_configuration.base_path);
388    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
389
390    if let Some(ref local_var_str) = include_deleted {
391        local_var_req_builder = local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
392    }
393    if let Some(ref local_var_str) = search {
394        local_var_req_builder = local_var_req_builder.query(&[("search", &local_var_str.to_string())]);
395    }
396    if let Some(ref local_var_str) = cursor {
397        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
398    }
399    if let Some(ref local_var_str) = limit {
400        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
401    }
402    if let Some(ref local_var_str) = sort {
403        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
404    }
405    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
406        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
407    }
408    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
409        let local_var_key = local_var_apikey.key.clone();
410        let local_var_value = match local_var_apikey.prefix {
411            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
412            None => local_var_key,
413        };
414        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
415    };
416
417    let local_var_req = local_var_req_builder.build()?;
418    let local_var_resp = local_var_client.execute(local_var_req).await?;
419
420    if "GET" != "GET" && "GET" != "HEAD" {
421      let headers = local_var_resp.headers();
422      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
423          Some(v) => v.to_str().unwrap().parse().unwrap(),
424          None => configuration::DEFAULT_RATELIMIT,
425      };
426      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
427          Some(v) => v.to_str().unwrap().parse().unwrap(),
428          None => 0,
429      };
430    }
431
432    let local_var_status = local_var_resp.status();
433    let local_var_content = local_var_resp.text().await?;
434
435    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
436        serde_json::from_str(&local_var_content).map_err(Error::from)
437    } else {
438        let local_var_entity: Option<ArcListVirtualKeysError> = serde_json::from_str(&local_var_content).ok();
439        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
440        Err(Error::ResponseError(local_var_error))
441    }
442}
443
444/// Issue a new access token for a virtual key, invalidating the previous one.
445pub async fn arc_rotate_virtual_key(configuration: &mut configuration::Configuration, params: ArcRotateVirtualKeyParams) -> Result<crate::models::ArcRotateVirtualKeyResponse, Error<ArcRotateVirtualKeyError>> {
446    let local_var_configuration = configuration;
447
448    // unbox the parameters
449    let key_id = params.key_id;
450    let arc_rotate_virtual_key_request = params.arc_rotate_virtual_key_request;
451
452
453    let local_var_client = &local_var_configuration.client;
454
455    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}/rotate", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
456    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
457
458    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
459        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
460    }
461    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
462        let local_var_key = local_var_apikey.key.clone();
463        let local_var_value = match local_var_apikey.prefix {
464            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
465            None => local_var_key,
466        };
467        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
468    };
469    local_var_req_builder = local_var_req_builder.json(&arc_rotate_virtual_key_request);
470
471    let local_var_req = local_var_req_builder.build()?;
472    let local_var_resp = local_var_client.execute(local_var_req).await?;
473
474    if "POST" != "GET" && "POST" != "HEAD" {
475      let headers = local_var_resp.headers();
476      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
477          Some(v) => v.to_str().unwrap().parse().unwrap(),
478          None => configuration::DEFAULT_RATELIMIT,
479      };
480      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
481          Some(v) => v.to_str().unwrap().parse().unwrap(),
482          None => 0,
483      };
484    }
485
486    let local_var_status = local_var_resp.status();
487    let local_var_content = local_var_resp.text().await?;
488
489    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
490        serde_json::from_str(&local_var_content).map_err(Error::from)
491    } else {
492        let local_var_entity: Option<ArcRotateVirtualKeyError> = serde_json::from_str(&local_var_content).ok();
493        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
494        Err(Error::ResponseError(local_var_error))
495    }
496}
497
498/// Update the attributes of a virtual key. Only the fields you include are changed.
499pub async fn arc_update_virtual_key(configuration: &mut configuration::Configuration, params: ArcUpdateVirtualKeyParams) -> Result<crate::models::ArcUpdateVirtualKeyResponse, Error<ArcUpdateVirtualKeyError>> {
500    let local_var_configuration = configuration;
501
502    // unbox the parameters
503    let key_id = params.key_id;
504    let arc_update_virtual_key_request = params.arc_update_virtual_key_request;
505
506
507    let local_var_client = &local_var_configuration.client;
508
509    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
510    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
511
512    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
513        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
514    }
515    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
516        let local_var_key = local_var_apikey.key.clone();
517        let local_var_value = match local_var_apikey.prefix {
518            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
519            None => local_var_key,
520        };
521        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
522    };
523    local_var_req_builder = local_var_req_builder.json(&arc_update_virtual_key_request);
524
525    let local_var_req = local_var_req_builder.build()?;
526    let local_var_resp = local_var_client.execute(local_var_req).await?;
527
528    if "PATCH" != "GET" && "PATCH" != "HEAD" {
529      let headers = local_var_resp.headers();
530      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
531          Some(v) => v.to_str().unwrap().parse().unwrap(),
532          None => configuration::DEFAULT_RATELIMIT,
533      };
534      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
535          Some(v) => v.to_str().unwrap().parse().unwrap(),
536          None => 0,
537      };
538    }
539
540    let local_var_status = local_var_resp.status();
541    let local_var_content = local_var_resp.text().await?;
542
543    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
544        serde_json::from_str(&local_var_content).map_err(Error::from)
545    } else {
546        let local_var_entity: Option<ArcUpdateVirtualKeyError> = serde_json::from_str(&local_var_content).ok();
547        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
548        Err(Error::ResponseError(local_var_error))
549    }
550}
551
552/// Replace the failover policy for a virtual key.  Failover is a per-account feature. If it isn't enabled on your account, this endpoint returns a 404 response. 
553pub async fn arc_update_virtual_key_failover(configuration: &mut configuration::Configuration, params: ArcUpdateVirtualKeyFailoverParams) -> Result<crate::models::ArcVirtualKeyFailoverResponse, Error<ArcUpdateVirtualKeyFailoverError>> {
554    let local_var_configuration = configuration;
555
556    // unbox the parameters
557    let key_id = params.key_id;
558    let arc_virtual_key_failover_request = params.arc_virtual_key_failover_request;
559
560
561    let local_var_client = &local_var_configuration.client;
562
563    let local_var_uri_str = format!("{}/ai-runtime-control/v1/keys/{key_id}/failover", local_var_configuration.base_path, key_id=crate::apis::urlencode(key_id));
564    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
565
566    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
567        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
568    }
569    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
570        let local_var_key = local_var_apikey.key.clone();
571        let local_var_value = match local_var_apikey.prefix {
572            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
573            None => local_var_key,
574        };
575        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
576    };
577    local_var_req_builder = local_var_req_builder.json(&arc_virtual_key_failover_request);
578
579    let local_var_req = local_var_req_builder.build()?;
580    let local_var_resp = local_var_client.execute(local_var_req).await?;
581
582    if "PUT" != "GET" && "PUT" != "HEAD" {
583      let headers = local_var_resp.headers();
584      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
585          Some(v) => v.to_str().unwrap().parse().unwrap(),
586          None => configuration::DEFAULT_RATELIMIT,
587      };
588      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
589          Some(v) => v.to_str().unwrap().parse().unwrap(),
590          None => 0,
591      };
592    }
593
594    let local_var_status = local_var_resp.status();
595    let local_var_content = local_var_resp.text().await?;
596
597    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
598        serde_json::from_str(&local_var_content).map_err(Error::from)
599    } else {
600        let local_var_entity: Option<ArcUpdateVirtualKeyFailoverError> = serde_json::from_str(&local_var_content).ok();
601        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
602        Err(Error::ResponseError(local_var_error))
603    }
604}
605