Skip to main content

fastly_api/apis/
ai_runtime_control_provider_connections_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_provider_connection`]
15#[derive(Clone, Debug, Default)]
16pub struct ArcCreateProviderConnectionParams {
17    pub arc_provider_connection_request: crate::models::ArcProviderConnectionRequest
18}
19
20/// struct for passing parameters to the method [`arc_delete_provider_connection`]
21#[derive(Clone, Debug, Default)]
22pub struct ArcDeleteProviderConnectionParams {
23    /// The ID of the provider connection.
24    pub id: String
25}
26
27/// struct for passing parameters to the method [`arc_get_provider_connection`]
28#[derive(Clone, Debug, Default)]
29pub struct ArcGetProviderConnectionParams {
30    /// The ID of the provider connection.
31    pub id: String
32}
33
34/// struct for passing parameters to the method [`arc_list_provider_connections`]
35#[derive(Clone, Debug, Default)]
36pub struct ArcListProviderConnectionsParams {
37    /// Include deleted provider connections in the results. Deleted connections have a `deleted_at` value.
38    pub include_deleted: Option<bool>,
39    /// Sort field. Prefix with `-` for descending order (e.g., `sort=-name`). 
40    pub sort: Option<String>
41}
42
43/// struct for passing parameters to the method [`arc_update_provider_connection`]
44#[derive(Clone, Debug, Default)]
45pub struct ArcUpdateProviderConnectionParams {
46    /// The ID of the provider connection.
47    pub id: String,
48    pub arc_update_provider_connection_request: crate::models::ArcUpdateProviderConnectionRequest
49}
50
51
52/// struct for typed errors of method [`arc_create_provider_connection`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ArcCreateProviderConnectionError {
56    Status400(crate::models::ArcError),
57    Status401(crate::models::ArcError),
58    Status403(crate::models::ArcError),
59    Status409(crate::models::ArcError),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`arc_delete_provider_connection`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum ArcDeleteProviderConnectionError {
67    Status401(crate::models::ArcError),
68    Status403(crate::models::ArcError),
69    Status404(crate::models::ArcError),
70    Status409(crate::models::ArcError),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`arc_get_provider_connection`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ArcGetProviderConnectionError {
78    Status401(crate::models::ArcError),
79    Status403(crate::models::ArcError),
80    Status404(crate::models::ArcError),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`arc_list_provider_connections`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum ArcListProviderConnectionsError {
88    Status401(crate::models::ArcError),
89    Status403(crate::models::ArcError),
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`arc_update_provider_connection`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum ArcUpdateProviderConnectionError {
97    Status400(crate::models::ArcError),
98    Status401(crate::models::ArcError),
99    Status403(crate::models::ArcError),
100    Status404(crate::models::ArcError),
101    Status409(crate::models::ArcError),
102    UnknownValue(serde_json::Value),
103}
104
105
106/// Create a provider connection. Set `auth_type` to `api-key` (the default) to connect with a provider's own API key, or to `aws-iam` to connect to Amazon Bedrock using an AWS IAM role.  Accounts are limited to 25 provider connections. Creating a 26th connection returns a 409 response. 
107pub async fn arc_create_provider_connection(configuration: &mut configuration::Configuration, params: ArcCreateProviderConnectionParams) -> Result<crate::models::ArcProviderConnectionResponse, Error<ArcCreateProviderConnectionError>> {
108    let local_var_configuration = configuration;
109
110    // unbox the parameters
111    let arc_provider_connection_request = params.arc_provider_connection_request;
112
113
114    let local_var_client = &local_var_configuration.client;
115
116    let local_var_uri_str = format!("{}/ai-runtime-control/v1/provider-connections", local_var_configuration.base_path);
117    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
118
119    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
120        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
121    }
122    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
123        let local_var_key = local_var_apikey.key.clone();
124        let local_var_value = match local_var_apikey.prefix {
125            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
126            None => local_var_key,
127        };
128        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
129    };
130    local_var_req_builder = local_var_req_builder.json(&arc_provider_connection_request);
131
132    let local_var_req = local_var_req_builder.build()?;
133    let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135    if "POST" != "GET" && "POST" != "HEAD" {
136      let headers = local_var_resp.headers();
137      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
138          Some(v) => v.to_str().unwrap().parse().unwrap(),
139          None => configuration::DEFAULT_RATELIMIT,
140      };
141      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
142          Some(v) => v.to_str().unwrap().parse().unwrap(),
143          None => 0,
144      };
145    }
146
147    let local_var_status = local_var_resp.status();
148    let local_var_content = local_var_resp.text().await?;
149
150    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
151        serde_json::from_str(&local_var_content).map_err(Error::from)
152    } else {
153        let local_var_entity: Option<ArcCreateProviderConnectionError> = serde_json::from_str(&local_var_content).ok();
154        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
155        Err(Error::ResponseError(local_var_error))
156    }
157}
158
159/// Delete a provider connection. Returns a 409 response if the connection is still referenced by a virtual key's failover policy. 
160pub async fn arc_delete_provider_connection(configuration: &mut configuration::Configuration, params: ArcDeleteProviderConnectionParams) -> Result<(), Error<ArcDeleteProviderConnectionError>> {
161    let local_var_configuration = configuration;
162
163    // unbox the parameters
164    let id = params.id;
165
166
167    let local_var_client = &local_var_configuration.client;
168
169    let local_var_uri_str = format!("{}/ai-runtime-control/v1/provider-connections/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
170    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
171
172    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174    }
175    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
176        let local_var_key = local_var_apikey.key.clone();
177        let local_var_value = match local_var_apikey.prefix {
178            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
179            None => local_var_key,
180        };
181        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
182    };
183
184    let local_var_req = local_var_req_builder.build()?;
185    let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187    if "DELETE" != "GET" && "DELETE" != "HEAD" {
188      let headers = local_var_resp.headers();
189      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
190          Some(v) => v.to_str().unwrap().parse().unwrap(),
191          None => configuration::DEFAULT_RATELIMIT,
192      };
193      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
194          Some(v) => v.to_str().unwrap().parse().unwrap(),
195          None => 0,
196      };
197    }
198
199    let local_var_status = local_var_resp.status();
200    let local_var_content = local_var_resp.text().await?;
201
202    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
203        Ok(())
204    } else {
205        let local_var_entity: Option<ArcDeleteProviderConnectionError> = serde_json::from_str(&local_var_content).ok();
206        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
207        Err(Error::ResponseError(local_var_error))
208    }
209}
210
211/// Retrieve a single provider connection.
212pub async fn arc_get_provider_connection(configuration: &mut configuration::Configuration, params: ArcGetProviderConnectionParams) -> Result<crate::models::ArcGetProviderConnectionResponse, Error<ArcGetProviderConnectionError>> {
213    let local_var_configuration = configuration;
214
215    // unbox the parameters
216    let id = params.id;
217
218
219    let local_var_client = &local_var_configuration.client;
220
221    let local_var_uri_str = format!("{}/ai-runtime-control/v1/provider-connections/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
222    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
223
224    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
225        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
228        let local_var_key = local_var_apikey.key.clone();
229        let local_var_value = match local_var_apikey.prefix {
230            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
231            None => local_var_key,
232        };
233        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
234    };
235
236    let local_var_req = local_var_req_builder.build()?;
237    let local_var_resp = local_var_client.execute(local_var_req).await?;
238
239    if "GET" != "GET" && "GET" != "HEAD" {
240      let headers = local_var_resp.headers();
241      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
242          Some(v) => v.to_str().unwrap().parse().unwrap(),
243          None => configuration::DEFAULT_RATELIMIT,
244      };
245      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
246          Some(v) => v.to_str().unwrap().parse().unwrap(),
247          None => 0,
248      };
249    }
250
251    let local_var_status = local_var_resp.status();
252    let local_var_content = local_var_resp.text().await?;
253
254    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255        serde_json::from_str(&local_var_content).map_err(Error::from)
256    } else {
257        let local_var_entity: Option<ArcGetProviderConnectionError> = serde_json::from_str(&local_var_content).ok();
258        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
259        Err(Error::ResponseError(local_var_error))
260    }
261}
262
263/// List the provider connections belonging to your account.
264pub async fn arc_list_provider_connections(configuration: &mut configuration::Configuration, params: ArcListProviderConnectionsParams) -> Result<crate::models::ArcProviderConnectionsResponse, Error<ArcListProviderConnectionsError>> {
265    let local_var_configuration = configuration;
266
267    // unbox the parameters
268    let include_deleted = params.include_deleted;
269    let sort = params.sort;
270
271
272    let local_var_client = &local_var_configuration.client;
273
274    let local_var_uri_str = format!("{}/ai-runtime-control/v1/provider-connections", local_var_configuration.base_path);
275    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
276
277    if let Some(ref local_var_str) = include_deleted {
278        local_var_req_builder = local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
279    }
280    if let Some(ref local_var_str) = sort {
281        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
282    }
283    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
284        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
285    }
286    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
287        let local_var_key = local_var_apikey.key.clone();
288        let local_var_value = match local_var_apikey.prefix {
289            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
290            None => local_var_key,
291        };
292        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
293    };
294
295    let local_var_req = local_var_req_builder.build()?;
296    let local_var_resp = local_var_client.execute(local_var_req).await?;
297
298    if "GET" != "GET" && "GET" != "HEAD" {
299      let headers = local_var_resp.headers();
300      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
301          Some(v) => v.to_str().unwrap().parse().unwrap(),
302          None => configuration::DEFAULT_RATELIMIT,
303      };
304      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
305          Some(v) => v.to_str().unwrap().parse().unwrap(),
306          None => 0,
307      };
308    }
309
310    let local_var_status = local_var_resp.status();
311    let local_var_content = local_var_resp.text().await?;
312
313    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
314        serde_json::from_str(&local_var_content).map_err(Error::from)
315    } else {
316        let local_var_entity: Option<ArcListProviderConnectionsError> = serde_json::from_str(&local_var_content).ok();
317        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
318        Err(Error::ResponseError(local_var_error))
319    }
320}
321
322/// Update the attributes of a provider connection. Only the fields you include are changed. Which fields you can set depends on the connection's existing `auth_type`: `base_url` and `api_key` apply only to `api-key` connections, and `customer_role_arn` and `region` apply only to `aws-iam` connections. `auth_type` itself cannot be changed. 
323pub async fn arc_update_provider_connection(configuration: &mut configuration::Configuration, params: ArcUpdateProviderConnectionParams) -> Result<crate::models::ArcProviderConnectionResponse, Error<ArcUpdateProviderConnectionError>> {
324    let local_var_configuration = configuration;
325
326    // unbox the parameters
327    let id = params.id;
328    let arc_update_provider_connection_request = params.arc_update_provider_connection_request;
329
330
331    let local_var_client = &local_var_configuration.client;
332
333    let local_var_uri_str = format!("{}/ai-runtime-control/v1/provider-connections/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
334    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
335
336    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
337        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
338    }
339    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
340        let local_var_key = local_var_apikey.key.clone();
341        let local_var_value = match local_var_apikey.prefix {
342            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
343            None => local_var_key,
344        };
345        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
346    };
347    local_var_req_builder = local_var_req_builder.json(&arc_update_provider_connection_request);
348
349    let local_var_req = local_var_req_builder.build()?;
350    let local_var_resp = local_var_client.execute(local_var_req).await?;
351
352    if "PATCH" != "GET" && "PATCH" != "HEAD" {
353      let headers = local_var_resp.headers();
354      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
355          Some(v) => v.to_str().unwrap().parse().unwrap(),
356          None => configuration::DEFAULT_RATELIMIT,
357      };
358      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
359          Some(v) => v.to_str().unwrap().parse().unwrap(),
360          None => 0,
361      };
362    }
363
364    let local_var_status = local_var_resp.status();
365    let local_var_content = local_var_resp.text().await?;
366
367    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
368        serde_json::from_str(&local_var_content).map_err(Error::from)
369    } else {
370        let local_var_entity: Option<ArcUpdateProviderConnectionError> = serde_json::from_str(&local_var_content).ok();
371        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
372        Err(Error::ResponseError(local_var_error))
373    }
374}
375