fastly_api/apis/
secret_store_item_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_secret`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateSecretParams {
17    pub store_id: String,
18    pub secret: Option<crate::models::Secret>
19}
20
21/// struct for passing parameters to the method [`delete_secret`]
22#[derive(Clone, Debug, Default)]
23pub struct DeleteSecretParams {
24    pub store_id: String,
25    pub secret_name: String
26}
27
28/// struct for passing parameters to the method [`get_secret`]
29#[derive(Clone, Debug, Default)]
30pub struct GetSecretParams {
31    pub store_id: String,
32    pub secret_name: String
33}
34
35/// struct for passing parameters to the method [`get_secrets`]
36#[derive(Clone, Debug, Default)]
37pub struct GetSecretsParams {
38    pub store_id: String,
39    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
40    pub cursor: Option<String>,
41    /// Number of results per page. The maximum is 200.
42    pub limit: Option<String>
43}
44
45/// struct for passing parameters to the method [`must_recreate_secret`]
46#[derive(Clone, Debug, Default)]
47pub struct MustRecreateSecretParams {
48    pub store_id: String,
49    pub secret: Option<crate::models::Secret>
50}
51
52/// struct for passing parameters to the method [`recreate_secret`]
53#[derive(Clone, Debug, Default)]
54pub struct RecreateSecretParams {
55    pub store_id: String,
56    pub secret: Option<crate::models::Secret>
57}
58
59
60/// struct for typed errors of method [`create_secret`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum CreateSecretError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`delete_secret`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DeleteSecretError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`get_secret`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetSecretError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`get_secrets`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum GetSecretsError {
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`must_recreate_secret`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum MustRecreateSecretError {
92    UnknownValue(serde_json::Value),
93}
94
95/// struct for typed errors of method [`recreate_secret`]
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum RecreateSecretError {
99    UnknownValue(serde_json::Value),
100}
101
102
103/// Create a new secret in a store. Returns an error if a secret already exists with the same name. See `PUT` and `PATCH` methods for ways to recreate an existing secret.  The `secret` field must be Base64-encoded because a secret can contain binary data. In the example below, the unencoded secret is \"Hello, world!\" 
104pub async fn create_secret(configuration: &mut configuration::Configuration, params: CreateSecretParams) -> Result<crate::models::SecretResponse, Error<CreateSecretError>> {
105    let local_var_configuration = configuration;
106
107    // unbox the parameters
108    let store_id = params.store_id;
109    let secret = params.secret;
110
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
115    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
116
117    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
119    }
120    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
121        let local_var_key = local_var_apikey.key.clone();
122        let local_var_value = match local_var_apikey.prefix {
123            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
124            None => local_var_key,
125        };
126        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
127    };
128    local_var_req_builder = local_var_req_builder.json(&secret);
129
130    let local_var_req = local_var_req_builder.build()?;
131    let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133    if "POST" != "GET" && "POST" != "HEAD" {
134      let headers = local_var_resp.headers();
135      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
136          Some(v) => v.to_str().unwrap().parse().unwrap(),
137          None => configuration::DEFAULT_RATELIMIT,
138      };
139      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
140          Some(v) => v.to_str().unwrap().parse().unwrap(),
141          None => 0,
142      };
143    }
144
145    let local_var_status = local_var_resp.status();
146    let local_var_content = local_var_resp.text().await?;
147
148    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149        serde_json::from_str(&local_var_content).map_err(Error::from)
150    } else {
151        let local_var_entity: Option<CreateSecretError> = serde_json::from_str(&local_var_content).ok();
152        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
153        Err(Error::ResponseError(local_var_error))
154    }
155}
156
157/// Delete a secret from a store by name.
158pub async fn delete_secret(configuration: &mut configuration::Configuration, params: DeleteSecretParams) -> Result<(), Error<DeleteSecretError>> {
159    let local_var_configuration = configuration;
160
161    // unbox the parameters
162    let store_id = params.store_id;
163    let secret_name = params.secret_name;
164
165
166    let local_var_client = &local_var_configuration.client;
167
168    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets/{secret_name}", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id), secret_name=crate::apis::urlencode(secret_name));
169    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
170
171    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
172        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
173    }
174    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
175        let local_var_key = local_var_apikey.key.clone();
176        let local_var_value = match local_var_apikey.prefix {
177            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
178            None => local_var_key,
179        };
180        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
181    };
182
183    let local_var_req = local_var_req_builder.build()?;
184    let local_var_resp = local_var_client.execute(local_var_req).await?;
185
186    if "DELETE" != "GET" && "DELETE" != "HEAD" {
187      let headers = local_var_resp.headers();
188      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
189          Some(v) => v.to_str().unwrap().parse().unwrap(),
190          None => configuration::DEFAULT_RATELIMIT,
191      };
192      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
193          Some(v) => v.to_str().unwrap().parse().unwrap(),
194          None => 0,
195      };
196    }
197
198    let local_var_status = local_var_resp.status();
199    let local_var_content = local_var_resp.text().await?;
200
201    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
202        Ok(())
203    } else {
204        let local_var_entity: Option<DeleteSecretError> = serde_json::from_str(&local_var_content).ok();
205        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
206        Err(Error::ResponseError(local_var_error))
207    }
208}
209
210/// Get metadata about a secret by name.
211pub async fn get_secret(configuration: &mut configuration::Configuration, params: GetSecretParams) -> Result<crate::models::SecretResponse, Error<GetSecretError>> {
212    let local_var_configuration = configuration;
213
214    // unbox the parameters
215    let store_id = params.store_id;
216    let secret_name = params.secret_name;
217
218
219    let local_var_client = &local_var_configuration.client;
220
221    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets/{secret_name}", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id), secret_name=crate::apis::urlencode(secret_name));
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<GetSecretError> = 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 all secrets within a store.
264pub async fn get_secrets(configuration: &mut configuration::Configuration, params: GetSecretsParams) -> Result<crate::models::InlineResponse2006, Error<GetSecretsError>> {
265    let local_var_configuration = configuration;
266
267    // unbox the parameters
268    let store_id = params.store_id;
269    let cursor = params.cursor;
270    let limit = params.limit;
271
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_str) = cursor {
279        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
280    }
281    if let Some(ref local_var_str) = limit {
282        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
283    }
284    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
285        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
286    }
287    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
288        let local_var_key = local_var_apikey.key.clone();
289        let local_var_value = match local_var_apikey.prefix {
290            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
291            None => local_var_key,
292        };
293        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
294    };
295
296    let local_var_req = local_var_req_builder.build()?;
297    let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299    if "GET" != "GET" && "GET" != "HEAD" {
300      let headers = local_var_resp.headers();
301      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
302          Some(v) => v.to_str().unwrap().parse().unwrap(),
303          None => configuration::DEFAULT_RATELIMIT,
304      };
305      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
306          Some(v) => v.to_str().unwrap().parse().unwrap(),
307          None => 0,
308      };
309    }
310
311    let local_var_status = local_var_resp.status();
312    let local_var_content = local_var_resp.text().await?;
313
314    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315        serde_json::from_str(&local_var_content).map_err(Error::from)
316    } else {
317        let local_var_entity: Option<GetSecretsError> = serde_json::from_str(&local_var_content).ok();
318        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
319        Err(Error::ResponseError(local_var_error))
320    }
321}
322
323/// Recreate a secret based on the secret's name. Returns an error if there is no existing secret with the same name.  The `secret` field must be Base64-encoded because a secret can contain binary data. In the example below, the unencoded secret is \"Hello, world!\" 
324pub async fn must_recreate_secret(configuration: &mut configuration::Configuration, params: MustRecreateSecretParams) -> Result<crate::models::SecretResponse, Error<MustRecreateSecretError>> {
325    let local_var_configuration = configuration;
326
327    // unbox the parameters
328    let store_id = params.store_id;
329    let secret = params.secret;
330
331
332    let local_var_client = &local_var_configuration.client;
333
334    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
335    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
336
337    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
339    }
340    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
341        let local_var_key = local_var_apikey.key.clone();
342        let local_var_value = match local_var_apikey.prefix {
343            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
344            None => local_var_key,
345        };
346        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
347    };
348    local_var_req_builder = local_var_req_builder.json(&secret);
349
350    let local_var_req = local_var_req_builder.build()?;
351    let local_var_resp = local_var_client.execute(local_var_req).await?;
352
353    if "PATCH" != "GET" && "PATCH" != "HEAD" {
354      let headers = local_var_resp.headers();
355      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
356          Some(v) => v.to_str().unwrap().parse().unwrap(),
357          None => configuration::DEFAULT_RATELIMIT,
358      };
359      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
360          Some(v) => v.to_str().unwrap().parse().unwrap(),
361          None => 0,
362      };
363    }
364
365    let local_var_status = local_var_resp.status();
366    let local_var_content = local_var_resp.text().await?;
367
368    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
369        serde_json::from_str(&local_var_content).map_err(Error::from)
370    } else {
371        let local_var_entity: Option<MustRecreateSecretError> = serde_json::from_str(&local_var_content).ok();
372        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
373        Err(Error::ResponseError(local_var_error))
374    }
375}
376
377/// Create or recreate a secret based on the secret's name. The response object's `recreated` field will be true if the secret was recreated.  The `secret` field must be Base64-encoded because a secret can contain binary data. In the example below, the unencoded secret is \"Hello, world!\" 
378pub async fn recreate_secret(configuration: &mut configuration::Configuration, params: RecreateSecretParams) -> Result<crate::models::SecretResponse, Error<RecreateSecretError>> {
379    let local_var_configuration = configuration;
380
381    // unbox the parameters
382    let store_id = params.store_id;
383    let secret = params.secret;
384
385
386    let local_var_client = &local_var_configuration.client;
387
388    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}/secrets", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
389    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
390
391    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
392        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
393    }
394    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
395        let local_var_key = local_var_apikey.key.clone();
396        let local_var_value = match local_var_apikey.prefix {
397            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
398            None => local_var_key,
399        };
400        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
401    };
402    local_var_req_builder = local_var_req_builder.json(&secret);
403
404    let local_var_req = local_var_req_builder.build()?;
405    let local_var_resp = local_var_client.execute(local_var_req).await?;
406
407    if "PUT" != "GET" && "PUT" != "HEAD" {
408      let headers = local_var_resp.headers();
409      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
410          Some(v) => v.to_str().unwrap().parse().unwrap(),
411          None => configuration::DEFAULT_RATELIMIT,
412      };
413      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
414          Some(v) => v.to_str().unwrap().parse().unwrap(),
415          None => 0,
416      };
417    }
418
419    let local_var_status = local_var_resp.status();
420    let local_var_content = local_var_resp.text().await?;
421
422    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
423        serde_json::from_str(&local_var_content).map_err(Error::from)
424    } else {
425        let local_var_entity: Option<RecreateSecretError> = serde_json::from_str(&local_var_content).ok();
426        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
427        Err(Error::ResponseError(local_var_error))
428    }
429}
430