fastly_api/apis/
config_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_config_store`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateConfigStoreParams {
17    /// The name of the config store.
18    pub name: Option<String>
19}
20
21/// struct for passing parameters to the method [`delete_config_store`]
22#[derive(Clone, Debug, Default)]
23pub struct DeleteConfigStoreParams {
24    /// An alphanumeric string identifying the config store.
25    pub config_store_id: String
26}
27
28/// struct for passing parameters to the method [`get_config_store`]
29#[derive(Clone, Debug, Default)]
30pub struct GetConfigStoreParams {
31    /// An alphanumeric string identifying the config store.
32    pub config_store_id: String
33}
34
35/// struct for passing parameters to the method [`get_config_store_info`]
36#[derive(Clone, Debug, Default)]
37pub struct GetConfigStoreInfoParams {
38    /// An alphanumeric string identifying the config store.
39    pub config_store_id: String
40}
41
42/// struct for passing parameters to the method [`list_config_store_services`]
43#[derive(Clone, Debug, Default)]
44pub struct ListConfigStoreServicesParams {
45    /// An alphanumeric string identifying the config store.
46    pub config_store_id: String
47}
48
49/// struct for passing parameters to the method [`list_config_stores`]
50#[derive(Clone, Debug, Default)]
51pub struct ListConfigStoresParams {
52    /// Returns a one-element array containing the details for the named config store.
53    pub name: Option<String>
54}
55
56/// struct for passing parameters to the method [`update_config_store`]
57#[derive(Clone, Debug, Default)]
58pub struct UpdateConfigStoreParams {
59    /// An alphanumeric string identifying the config store.
60    pub config_store_id: String,
61    /// The name of the config store.
62    pub name: Option<String>
63}
64
65
66/// struct for typed errors of method [`create_config_store`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum CreateConfigStoreError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`delete_config_store`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum DeleteConfigStoreError {
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`get_config_store`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetConfigStoreError {
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`get_config_store_info`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum GetConfigStoreInfoError {
91    UnknownValue(serde_json::Value),
92}
93
94/// struct for typed errors of method [`list_config_store_services`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum ListConfigStoreServicesError {
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`list_config_stores`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum ListConfigStoresError {
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`update_config_store`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum UpdateConfigStoreError {
112    UnknownValue(serde_json::Value),
113}
114
115
116/// Create a config store.
117pub async fn create_config_store(configuration: &mut configuration::Configuration, params: CreateConfigStoreParams) -> Result<crate::models::ConfigStoreResponse, Error<CreateConfigStoreError>> {
118    let local_var_configuration = configuration;
119
120    // unbox the parameters
121    let name = params.name;
122
123
124    let local_var_client = &local_var_configuration.client;
125
126    let local_var_uri_str = format!("{}/resources/stores/config", local_var_configuration.base_path);
127    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
128
129    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
130        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
131    }
132    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
133        let local_var_key = local_var_apikey.key.clone();
134        let local_var_value = match local_var_apikey.prefix {
135            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
136            None => local_var_key,
137        };
138        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
139    };
140    let mut local_var_form_params = std::collections::HashMap::new();
141    if let Some(local_var_param_value) = name {
142        local_var_form_params.insert("name", local_var_param_value.to_string());
143    }
144    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
145
146    let local_var_req = local_var_req_builder.build()?;
147    let local_var_resp = local_var_client.execute(local_var_req).await?;
148
149    if "POST" != "GET" && "POST" != "HEAD" {
150      let headers = local_var_resp.headers();
151      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
152          Some(v) => v.to_str().unwrap().parse().unwrap(),
153          None => configuration::DEFAULT_RATELIMIT,
154      };
155      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
156          Some(v) => v.to_str().unwrap().parse().unwrap(),
157          None => 0,
158      };
159    }
160
161    let local_var_status = local_var_resp.status();
162    let local_var_content = local_var_resp.text().await?;
163
164    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165        serde_json::from_str(&local_var_content).map_err(Error::from)
166    } else {
167        let local_var_entity: Option<CreateConfigStoreError> = serde_json::from_str(&local_var_content).ok();
168        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
169        Err(Error::ResponseError(local_var_error))
170    }
171}
172
173/// Delete a config store.
174pub async fn delete_config_store(configuration: &mut configuration::Configuration, params: DeleteConfigStoreParams) -> Result<crate::models::InlineResponse200, Error<DeleteConfigStoreError>> {
175    let local_var_configuration = configuration;
176
177    // unbox the parameters
178    let config_store_id = params.config_store_id;
179
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
190        let local_var_key = local_var_apikey.key.clone();
191        let local_var_value = match local_var_apikey.prefix {
192            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
193            None => local_var_key,
194        };
195        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
196    };
197
198    let local_var_req = local_var_req_builder.build()?;
199    let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201    if "DELETE" != "GET" && "DELETE" != "HEAD" {
202      let headers = local_var_resp.headers();
203      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
204          Some(v) => v.to_str().unwrap().parse().unwrap(),
205          None => configuration::DEFAULT_RATELIMIT,
206      };
207      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
208          Some(v) => v.to_str().unwrap().parse().unwrap(),
209          None => 0,
210      };
211    }
212
213    let local_var_status = local_var_resp.status();
214    let local_var_content = local_var_resp.text().await?;
215
216    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217        serde_json::from_str(&local_var_content).map_err(Error::from)
218    } else {
219        let local_var_entity: Option<DeleteConfigStoreError> = serde_json::from_str(&local_var_content).ok();
220        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
221        Err(Error::ResponseError(local_var_error))
222    }
223}
224
225/// Describe a config store by its identifier.
226pub async fn get_config_store(configuration: &mut configuration::Configuration, params: GetConfigStoreParams) -> Result<crate::models::ConfigStoreResponse, Error<GetConfigStoreError>> {
227    let local_var_configuration = configuration;
228
229    // unbox the parameters
230    let config_store_id = params.config_store_id;
231
232
233    let local_var_client = &local_var_configuration.client;
234
235    let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
236    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
237
238    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
239        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
240    }
241    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
242        let local_var_key = local_var_apikey.key.clone();
243        let local_var_value = match local_var_apikey.prefix {
244            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
245            None => local_var_key,
246        };
247        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
248    };
249
250    let local_var_req = local_var_req_builder.build()?;
251    let local_var_resp = local_var_client.execute(local_var_req).await?;
252
253    if "GET" != "GET" && "GET" != "HEAD" {
254      let headers = local_var_resp.headers();
255      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
256          Some(v) => v.to_str().unwrap().parse().unwrap(),
257          None => configuration::DEFAULT_RATELIMIT,
258      };
259      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
260          Some(v) => v.to_str().unwrap().parse().unwrap(),
261          None => 0,
262      };
263    }
264
265    let local_var_status = local_var_resp.status();
266    let local_var_content = local_var_resp.text().await?;
267
268    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
269        serde_json::from_str(&local_var_content).map_err(Error::from)
270    } else {
271        let local_var_entity: Option<GetConfigStoreError> = serde_json::from_str(&local_var_content).ok();
272        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
273        Err(Error::ResponseError(local_var_error))
274    }
275}
276
277/// Retrieve metadata for a single config store.
278pub async fn get_config_store_info(configuration: &mut configuration::Configuration, params: GetConfigStoreInfoParams) -> Result<crate::models::ConfigStoreInfoResponse, Error<GetConfigStoreInfoError>> {
279    let local_var_configuration = configuration;
280
281    // unbox the parameters
282    let config_store_id = params.config_store_id;
283
284
285    let local_var_client = &local_var_configuration.client;
286
287    let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/info", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
288    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
289
290    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
291        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292    }
293    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
294        let local_var_key = local_var_apikey.key.clone();
295        let local_var_value = match local_var_apikey.prefix {
296            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
297            None => local_var_key,
298        };
299        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
300    };
301
302    let local_var_req = local_var_req_builder.build()?;
303    let local_var_resp = local_var_client.execute(local_var_req).await?;
304
305    if "GET" != "GET" && "GET" != "HEAD" {
306      let headers = local_var_resp.headers();
307      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
308          Some(v) => v.to_str().unwrap().parse().unwrap(),
309          None => configuration::DEFAULT_RATELIMIT,
310      };
311      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
312          Some(v) => v.to_str().unwrap().parse().unwrap(),
313          None => 0,
314      };
315    }
316
317    let local_var_status = local_var_resp.status();
318    let local_var_content = local_var_resp.text().await?;
319
320    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321        serde_json::from_str(&local_var_content).map_err(Error::from)
322    } else {
323        let local_var_entity: Option<GetConfigStoreInfoError> = serde_json::from_str(&local_var_content).ok();
324        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
325        Err(Error::ResponseError(local_var_error))
326    }
327}
328
329/// List services linked to a config store
330pub async fn list_config_store_services(configuration: &mut configuration::Configuration, params: ListConfigStoreServicesParams) -> Result<serde_json::Value, Error<ListConfigStoreServicesError>> {
331    let local_var_configuration = configuration;
332
333    // unbox the parameters
334    let config_store_id = params.config_store_id;
335
336
337    let local_var_client = &local_var_configuration.client;
338
339    let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/services", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
340    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
341
342    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
343        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
344    }
345    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
346        let local_var_key = local_var_apikey.key.clone();
347        let local_var_value = match local_var_apikey.prefix {
348            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
349            None => local_var_key,
350        };
351        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
352    };
353
354    let local_var_req = local_var_req_builder.build()?;
355    let local_var_resp = local_var_client.execute(local_var_req).await?;
356
357    if "GET" != "GET" && "GET" != "HEAD" {
358      let headers = local_var_resp.headers();
359      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
360          Some(v) => v.to_str().unwrap().parse().unwrap(),
361          None => configuration::DEFAULT_RATELIMIT,
362      };
363      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
364          Some(v) => v.to_str().unwrap().parse().unwrap(),
365          None => 0,
366      };
367    }
368
369    let local_var_status = local_var_resp.status();
370    let local_var_content = local_var_resp.text().await?;
371
372    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
373        serde_json::from_str(&local_var_content).map_err(Error::from)
374    } else {
375        let local_var_entity: Option<ListConfigStoreServicesError> = serde_json::from_str(&local_var_content).ok();
376        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
377        Err(Error::ResponseError(local_var_error))
378    }
379}
380
381/// List config stores.
382pub async fn list_config_stores(configuration: &mut configuration::Configuration, params: ListConfigStoresParams) -> Result<Vec<crate::models::ConfigStoreResponse>, Error<ListConfigStoresError>> {
383    let local_var_configuration = configuration;
384
385    // unbox the parameters
386    let name = params.name;
387
388
389    let local_var_client = &local_var_configuration.client;
390
391    let local_var_uri_str = format!("{}/resources/stores/config", local_var_configuration.base_path);
392    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
393
394    if let Some(ref local_var_str) = name {
395        local_var_req_builder = local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
396    }
397    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
398        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
399    }
400    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
401        let local_var_key = local_var_apikey.key.clone();
402        let local_var_value = match local_var_apikey.prefix {
403            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
404            None => local_var_key,
405        };
406        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
407    };
408
409    let local_var_req = local_var_req_builder.build()?;
410    let local_var_resp = local_var_client.execute(local_var_req).await?;
411
412    if "GET" != "GET" && "GET" != "HEAD" {
413      let headers = local_var_resp.headers();
414      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
415          Some(v) => v.to_str().unwrap().parse().unwrap(),
416          None => configuration::DEFAULT_RATELIMIT,
417      };
418      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
419          Some(v) => v.to_str().unwrap().parse().unwrap(),
420          None => 0,
421      };
422    }
423
424    let local_var_status = local_var_resp.status();
425    let local_var_content = local_var_resp.text().await?;
426
427    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
428        serde_json::from_str(&local_var_content).map_err(Error::from)
429    } else {
430        let local_var_entity: Option<ListConfigStoresError> = serde_json::from_str(&local_var_content).ok();
431        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
432        Err(Error::ResponseError(local_var_error))
433    }
434}
435
436/// Update a config store.
437pub async fn update_config_store(configuration: &mut configuration::Configuration, params: UpdateConfigStoreParams) -> Result<crate::models::ConfigStoreResponse, Error<UpdateConfigStoreError>> {
438    let local_var_configuration = configuration;
439
440    // unbox the parameters
441    let config_store_id = params.config_store_id;
442    let name = params.name;
443
444
445    let local_var_client = &local_var_configuration.client;
446
447    let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
448    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
449
450    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
451        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
452    }
453    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
454        let local_var_key = local_var_apikey.key.clone();
455        let local_var_value = match local_var_apikey.prefix {
456            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
457            None => local_var_key,
458        };
459        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
460    };
461    let mut local_var_form_params = std::collections::HashMap::new();
462    if let Some(local_var_param_value) = name {
463        local_var_form_params.insert("name", local_var_param_value.to_string());
464    }
465    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
466
467    let local_var_req = local_var_req_builder.build()?;
468    let local_var_resp = local_var_client.execute(local_var_req).await?;
469
470    if "PUT" != "GET" && "PUT" != "HEAD" {
471      let headers = local_var_resp.headers();
472      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
473          Some(v) => v.to_str().unwrap().parse().unwrap(),
474          None => configuration::DEFAULT_RATELIMIT,
475      };
476      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
477          Some(v) => v.to_str().unwrap().parse().unwrap(),
478          None => 0,
479      };
480    }
481
482    let local_var_status = local_var_resp.status();
483    let local_var_content = local_var_resp.text().await?;
484
485    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
486        serde_json::from_str(&local_var_content).map_err(Error::from)
487    } else {
488        let local_var_entity: Option<UpdateConfigStoreError> = serde_json::from_str(&local_var_content).ok();
489        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
490        Err(Error::ResponseError(local_var_error))
491    }
492}
493