fastly_api/apis/
secret_store_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_store`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateSecretStoreParams {
17    pub secret_store: Option<crate::models::SecretStore>
18}
19
20/// struct for passing parameters to the method [`delete_secret_store`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteSecretStoreParams {
23    pub store_id: String
24}
25
26/// struct for passing parameters to the method [`get_secret_store`]
27#[derive(Clone, Debug, Default)]
28pub struct GetSecretStoreParams {
29    pub store_id: String
30}
31
32/// struct for passing parameters to the method [`get_secret_stores`]
33#[derive(Clone, Debug, Default)]
34pub struct GetSecretStoresParams {
35    /// 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.
36    pub cursor: Option<String>,
37    /// Number of results per page. The maximum is 200.
38    pub limit: Option<String>,
39    /// Returns a one-element array containing the details for the named secret store.
40    pub name: Option<String>
41}
42
43
44/// struct for typed errors of method [`client_key`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum ClientKeyError {
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`create_secret_store`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum CreateSecretStoreError {
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`delete_secret_store`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum DeleteSecretStoreError {
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method [`get_secret_store`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetSecretStoreError {
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`get_secret_stores`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum GetSecretStoresError {
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`signing_key`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum SigningKeyError {
83    UnknownValue(serde_json::Value),
84}
85
86
87/// Create a new client key for encrypting secrets locally before uploading.
88pub async fn client_key(configuration: &mut configuration::Configuration) -> Result<crate::models::ClientKey, Error<ClientKeyError>> {
89    let local_var_configuration = configuration;
90
91    // unbox the parameters
92
93
94    let local_var_client = &local_var_configuration.client;
95
96    let local_var_uri_str = format!("{}/resources/stores/secret/client-key", local_var_configuration.base_path);
97    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101    }
102    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
103        let local_var_key = local_var_apikey.key.clone();
104        let local_var_value = match local_var_apikey.prefix {
105            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
106            None => local_var_key,
107        };
108        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
109    };
110
111    let local_var_req = local_var_req_builder.build()?;
112    let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114    if "POST" != "GET" && "POST" != "HEAD" {
115      let headers = local_var_resp.headers();
116      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
117          Some(v) => v.to_str().unwrap().parse().unwrap(),
118          None => configuration::DEFAULT_RATELIMIT,
119      };
120      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
121          Some(v) => v.to_str().unwrap().parse().unwrap(),
122          None => 0,
123      };
124    }
125
126    let local_var_status = local_var_resp.status();
127    let local_var_content = local_var_resp.text().await?;
128
129    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
130        serde_json::from_str(&local_var_content).map_err(Error::from)
131    } else {
132        let local_var_entity: Option<ClientKeyError> = serde_json::from_str(&local_var_content).ok();
133        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
134        Err(Error::ResponseError(local_var_error))
135    }
136}
137
138/// Create a new secret store.
139pub async fn create_secret_store(configuration: &mut configuration::Configuration, params: CreateSecretStoreParams) -> Result<crate::models::SecretStoreResponse, Error<CreateSecretStoreError>> {
140    let local_var_configuration = configuration;
141
142    // unbox the parameters
143    let secret_store = params.secret_store;
144
145
146    let local_var_client = &local_var_configuration.client;
147
148    let local_var_uri_str = format!("{}/resources/stores/secret", local_var_configuration.base_path);
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153    }
154    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
155        let local_var_key = local_var_apikey.key.clone();
156        let local_var_value = match local_var_apikey.prefix {
157            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
158            None => local_var_key,
159        };
160        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
161    };
162    local_var_req_builder = local_var_req_builder.json(&secret_store);
163
164    let local_var_req = local_var_req_builder.build()?;
165    let local_var_resp = local_var_client.execute(local_var_req).await?;
166
167    if "POST" != "GET" && "POST" != "HEAD" {
168      let headers = local_var_resp.headers();
169      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
170          Some(v) => v.to_str().unwrap().parse().unwrap(),
171          None => configuration::DEFAULT_RATELIMIT,
172      };
173      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
174          Some(v) => v.to_str().unwrap().parse().unwrap(),
175          None => 0,
176      };
177    }
178
179    let local_var_status = local_var_resp.status();
180    let local_var_content = local_var_resp.text().await?;
181
182    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183        serde_json::from_str(&local_var_content).map_err(Error::from)
184    } else {
185        let local_var_entity: Option<CreateSecretStoreError> = serde_json::from_str(&local_var_content).ok();
186        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
187        Err(Error::ResponseError(local_var_error))
188    }
189}
190
191/// Delete a secret store and all of its contents.
192pub async fn delete_secret_store(configuration: &mut configuration::Configuration, params: DeleteSecretStoreParams) -> Result<(), Error<DeleteSecretStoreError>> {
193    let local_var_configuration = configuration;
194
195    // unbox the parameters
196    let store_id = params.store_id;
197
198
199    let local_var_client = &local_var_configuration.client;
200
201    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
202    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
203
204    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206    }
207    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
208        let local_var_key = local_var_apikey.key.clone();
209        let local_var_value = match local_var_apikey.prefix {
210            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
211            None => local_var_key,
212        };
213        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
214    };
215
216    let local_var_req = local_var_req_builder.build()?;
217    let local_var_resp = local_var_client.execute(local_var_req).await?;
218
219    if "DELETE" != "GET" && "DELETE" != "HEAD" {
220      let headers = local_var_resp.headers();
221      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
222          Some(v) => v.to_str().unwrap().parse().unwrap(),
223          None => configuration::DEFAULT_RATELIMIT,
224      };
225      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
226          Some(v) => v.to_str().unwrap().parse().unwrap(),
227          None => 0,
228      };
229    }
230
231    let local_var_status = local_var_resp.status();
232    let local_var_content = local_var_resp.text().await?;
233
234    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235        Ok(())
236    } else {
237        let local_var_entity: Option<DeleteSecretStoreError> = serde_json::from_str(&local_var_content).ok();
238        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239        Err(Error::ResponseError(local_var_error))
240    }
241}
242
243/// Get a secret store by ID.
244pub async fn get_secret_store(configuration: &mut configuration::Configuration, params: GetSecretStoreParams) -> Result<crate::models::SecretStoreResponse, Error<GetSecretStoreError>> {
245    let local_var_configuration = configuration;
246
247    // unbox the parameters
248    let store_id = params.store_id;
249
250
251    let local_var_client = &local_var_configuration.client;
252
253    let local_var_uri_str = format!("{}/resources/stores/secret/{store_id}", local_var_configuration.base_path, store_id=crate::apis::urlencode(store_id));
254    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
255
256    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
258    }
259    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
260        let local_var_key = local_var_apikey.key.clone();
261        let local_var_value = match local_var_apikey.prefix {
262            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
263            None => local_var_key,
264        };
265        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
266    };
267
268    let local_var_req = local_var_req_builder.build()?;
269    let local_var_resp = local_var_client.execute(local_var_req).await?;
270
271    if "GET" != "GET" && "GET" != "HEAD" {
272      let headers = local_var_resp.headers();
273      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
274          Some(v) => v.to_str().unwrap().parse().unwrap(),
275          None => configuration::DEFAULT_RATELIMIT,
276      };
277      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
278          Some(v) => v.to_str().unwrap().parse().unwrap(),
279          None => 0,
280      };
281    }
282
283    let local_var_status = local_var_resp.status();
284    let local_var_content = local_var_resp.text().await?;
285
286    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
287        serde_json::from_str(&local_var_content).map_err(Error::from)
288    } else {
289        let local_var_entity: Option<GetSecretStoreError> = serde_json::from_str(&local_var_content).ok();
290        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
291        Err(Error::ResponseError(local_var_error))
292    }
293}
294
295/// Get all secret stores.
296pub async fn get_secret_stores(configuration: &mut configuration::Configuration, params: GetSecretStoresParams) -> Result<crate::models::InlineResponse2007, Error<GetSecretStoresError>> {
297    let local_var_configuration = configuration;
298
299    // unbox the parameters
300    let cursor = params.cursor;
301    let limit = params.limit;
302    let name = params.name;
303
304
305    let local_var_client = &local_var_configuration.client;
306
307    let local_var_uri_str = format!("{}/resources/stores/secret", local_var_configuration.base_path);
308    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
309
310    if let Some(ref local_var_str) = cursor {
311        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
312    }
313    if let Some(ref local_var_str) = limit {
314        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
315    }
316    if let Some(ref local_var_str) = name {
317        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
318    }
319    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
320        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
321    }
322    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
323        let local_var_key = local_var_apikey.key.clone();
324        let local_var_value = match local_var_apikey.prefix {
325            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
326            None => local_var_key,
327        };
328        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
329    };
330
331    let local_var_req = local_var_req_builder.build()?;
332    let local_var_resp = local_var_client.execute(local_var_req).await?;
333
334    if "GET" != "GET" && "GET" != "HEAD" {
335      let headers = local_var_resp.headers();
336      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
337          Some(v) => v.to_str().unwrap().parse().unwrap(),
338          None => configuration::DEFAULT_RATELIMIT,
339      };
340      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
341          Some(v) => v.to_str().unwrap().parse().unwrap(),
342          None => 0,
343      };
344    }
345
346    let local_var_status = local_var_resp.status();
347    let local_var_content = local_var_resp.text().await?;
348
349    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
350        serde_json::from_str(&local_var_content).map_err(Error::from)
351    } else {
352        let local_var_entity: Option<GetSecretStoresError> = serde_json::from_str(&local_var_content).ok();
353        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
354        Err(Error::ResponseError(local_var_error))
355    }
356}
357
358/// Get the public key used for signing client keys.
359pub async fn signing_key(configuration: &mut configuration::Configuration) -> Result<crate::models::SigningKey, Error<SigningKeyError>> {
360    let local_var_configuration = configuration;
361
362    // unbox the parameters
363
364
365    let local_var_client = &local_var_configuration.client;
366
367    let local_var_uri_str = format!("{}/resources/stores/secret/signing-key", local_var_configuration.base_path);
368    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
369
370    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
371        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
372    }
373    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
374        let local_var_key = local_var_apikey.key.clone();
375        let local_var_value = match local_var_apikey.prefix {
376            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
377            None => local_var_key,
378        };
379        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
380    };
381
382    let local_var_req = local_var_req_builder.build()?;
383    let local_var_resp = local_var_client.execute(local_var_req).await?;
384
385    if "GET" != "GET" && "GET" != "HEAD" {
386      let headers = local_var_resp.headers();
387      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
388          Some(v) => v.to_str().unwrap().parse().unwrap(),
389          None => configuration::DEFAULT_RATELIMIT,
390      };
391      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
392          Some(v) => v.to_str().unwrap().parse().unwrap(),
393          None => 0,
394      };
395    }
396
397    let local_var_status = local_var_resp.status();
398    let local_var_content = local_var_resp.text().await?;
399
400    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
401        serde_json::from_str(&local_var_content).map_err(Error::from)
402    } else {
403        let local_var_entity: Option<SigningKeyError> = serde_json::from_str(&local_var_content).ok();
404        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
405        Err(Error::ResponseError(local_var_error))
406    }
407}
408