fastly_api/apis/
object_storage_access_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 [`create_access_key`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateAccessKeyParams {
17    pub access_key: Option<crate::models::AccessKey>
18}
19
20/// struct for passing parameters to the method [`delete_access_key`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteAccessKeyParams {
23    pub access_key: String
24}
25
26/// struct for passing parameters to the method [`get_access_key`]
27#[derive(Clone, Debug, Default)]
28pub struct GetAccessKeyParams {
29    pub access_key: String
30}
31
32
33/// struct for typed errors of method [`create_access_key`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum CreateAccessKeyError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`delete_access_key`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum DeleteAccessKeyError {
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`get_access_key`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetAccessKeyError {
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`list_access_keys`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ListAccessKeysError {
58    UnknownValue(serde_json::Value),
59}
60
61
62/// Create an access key.
63pub async fn create_access_key(configuration: &mut configuration::Configuration, params: CreateAccessKeyParams) -> Result<crate::models::AccessKeyResponse, Error<CreateAccessKeyError>> {
64    let local_var_configuration = configuration;
65
66    // unbox the parameters
67    let access_key = params.access_key;
68
69
70    let local_var_client = &local_var_configuration.client;
71
72    let local_var_uri_str = format!("{}/resources/object-storage/access-keys", local_var_configuration.base_path);
73    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
74
75    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
76        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
77    }
78    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
79        let local_var_key = local_var_apikey.key.clone();
80        let local_var_value = match local_var_apikey.prefix {
81            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
82            None => local_var_key,
83        };
84        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
85    };
86    local_var_req_builder = local_var_req_builder.json(&access_key);
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    if "POST" != "GET" && "POST" != "HEAD" {
92      let headers = local_var_resp.headers();
93      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
94          Some(v) => v.to_str().unwrap().parse().unwrap(),
95          None => configuration::DEFAULT_RATELIMIT,
96      };
97      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
98          Some(v) => v.to_str().unwrap().parse().unwrap(),
99          None => 0,
100      };
101    }
102
103    let local_var_status = local_var_resp.status();
104    let local_var_content = local_var_resp.text().await?;
105
106    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107        serde_json::from_str(&local_var_content).map_err(Error::from)
108    } else {
109        let local_var_entity: Option<CreateAccessKeyError> = serde_json::from_str(&local_var_content).ok();
110        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111        Err(Error::ResponseError(local_var_error))
112    }
113}
114
115/// Delete an access key.
116pub async fn delete_access_key(configuration: &mut configuration::Configuration, params: DeleteAccessKeyParams) -> Result<(), Error<DeleteAccessKeyError>> {
117    let local_var_configuration = configuration;
118
119    // unbox the parameters
120    let access_key = params.access_key;
121
122
123    let local_var_client = &local_var_configuration.client;
124
125    let local_var_uri_str = format!("{}/resources/object-storage/access-keys/{access_key}", local_var_configuration.base_path, access_key=crate::apis::urlencode(access_key));
126    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
127
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130    }
131    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
132        let local_var_key = local_var_apikey.key.clone();
133        let local_var_value = match local_var_apikey.prefix {
134            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
135            None => local_var_key,
136        };
137        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
138    };
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 "DELETE" != "GET" && "DELETE" != "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        Ok(())
160    } else {
161        let local_var_entity: Option<DeleteAccessKeyError> = 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/// Get an access key by its identifier.
168pub async fn get_access_key(configuration: &mut configuration::Configuration, params: GetAccessKeyParams) -> Result<crate::models::AccessKey, Error<GetAccessKeyError>> {
169    let local_var_configuration = configuration;
170
171    // unbox the parameters
172    let access_key = params.access_key;
173
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!("{}/resources/object-storage/access-keys/{access_key}", local_var_configuration.base_path, access_key=crate::apis::urlencode(access_key));
178    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, 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 "GET" != "GET" && "GET" != "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        serde_json::from_str(&local_var_content).map_err(Error::from)
212    } else {
213        let local_var_entity: Option<GetAccessKeyError> = 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/// List access keys.
220pub async fn list_access_keys(configuration: &mut configuration::Configuration) -> Result<crate::models::AccessKeyResponse, Error<ListAccessKeysError>> {
221    let local_var_configuration = configuration;
222
223    // unbox the parameters
224
225
226    let local_var_client = &local_var_configuration.client;
227
228    let local_var_uri_str = format!("{}/resources/object-storage/access-keys", local_var_configuration.base_path);
229    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
230
231    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
232        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
233    }
234    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
235        let local_var_key = local_var_apikey.key.clone();
236        let local_var_value = match local_var_apikey.prefix {
237            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
238            None => local_var_key,
239        };
240        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
241    };
242
243    let local_var_req = local_var_req_builder.build()?;
244    let local_var_resp = local_var_client.execute(local_var_req).await?;
245
246    if "GET" != "GET" && "GET" != "HEAD" {
247      let headers = local_var_resp.headers();
248      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
249          Some(v) => v.to_str().unwrap().parse().unwrap(),
250          None => configuration::DEFAULT_RATELIMIT,
251      };
252      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
253          Some(v) => v.to_str().unwrap().parse().unwrap(),
254          None => 0,
255      };
256    }
257
258    let local_var_status = local_var_resp.status();
259    let local_var_content = local_var_resp.text().await?;
260
261    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
262        serde_json::from_str(&local_var_content).map_err(Error::from)
263    } else {
264        let local_var_entity: Option<ListAccessKeysError> = serde_json::from_str(&local_var_content).ok();
265        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
266        Err(Error::ResponseError(local_var_error))
267    }
268}
269