1use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14#[derive(Clone, Debug, Default)]
16pub struct BulkUpdateConfigStoreItemParams {
17 pub config_store_id: String,
19 pub bulk_update_config_store_list_request: Option<crate::models::BulkUpdateConfigStoreListRequest>
20}
21
22#[derive(Clone, Debug, Default)]
24pub struct CreateConfigStoreItemParams {
25 pub config_store_id: String,
27 pub item_key: Option<String>,
29 pub item_value: Option<String>
31}
32
33#[derive(Clone, Debug, Default)]
35pub struct DeleteConfigStoreItemParams {
36 pub config_store_id: String,
38 pub config_store_item_key: String
40}
41
42#[derive(Clone, Debug, Default)]
44pub struct GetConfigStoreItemParams {
45 pub config_store_id: String,
47 pub config_store_item_key: String
49}
50
51#[derive(Clone, Debug, Default)]
53pub struct ListConfigStoreItemsParams {
54 pub config_store_id: String
56}
57
58#[derive(Clone, Debug, Default)]
60pub struct UpdateConfigStoreItemParams {
61 pub config_store_id: String,
63 pub config_store_item_key: String,
65 pub item_key: Option<String>,
67 pub item_value: Option<String>
69}
70
71#[derive(Clone, Debug, Default)]
73pub struct UpsertConfigStoreItemParams {
74 pub config_store_id: String,
76 pub config_store_item_key: String,
78 pub item_key: Option<String>,
80 pub item_value: Option<String>
82}
83
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum BulkUpdateConfigStoreItemError {
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum CreateConfigStoreItemError {
96 UnknownValue(serde_json::Value),
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum DeleteConfigStoreItemError {
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetConfigStoreItemError {
110 UnknownValue(serde_json::Value),
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum ListConfigStoreItemsError {
117 UnknownValue(serde_json::Value),
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum UpdateConfigStoreItemError {
124 UnknownValue(serde_json::Value),
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum UpsertConfigStoreItemError {
131 UnknownValue(serde_json::Value),
132}
133
134
135pub async fn bulk_update_config_store_item(configuration: &mut configuration::Configuration, params: BulkUpdateConfigStoreItemParams) -> Result<crate::models::InlineResponse200, Error<BulkUpdateConfigStoreItemError>> {
137 let local_var_configuration = configuration;
138
139 let config_store_id = params.config_store_id;
141 let bulk_update_config_store_list_request = params.bulk_update_config_store_list_request;
142
143
144 let local_var_client = &local_var_configuration.client;
145
146 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/items", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
147 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
148
149 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
150 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
151 }
152 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
153 let local_var_key = local_var_apikey.key.clone();
154 let local_var_value = match local_var_apikey.prefix {
155 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
156 None => local_var_key,
157 };
158 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
159 };
160 local_var_req_builder = local_var_req_builder.json(&bulk_update_config_store_list_request);
161
162 let local_var_req = local_var_req_builder.build()?;
163 let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165 if "PATCH" != "GET" && "PATCH" != "HEAD" {
166 let headers = local_var_resp.headers();
167 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
168 Some(v) => v.to_str().unwrap().parse().unwrap(),
169 None => configuration::DEFAULT_RATELIMIT,
170 };
171 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
172 Some(v) => v.to_str().unwrap().parse().unwrap(),
173 None => 0,
174 };
175 }
176
177 let local_var_status = local_var_resp.status();
178 let local_var_content = local_var_resp.text().await?;
179
180 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181 serde_json::from_str(&local_var_content).map_err(Error::from)
182 } else {
183 let local_var_entity: Option<BulkUpdateConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
184 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185 Err(Error::ResponseError(local_var_error))
186 }
187}
188
189pub async fn create_config_store_item(configuration: &mut configuration::Configuration, params: CreateConfigStoreItemParams) -> Result<crate::models::ConfigStoreItemResponse, Error<CreateConfigStoreItemError>> {
191 let local_var_configuration = configuration;
192
193 let config_store_id = params.config_store_id;
195 let item_key = params.item_key;
196 let item_value = params.item_value;
197
198
199 let local_var_client = &local_var_configuration.client;
200
201 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/item", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
202 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, 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 let mut local_var_form_params = std::collections::HashMap::new();
216 if let Some(local_var_param_value) = item_key {
217 local_var_form_params.insert("item_key", local_var_param_value.to_string());
218 }
219 if let Some(local_var_param_value) = item_value {
220 local_var_form_params.insert("item_value", local_var_param_value.to_string());
221 }
222 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
223
224 let local_var_req = local_var_req_builder.build()?;
225 let local_var_resp = local_var_client.execute(local_var_req).await?;
226
227 if "POST" != "GET" && "POST" != "HEAD" {
228 let headers = local_var_resp.headers();
229 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
230 Some(v) => v.to_str().unwrap().parse().unwrap(),
231 None => configuration::DEFAULT_RATELIMIT,
232 };
233 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
234 Some(v) => v.to_str().unwrap().parse().unwrap(),
235 None => 0,
236 };
237 }
238
239 let local_var_status = local_var_resp.status();
240 let local_var_content = local_var_resp.text().await?;
241
242 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
243 serde_json::from_str(&local_var_content).map_err(Error::from)
244 } else {
245 let local_var_entity: Option<CreateConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
246 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
247 Err(Error::ResponseError(local_var_error))
248 }
249}
250
251pub async fn delete_config_store_item(configuration: &mut configuration::Configuration, params: DeleteConfigStoreItemParams) -> Result<crate::models::InlineResponse200, Error<DeleteConfigStoreItemError>> {
253 let local_var_configuration = configuration;
254
255 let config_store_id = params.config_store_id;
257 let config_store_item_key = params.config_store_item_key;
258
259
260 let local_var_client = &local_var_configuration.client;
261
262 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/item/{config_store_item_key}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id), config_store_item_key=crate::apis::urlencode(config_store_item_key));
263 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
264
265 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
267 }
268 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
269 let local_var_key = local_var_apikey.key.clone();
270 let local_var_value = match local_var_apikey.prefix {
271 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
272 None => local_var_key,
273 };
274 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
275 };
276
277 let local_var_req = local_var_req_builder.build()?;
278 let local_var_resp = local_var_client.execute(local_var_req).await?;
279
280 if "DELETE" != "GET" && "DELETE" != "HEAD" {
281 let headers = local_var_resp.headers();
282 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
283 Some(v) => v.to_str().unwrap().parse().unwrap(),
284 None => configuration::DEFAULT_RATELIMIT,
285 };
286 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
287 Some(v) => v.to_str().unwrap().parse().unwrap(),
288 None => 0,
289 };
290 }
291
292 let local_var_status = local_var_resp.status();
293 let local_var_content = local_var_resp.text().await?;
294
295 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296 serde_json::from_str(&local_var_content).map_err(Error::from)
297 } else {
298 let local_var_entity: Option<DeleteConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
299 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
300 Err(Error::ResponseError(local_var_error))
301 }
302}
303
304pub async fn get_config_store_item(configuration: &mut configuration::Configuration, params: GetConfigStoreItemParams) -> Result<crate::models::ConfigStoreItemResponse, Error<GetConfigStoreItemError>> {
306 let local_var_configuration = configuration;
307
308 let config_store_id = params.config_store_id;
310 let config_store_item_key = params.config_store_item_key;
311
312
313 let local_var_client = &local_var_configuration.client;
314
315 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/item/{config_store_item_key}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id), config_store_item_key=crate::apis::urlencode(config_store_item_key));
316 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
317
318 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
319 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
320 }
321 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
322 let local_var_key = local_var_apikey.key.clone();
323 let local_var_value = match local_var_apikey.prefix {
324 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
325 None => local_var_key,
326 };
327 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
328 };
329
330 let local_var_req = local_var_req_builder.build()?;
331 let local_var_resp = local_var_client.execute(local_var_req).await?;
332
333 if "GET" != "GET" && "GET" != "HEAD" {
334 let headers = local_var_resp.headers();
335 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
336 Some(v) => v.to_str().unwrap().parse().unwrap(),
337 None => configuration::DEFAULT_RATELIMIT,
338 };
339 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
340 Some(v) => v.to_str().unwrap().parse().unwrap(),
341 None => 0,
342 };
343 }
344
345 let local_var_status = local_var_resp.status();
346 let local_var_content = local_var_resp.text().await?;
347
348 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
349 serde_json::from_str(&local_var_content).map_err(Error::from)
350 } else {
351 let local_var_entity: Option<GetConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
352 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
353 Err(Error::ResponseError(local_var_error))
354 }
355}
356
357pub async fn list_config_store_items(configuration: &mut configuration::Configuration, params: ListConfigStoreItemsParams) -> Result<Vec<crate::models::ConfigStoreItemResponse>, Error<ListConfigStoreItemsError>> {
359 let local_var_configuration = configuration;
360
361 let config_store_id = params.config_store_id;
363
364
365 let local_var_client = &local_var_configuration.client;
366
367 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/items", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id));
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<ListConfigStoreItemsError> = 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
409pub async fn update_config_store_item(configuration: &mut configuration::Configuration, params: UpdateConfigStoreItemParams) -> Result<crate::models::ConfigStoreItemResponse, Error<UpdateConfigStoreItemError>> {
411 let local_var_configuration = configuration;
412
413 let config_store_id = params.config_store_id;
415 let config_store_item_key = params.config_store_item_key;
416 let item_key = params.item_key;
417 let item_value = params.item_value;
418
419
420 let local_var_client = &local_var_configuration.client;
421
422 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/item/{config_store_item_key}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id), config_store_item_key=crate::apis::urlencode(config_store_item_key));
423 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
424
425 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
426 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
427 }
428 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
429 let local_var_key = local_var_apikey.key.clone();
430 let local_var_value = match local_var_apikey.prefix {
431 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
432 None => local_var_key,
433 };
434 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
435 };
436 let mut local_var_form_params = std::collections::HashMap::new();
437 if let Some(local_var_param_value) = item_key {
438 local_var_form_params.insert("item_key", local_var_param_value.to_string());
439 }
440 if let Some(local_var_param_value) = item_value {
441 local_var_form_params.insert("item_value", local_var_param_value.to_string());
442 }
443 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
444
445 let local_var_req = local_var_req_builder.build()?;
446 let local_var_resp = local_var_client.execute(local_var_req).await?;
447
448 if "PATCH" != "GET" && "PATCH" != "HEAD" {
449 let headers = local_var_resp.headers();
450 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
451 Some(v) => v.to_str().unwrap().parse().unwrap(),
452 None => configuration::DEFAULT_RATELIMIT,
453 };
454 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
455 Some(v) => v.to_str().unwrap().parse().unwrap(),
456 None => 0,
457 };
458 }
459
460 let local_var_status = local_var_resp.status();
461 let local_var_content = local_var_resp.text().await?;
462
463 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
464 serde_json::from_str(&local_var_content).map_err(Error::from)
465 } else {
466 let local_var_entity: Option<UpdateConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
467 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
468 Err(Error::ResponseError(local_var_error))
469 }
470}
471
472pub async fn upsert_config_store_item(configuration: &mut configuration::Configuration, params: UpsertConfigStoreItemParams) -> Result<crate::models::ConfigStoreItemResponse, Error<UpsertConfigStoreItemError>> {
474 let local_var_configuration = configuration;
475
476 let config_store_id = params.config_store_id;
478 let config_store_item_key = params.config_store_item_key;
479 let item_key = params.item_key;
480 let item_value = params.item_value;
481
482
483 let local_var_client = &local_var_configuration.client;
484
485 let local_var_uri_str = format!("{}/resources/stores/config/{config_store_id}/item/{config_store_item_key}", local_var_configuration.base_path, config_store_id=crate::apis::urlencode(config_store_id), config_store_item_key=crate::apis::urlencode(config_store_item_key));
486 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
487
488 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
489 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
490 }
491 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
492 let local_var_key = local_var_apikey.key.clone();
493 let local_var_value = match local_var_apikey.prefix {
494 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
495 None => local_var_key,
496 };
497 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
498 };
499 let mut local_var_form_params = std::collections::HashMap::new();
500 if let Some(local_var_param_value) = item_key {
501 local_var_form_params.insert("item_key", local_var_param_value.to_string());
502 }
503 if let Some(local_var_param_value) = item_value {
504 local_var_form_params.insert("item_value", local_var_param_value.to_string());
505 }
506 local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
507
508 let local_var_req = local_var_req_builder.build()?;
509 let local_var_resp = local_var_client.execute(local_var_req).await?;
510
511 if "PUT" != "GET" && "PUT" != "HEAD" {
512 let headers = local_var_resp.headers();
513 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
514 Some(v) => v.to_str().unwrap().parse().unwrap(),
515 None => configuration::DEFAULT_RATELIMIT,
516 };
517 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
518 Some(v) => v.to_str().unwrap().parse().unwrap(),
519 None => 0,
520 };
521 }
522
523 let local_var_status = local_var_resp.status();
524 let local_var_content = local_var_resp.text().await?;
525
526 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
527 serde_json::from_str(&local_var_content).map_err(Error::from)
528 } else {
529 let local_var_entity: Option<UpsertConfigStoreItemError> = serde_json::from_str(&local_var_content).ok();
530 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
531 Err(Error::ResponseError(local_var_error))
532 }
533}
534