1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::{Deserialize, Serialize};
11use std::io::Write;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateCostAWSCURConfigError {
17 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18 UnknownValue(serde_json::Value),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateCostAzureUCConfigsError {
25 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateCostGCPUsageCostConfigError {
33 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteBudgetError {
41 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum DeleteCostAWSCURConfigError {
49 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum DeleteCostAzureUCConfigError {
57 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum DeleteCostGCPUsageCostConfigError {
65 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum DeleteCustomCostsFileError {
73 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum GetBudgetError {
81 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum GetCustomCostsFileError {
89 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum ListBudgetsError {
97 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
98 UnknownValue(serde_json::Value),
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum ListCostAWSCURConfigsError {
105 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
106 UnknownValue(serde_json::Value),
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum ListCostAzureUCConfigsError {
113 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
114 UnknownValue(serde_json::Value),
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum ListCostGCPUsageCostConfigsError {
121 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
122 UnknownValue(serde_json::Value),
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum ListCustomCostsFilesError {
129 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
130 UnknownValue(serde_json::Value),
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum UpdateCostAWSCURConfigError {
137 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
138 UnknownValue(serde_json::Value),
139}
140
141#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum UpdateCostAzureUCConfigsError {
145 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
146 UnknownValue(serde_json::Value),
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151#[serde(untagged)]
152pub enum UpdateCostGCPUsageCostConfigError {
153 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
154 UnknownValue(serde_json::Value),
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159#[serde(untagged)]
160pub enum UploadCustomCostsFileError {
161 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
162 UnknownValue(serde_json::Value),
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(untagged)]
168pub enum UpsertBudgetError {
169 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
170 UnknownValue(serde_json::Value),
171}
172
173#[derive(Debug, Clone)]
175pub struct CloudCostManagementAPI {
176 config: datadog::Configuration,
177 client: reqwest_middleware::ClientWithMiddleware,
178}
179
180impl Default for CloudCostManagementAPI {
181 fn default() -> Self {
182 Self::with_config(datadog::Configuration::default())
183 }
184}
185
186impl CloudCostManagementAPI {
187 pub fn new() -> Self {
188 Self::default()
189 }
190 pub fn with_config(config: datadog::Configuration) -> Self {
191 let mut reqwest_client_builder = reqwest::Client::builder();
192
193 if let Some(proxy_url) = &config.proxy_url {
194 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
195 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
196 }
197
198 let mut middleware_client_builder =
199 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
200
201 if config.enable_retry {
202 struct RetryableStatus;
203 impl reqwest_retry::RetryableStrategy for RetryableStatus {
204 fn handle(
205 &self,
206 res: &Result<reqwest::Response, reqwest_middleware::Error>,
207 ) -> Option<reqwest_retry::Retryable> {
208 match res {
209 Ok(success) => reqwest_retry::default_on_request_success(success),
210 Err(_) => None,
211 }
212 }
213 }
214 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
215 .build_with_max_retries(config.max_retries);
216
217 let retry_middleware =
218 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
219 backoff_policy,
220 RetryableStatus,
221 );
222
223 middleware_client_builder = middleware_client_builder.with(retry_middleware);
224 }
225
226 let client = middleware_client_builder.build();
227
228 Self { config, client }
229 }
230
231 pub fn with_client_and_config(
232 config: datadog::Configuration,
233 client: reqwest_middleware::ClientWithMiddleware,
234 ) -> Self {
235 Self { config, client }
236 }
237
238 pub async fn create_cost_awscur_config(
240 &self,
241 body: crate::datadogV2::model::AwsCURConfigPostRequest,
242 ) -> Result<
243 crate::datadogV2::model::AwsCURConfigResponse,
244 datadog::Error<CreateCostAWSCURConfigError>,
245 > {
246 match self.create_cost_awscur_config_with_http_info(body).await {
247 Ok(response_content) => {
248 if let Some(e) = response_content.entity {
249 Ok(e)
250 } else {
251 Err(datadog::Error::Serde(serde::de::Error::custom(
252 "response content was None",
253 )))
254 }
255 }
256 Err(err) => Err(err),
257 }
258 }
259
260 pub async fn create_cost_awscur_config_with_http_info(
262 &self,
263 body: crate::datadogV2::model::AwsCURConfigPostRequest,
264 ) -> Result<
265 datadog::ResponseContent<crate::datadogV2::model::AwsCURConfigResponse>,
266 datadog::Error<CreateCostAWSCURConfigError>,
267 > {
268 let local_configuration = &self.config;
269 let operation_id = "v2.create_cost_awscur_config";
270
271 let local_client = &self.client;
272
273 let local_uri_str = format!(
274 "{}/api/v2/cost/aws_cur_config",
275 local_configuration.get_operation_host(operation_id)
276 );
277 let mut local_req_builder =
278 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
279
280 let mut headers = HeaderMap::new();
282 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
283 headers.insert("Accept", HeaderValue::from_static("application/json"));
284
285 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
287 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
288 Err(e) => {
289 log::warn!("Failed to parse user agent header: {e}, falling back to default");
290 headers.insert(
291 reqwest::header::USER_AGENT,
292 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
293 )
294 }
295 };
296
297 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
299 headers.insert(
300 "DD-API-KEY",
301 HeaderValue::from_str(local_key.key.as_str())
302 .expect("failed to parse DD-API-KEY header"),
303 );
304 };
305 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
306 headers.insert(
307 "DD-APPLICATION-KEY",
308 HeaderValue::from_str(local_key.key.as_str())
309 .expect("failed to parse DD-APPLICATION-KEY header"),
310 );
311 };
312
313 let output = Vec::new();
315 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
316 if body.serialize(&mut ser).is_ok() {
317 if let Some(content_encoding) = headers.get("Content-Encoding") {
318 match content_encoding.to_str().unwrap_or_default() {
319 "gzip" => {
320 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
321 let _ = enc.write_all(ser.into_inner().as_slice());
322 match enc.finish() {
323 Ok(buf) => {
324 local_req_builder = local_req_builder.body(buf);
325 }
326 Err(e) => return Err(datadog::Error::Io(e)),
327 }
328 }
329 "deflate" => {
330 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
331 let _ = enc.write_all(ser.into_inner().as_slice());
332 match enc.finish() {
333 Ok(buf) => {
334 local_req_builder = local_req_builder.body(buf);
335 }
336 Err(e) => return Err(datadog::Error::Io(e)),
337 }
338 }
339 "zstd1" => {
340 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
341 let _ = enc.write_all(ser.into_inner().as_slice());
342 match enc.finish() {
343 Ok(buf) => {
344 local_req_builder = local_req_builder.body(buf);
345 }
346 Err(e) => return Err(datadog::Error::Io(e)),
347 }
348 }
349 _ => {
350 local_req_builder = local_req_builder.body(ser.into_inner());
351 }
352 }
353 } else {
354 local_req_builder = local_req_builder.body(ser.into_inner());
355 }
356 }
357
358 local_req_builder = local_req_builder.headers(headers);
359 let local_req = local_req_builder.build()?;
360 log::debug!("request content: {:?}", local_req.body());
361 let local_resp = local_client.execute(local_req).await?;
362
363 let local_status = local_resp.status();
364 let local_content = local_resp.text().await?;
365 log::debug!("response content: {}", local_content);
366
367 if !local_status.is_client_error() && !local_status.is_server_error() {
368 match serde_json::from_str::<crate::datadogV2::model::AwsCURConfigResponse>(
369 &local_content,
370 ) {
371 Ok(e) => {
372 return Ok(datadog::ResponseContent {
373 status: local_status,
374 content: local_content,
375 entity: Some(e),
376 })
377 }
378 Err(e) => return Err(datadog::Error::Serde(e)),
379 };
380 } else {
381 let local_entity: Option<CreateCostAWSCURConfigError> =
382 serde_json::from_str(&local_content).ok();
383 let local_error = datadog::ResponseContent {
384 status: local_status,
385 content: local_content,
386 entity: local_entity,
387 };
388 Err(datadog::Error::ResponseError(local_error))
389 }
390 }
391
392 pub async fn create_cost_azure_uc_configs(
394 &self,
395 body: crate::datadogV2::model::AzureUCConfigPostRequest,
396 ) -> Result<
397 crate::datadogV2::model::AzureUCConfigPairsResponse,
398 datadog::Error<CreateCostAzureUCConfigsError>,
399 > {
400 match self.create_cost_azure_uc_configs_with_http_info(body).await {
401 Ok(response_content) => {
402 if let Some(e) = response_content.entity {
403 Ok(e)
404 } else {
405 Err(datadog::Error::Serde(serde::de::Error::custom(
406 "response content was None",
407 )))
408 }
409 }
410 Err(err) => Err(err),
411 }
412 }
413
414 pub async fn create_cost_azure_uc_configs_with_http_info(
416 &self,
417 body: crate::datadogV2::model::AzureUCConfigPostRequest,
418 ) -> Result<
419 datadog::ResponseContent<crate::datadogV2::model::AzureUCConfigPairsResponse>,
420 datadog::Error<CreateCostAzureUCConfigsError>,
421 > {
422 let local_configuration = &self.config;
423 let operation_id = "v2.create_cost_azure_uc_configs";
424
425 let local_client = &self.client;
426
427 let local_uri_str = format!(
428 "{}/api/v2/cost/azure_uc_config",
429 local_configuration.get_operation_host(operation_id)
430 );
431 let mut local_req_builder =
432 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
433
434 let mut headers = HeaderMap::new();
436 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
437 headers.insert("Accept", HeaderValue::from_static("application/json"));
438
439 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
441 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
442 Err(e) => {
443 log::warn!("Failed to parse user agent header: {e}, falling back to default");
444 headers.insert(
445 reqwest::header::USER_AGENT,
446 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
447 )
448 }
449 };
450
451 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
453 headers.insert(
454 "DD-API-KEY",
455 HeaderValue::from_str(local_key.key.as_str())
456 .expect("failed to parse DD-API-KEY header"),
457 );
458 };
459 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
460 headers.insert(
461 "DD-APPLICATION-KEY",
462 HeaderValue::from_str(local_key.key.as_str())
463 .expect("failed to parse DD-APPLICATION-KEY header"),
464 );
465 };
466
467 let output = Vec::new();
469 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
470 if body.serialize(&mut ser).is_ok() {
471 if let Some(content_encoding) = headers.get("Content-Encoding") {
472 match content_encoding.to_str().unwrap_or_default() {
473 "gzip" => {
474 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
475 let _ = enc.write_all(ser.into_inner().as_slice());
476 match enc.finish() {
477 Ok(buf) => {
478 local_req_builder = local_req_builder.body(buf);
479 }
480 Err(e) => return Err(datadog::Error::Io(e)),
481 }
482 }
483 "deflate" => {
484 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
485 let _ = enc.write_all(ser.into_inner().as_slice());
486 match enc.finish() {
487 Ok(buf) => {
488 local_req_builder = local_req_builder.body(buf);
489 }
490 Err(e) => return Err(datadog::Error::Io(e)),
491 }
492 }
493 "zstd1" => {
494 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
495 let _ = enc.write_all(ser.into_inner().as_slice());
496 match enc.finish() {
497 Ok(buf) => {
498 local_req_builder = local_req_builder.body(buf);
499 }
500 Err(e) => return Err(datadog::Error::Io(e)),
501 }
502 }
503 _ => {
504 local_req_builder = local_req_builder.body(ser.into_inner());
505 }
506 }
507 } else {
508 local_req_builder = local_req_builder.body(ser.into_inner());
509 }
510 }
511
512 local_req_builder = local_req_builder.headers(headers);
513 let local_req = local_req_builder.build()?;
514 log::debug!("request content: {:?}", local_req.body());
515 let local_resp = local_client.execute(local_req).await?;
516
517 let local_status = local_resp.status();
518 let local_content = local_resp.text().await?;
519 log::debug!("response content: {}", local_content);
520
521 if !local_status.is_client_error() && !local_status.is_server_error() {
522 match serde_json::from_str::<crate::datadogV2::model::AzureUCConfigPairsResponse>(
523 &local_content,
524 ) {
525 Ok(e) => {
526 return Ok(datadog::ResponseContent {
527 status: local_status,
528 content: local_content,
529 entity: Some(e),
530 })
531 }
532 Err(e) => return Err(datadog::Error::Serde(e)),
533 };
534 } else {
535 let local_entity: Option<CreateCostAzureUCConfigsError> =
536 serde_json::from_str(&local_content).ok();
537 let local_error = datadog::ResponseContent {
538 status: local_status,
539 content: local_content,
540 entity: local_entity,
541 };
542 Err(datadog::Error::ResponseError(local_error))
543 }
544 }
545
546 pub async fn create_cost_gcp_usage_cost_config(
548 &self,
549 body: crate::datadogV2::model::GCPUsageCostConfigPostRequest,
550 ) -> Result<
551 crate::datadogV2::model::GCPUsageCostConfigResponse,
552 datadog::Error<CreateCostGCPUsageCostConfigError>,
553 > {
554 match self
555 .create_cost_gcp_usage_cost_config_with_http_info(body)
556 .await
557 {
558 Ok(response_content) => {
559 if let Some(e) = response_content.entity {
560 Ok(e)
561 } else {
562 Err(datadog::Error::Serde(serde::de::Error::custom(
563 "response content was None",
564 )))
565 }
566 }
567 Err(err) => Err(err),
568 }
569 }
570
571 pub async fn create_cost_gcp_usage_cost_config_with_http_info(
573 &self,
574 body: crate::datadogV2::model::GCPUsageCostConfigPostRequest,
575 ) -> Result<
576 datadog::ResponseContent<crate::datadogV2::model::GCPUsageCostConfigResponse>,
577 datadog::Error<CreateCostGCPUsageCostConfigError>,
578 > {
579 let local_configuration = &self.config;
580 let operation_id = "v2.create_cost_gcp_usage_cost_config";
581
582 let local_client = &self.client;
583
584 let local_uri_str = format!(
585 "{}/api/v2/cost/gcp_uc_config",
586 local_configuration.get_operation_host(operation_id)
587 );
588 let mut local_req_builder =
589 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
590
591 let mut headers = HeaderMap::new();
593 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
594 headers.insert("Accept", HeaderValue::from_static("application/json"));
595
596 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
598 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
599 Err(e) => {
600 log::warn!("Failed to parse user agent header: {e}, falling back to default");
601 headers.insert(
602 reqwest::header::USER_AGENT,
603 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
604 )
605 }
606 };
607
608 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
610 headers.insert(
611 "DD-API-KEY",
612 HeaderValue::from_str(local_key.key.as_str())
613 .expect("failed to parse DD-API-KEY header"),
614 );
615 };
616 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
617 headers.insert(
618 "DD-APPLICATION-KEY",
619 HeaderValue::from_str(local_key.key.as_str())
620 .expect("failed to parse DD-APPLICATION-KEY header"),
621 );
622 };
623
624 let output = Vec::new();
626 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
627 if body.serialize(&mut ser).is_ok() {
628 if let Some(content_encoding) = headers.get("Content-Encoding") {
629 match content_encoding.to_str().unwrap_or_default() {
630 "gzip" => {
631 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
632 let _ = enc.write_all(ser.into_inner().as_slice());
633 match enc.finish() {
634 Ok(buf) => {
635 local_req_builder = local_req_builder.body(buf);
636 }
637 Err(e) => return Err(datadog::Error::Io(e)),
638 }
639 }
640 "deflate" => {
641 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
642 let _ = enc.write_all(ser.into_inner().as_slice());
643 match enc.finish() {
644 Ok(buf) => {
645 local_req_builder = local_req_builder.body(buf);
646 }
647 Err(e) => return Err(datadog::Error::Io(e)),
648 }
649 }
650 "zstd1" => {
651 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
652 let _ = enc.write_all(ser.into_inner().as_slice());
653 match enc.finish() {
654 Ok(buf) => {
655 local_req_builder = local_req_builder.body(buf);
656 }
657 Err(e) => return Err(datadog::Error::Io(e)),
658 }
659 }
660 _ => {
661 local_req_builder = local_req_builder.body(ser.into_inner());
662 }
663 }
664 } else {
665 local_req_builder = local_req_builder.body(ser.into_inner());
666 }
667 }
668
669 local_req_builder = local_req_builder.headers(headers);
670 let local_req = local_req_builder.build()?;
671 log::debug!("request content: {:?}", local_req.body());
672 let local_resp = local_client.execute(local_req).await?;
673
674 let local_status = local_resp.status();
675 let local_content = local_resp.text().await?;
676 log::debug!("response content: {}", local_content);
677
678 if !local_status.is_client_error() && !local_status.is_server_error() {
679 match serde_json::from_str::<crate::datadogV2::model::GCPUsageCostConfigResponse>(
680 &local_content,
681 ) {
682 Ok(e) => {
683 return Ok(datadog::ResponseContent {
684 status: local_status,
685 content: local_content,
686 entity: Some(e),
687 })
688 }
689 Err(e) => return Err(datadog::Error::Serde(e)),
690 };
691 } else {
692 let local_entity: Option<CreateCostGCPUsageCostConfigError> =
693 serde_json::from_str(&local_content).ok();
694 let local_error = datadog::ResponseContent {
695 status: local_status,
696 content: local_content,
697 entity: local_entity,
698 };
699 Err(datadog::Error::ResponseError(local_error))
700 }
701 }
702
703 pub async fn delete_budget(
705 &self,
706 budget_id: String,
707 ) -> Result<(), datadog::Error<DeleteBudgetError>> {
708 match self.delete_budget_with_http_info(budget_id).await {
709 Ok(_) => Ok(()),
710 Err(err) => Err(err),
711 }
712 }
713
714 pub async fn delete_budget_with_http_info(
716 &self,
717 budget_id: String,
718 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteBudgetError>> {
719 let local_configuration = &self.config;
720 let operation_id = "v2.delete_budget";
721
722 let local_client = &self.client;
723
724 let local_uri_str = format!(
725 "{}/api/v2/cost/budget/{budget_id}",
726 local_configuration.get_operation_host(operation_id),
727 budget_id = datadog::urlencode(budget_id)
728 );
729 let mut local_req_builder =
730 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
731
732 let mut headers = HeaderMap::new();
734 headers.insert("Accept", HeaderValue::from_static("*/*"));
735
736 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
738 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
739 Err(e) => {
740 log::warn!("Failed to parse user agent header: {e}, falling back to default");
741 headers.insert(
742 reqwest::header::USER_AGENT,
743 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
744 )
745 }
746 };
747
748 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
750 headers.insert(
751 "DD-API-KEY",
752 HeaderValue::from_str(local_key.key.as_str())
753 .expect("failed to parse DD-API-KEY header"),
754 );
755 };
756 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
757 headers.insert(
758 "DD-APPLICATION-KEY",
759 HeaderValue::from_str(local_key.key.as_str())
760 .expect("failed to parse DD-APPLICATION-KEY header"),
761 );
762 };
763
764 local_req_builder = local_req_builder.headers(headers);
765 let local_req = local_req_builder.build()?;
766 log::debug!("request content: {:?}", local_req.body());
767 let local_resp = local_client.execute(local_req).await?;
768
769 let local_status = local_resp.status();
770 let local_content = local_resp.text().await?;
771 log::debug!("response content: {}", local_content);
772
773 if !local_status.is_client_error() && !local_status.is_server_error() {
774 Ok(datadog::ResponseContent {
775 status: local_status,
776 content: local_content,
777 entity: None,
778 })
779 } else {
780 let local_entity: Option<DeleteBudgetError> = serde_json::from_str(&local_content).ok();
781 let local_error = datadog::ResponseContent {
782 status: local_status,
783 content: local_content,
784 entity: local_entity,
785 };
786 Err(datadog::Error::ResponseError(local_error))
787 }
788 }
789
790 pub async fn delete_cost_awscur_config(
792 &self,
793 cloud_account_id: String,
794 ) -> Result<(), datadog::Error<DeleteCostAWSCURConfigError>> {
795 match self
796 .delete_cost_awscur_config_with_http_info(cloud_account_id)
797 .await
798 {
799 Ok(_) => Ok(()),
800 Err(err) => Err(err),
801 }
802 }
803
804 pub async fn delete_cost_awscur_config_with_http_info(
806 &self,
807 cloud_account_id: String,
808 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCostAWSCURConfigError>> {
809 let local_configuration = &self.config;
810 let operation_id = "v2.delete_cost_awscur_config";
811
812 let local_client = &self.client;
813
814 let local_uri_str = format!(
815 "{}/api/v2/cost/aws_cur_config/{cloud_account_id}",
816 local_configuration.get_operation_host(operation_id),
817 cloud_account_id = datadog::urlencode(cloud_account_id)
818 );
819 let mut local_req_builder =
820 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
821
822 let mut headers = HeaderMap::new();
824 headers.insert("Accept", HeaderValue::from_static("*/*"));
825
826 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
828 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
829 Err(e) => {
830 log::warn!("Failed to parse user agent header: {e}, falling back to default");
831 headers.insert(
832 reqwest::header::USER_AGENT,
833 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
834 )
835 }
836 };
837
838 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
840 headers.insert(
841 "DD-API-KEY",
842 HeaderValue::from_str(local_key.key.as_str())
843 .expect("failed to parse DD-API-KEY header"),
844 );
845 };
846 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
847 headers.insert(
848 "DD-APPLICATION-KEY",
849 HeaderValue::from_str(local_key.key.as_str())
850 .expect("failed to parse DD-APPLICATION-KEY header"),
851 );
852 };
853
854 local_req_builder = local_req_builder.headers(headers);
855 let local_req = local_req_builder.build()?;
856 log::debug!("request content: {:?}", local_req.body());
857 let local_resp = local_client.execute(local_req).await?;
858
859 let local_status = local_resp.status();
860 let local_content = local_resp.text().await?;
861 log::debug!("response content: {}", local_content);
862
863 if !local_status.is_client_error() && !local_status.is_server_error() {
864 Ok(datadog::ResponseContent {
865 status: local_status,
866 content: local_content,
867 entity: None,
868 })
869 } else {
870 let local_entity: Option<DeleteCostAWSCURConfigError> =
871 serde_json::from_str(&local_content).ok();
872 let local_error = datadog::ResponseContent {
873 status: local_status,
874 content: local_content,
875 entity: local_entity,
876 };
877 Err(datadog::Error::ResponseError(local_error))
878 }
879 }
880
881 pub async fn delete_cost_azure_uc_config(
883 &self,
884 cloud_account_id: String,
885 ) -> Result<(), datadog::Error<DeleteCostAzureUCConfigError>> {
886 match self
887 .delete_cost_azure_uc_config_with_http_info(cloud_account_id)
888 .await
889 {
890 Ok(_) => Ok(()),
891 Err(err) => Err(err),
892 }
893 }
894
895 pub async fn delete_cost_azure_uc_config_with_http_info(
897 &self,
898 cloud_account_id: String,
899 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCostAzureUCConfigError>> {
900 let local_configuration = &self.config;
901 let operation_id = "v2.delete_cost_azure_uc_config";
902
903 let local_client = &self.client;
904
905 let local_uri_str = format!(
906 "{}/api/v2/cost/azure_uc_config/{cloud_account_id}",
907 local_configuration.get_operation_host(operation_id),
908 cloud_account_id = datadog::urlencode(cloud_account_id)
909 );
910 let mut local_req_builder =
911 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
912
913 let mut headers = HeaderMap::new();
915 headers.insert("Accept", HeaderValue::from_static("*/*"));
916
917 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
919 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
920 Err(e) => {
921 log::warn!("Failed to parse user agent header: {e}, falling back to default");
922 headers.insert(
923 reqwest::header::USER_AGENT,
924 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
925 )
926 }
927 };
928
929 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
931 headers.insert(
932 "DD-API-KEY",
933 HeaderValue::from_str(local_key.key.as_str())
934 .expect("failed to parse DD-API-KEY header"),
935 );
936 };
937 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
938 headers.insert(
939 "DD-APPLICATION-KEY",
940 HeaderValue::from_str(local_key.key.as_str())
941 .expect("failed to parse DD-APPLICATION-KEY header"),
942 );
943 };
944
945 local_req_builder = local_req_builder.headers(headers);
946 let local_req = local_req_builder.build()?;
947 log::debug!("request content: {:?}", local_req.body());
948 let local_resp = local_client.execute(local_req).await?;
949
950 let local_status = local_resp.status();
951 let local_content = local_resp.text().await?;
952 log::debug!("response content: {}", local_content);
953
954 if !local_status.is_client_error() && !local_status.is_server_error() {
955 Ok(datadog::ResponseContent {
956 status: local_status,
957 content: local_content,
958 entity: None,
959 })
960 } else {
961 let local_entity: Option<DeleteCostAzureUCConfigError> =
962 serde_json::from_str(&local_content).ok();
963 let local_error = datadog::ResponseContent {
964 status: local_status,
965 content: local_content,
966 entity: local_entity,
967 };
968 Err(datadog::Error::ResponseError(local_error))
969 }
970 }
971
972 pub async fn delete_cost_gcp_usage_cost_config(
974 &self,
975 cloud_account_id: String,
976 ) -> Result<(), datadog::Error<DeleteCostGCPUsageCostConfigError>> {
977 match self
978 .delete_cost_gcp_usage_cost_config_with_http_info(cloud_account_id)
979 .await
980 {
981 Ok(_) => Ok(()),
982 Err(err) => Err(err),
983 }
984 }
985
986 pub async fn delete_cost_gcp_usage_cost_config_with_http_info(
988 &self,
989 cloud_account_id: String,
990 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCostGCPUsageCostConfigError>>
991 {
992 let local_configuration = &self.config;
993 let operation_id = "v2.delete_cost_gcp_usage_cost_config";
994
995 let local_client = &self.client;
996
997 let local_uri_str = format!(
998 "{}/api/v2/cost/gcp_uc_config/{cloud_account_id}",
999 local_configuration.get_operation_host(operation_id),
1000 cloud_account_id = datadog::urlencode(cloud_account_id)
1001 );
1002 let mut local_req_builder =
1003 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1004
1005 let mut headers = HeaderMap::new();
1007 headers.insert("Accept", HeaderValue::from_static("*/*"));
1008
1009 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1011 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1012 Err(e) => {
1013 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1014 headers.insert(
1015 reqwest::header::USER_AGENT,
1016 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1017 )
1018 }
1019 };
1020
1021 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1023 headers.insert(
1024 "DD-API-KEY",
1025 HeaderValue::from_str(local_key.key.as_str())
1026 .expect("failed to parse DD-API-KEY header"),
1027 );
1028 };
1029 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1030 headers.insert(
1031 "DD-APPLICATION-KEY",
1032 HeaderValue::from_str(local_key.key.as_str())
1033 .expect("failed to parse DD-APPLICATION-KEY header"),
1034 );
1035 };
1036
1037 local_req_builder = local_req_builder.headers(headers);
1038 let local_req = local_req_builder.build()?;
1039 log::debug!("request content: {:?}", local_req.body());
1040 let local_resp = local_client.execute(local_req).await?;
1041
1042 let local_status = local_resp.status();
1043 let local_content = local_resp.text().await?;
1044 log::debug!("response content: {}", local_content);
1045
1046 if !local_status.is_client_error() && !local_status.is_server_error() {
1047 Ok(datadog::ResponseContent {
1048 status: local_status,
1049 content: local_content,
1050 entity: None,
1051 })
1052 } else {
1053 let local_entity: Option<DeleteCostGCPUsageCostConfigError> =
1054 serde_json::from_str(&local_content).ok();
1055 let local_error = datadog::ResponseContent {
1056 status: local_status,
1057 content: local_content,
1058 entity: local_entity,
1059 };
1060 Err(datadog::Error::ResponseError(local_error))
1061 }
1062 }
1063
1064 pub async fn delete_custom_costs_file(
1066 &self,
1067 file_id: String,
1068 ) -> Result<(), datadog::Error<DeleteCustomCostsFileError>> {
1069 match self.delete_custom_costs_file_with_http_info(file_id).await {
1070 Ok(_) => Ok(()),
1071 Err(err) => Err(err),
1072 }
1073 }
1074
1075 pub async fn delete_custom_costs_file_with_http_info(
1077 &self,
1078 file_id: String,
1079 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCustomCostsFileError>> {
1080 let local_configuration = &self.config;
1081 let operation_id = "v2.delete_custom_costs_file";
1082
1083 let local_client = &self.client;
1084
1085 let local_uri_str = format!(
1086 "{}/api/v2/cost/custom_costs/{file_id}",
1087 local_configuration.get_operation_host(operation_id),
1088 file_id = datadog::urlencode(file_id)
1089 );
1090 let mut local_req_builder =
1091 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1092
1093 let mut headers = HeaderMap::new();
1095 headers.insert("Accept", HeaderValue::from_static("*/*"));
1096
1097 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1099 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1100 Err(e) => {
1101 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1102 headers.insert(
1103 reqwest::header::USER_AGENT,
1104 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1105 )
1106 }
1107 };
1108
1109 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1111 headers.insert(
1112 "DD-API-KEY",
1113 HeaderValue::from_str(local_key.key.as_str())
1114 .expect("failed to parse DD-API-KEY header"),
1115 );
1116 };
1117 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1118 headers.insert(
1119 "DD-APPLICATION-KEY",
1120 HeaderValue::from_str(local_key.key.as_str())
1121 .expect("failed to parse DD-APPLICATION-KEY header"),
1122 );
1123 };
1124
1125 local_req_builder = local_req_builder.headers(headers);
1126 let local_req = local_req_builder.build()?;
1127 log::debug!("request content: {:?}", local_req.body());
1128 let local_resp = local_client.execute(local_req).await?;
1129
1130 let local_status = local_resp.status();
1131 let local_content = local_resp.text().await?;
1132 log::debug!("response content: {}", local_content);
1133
1134 if !local_status.is_client_error() && !local_status.is_server_error() {
1135 Ok(datadog::ResponseContent {
1136 status: local_status,
1137 content: local_content,
1138 entity: None,
1139 })
1140 } else {
1141 let local_entity: Option<DeleteCustomCostsFileError> =
1142 serde_json::from_str(&local_content).ok();
1143 let local_error = datadog::ResponseContent {
1144 status: local_status,
1145 content: local_content,
1146 entity: local_entity,
1147 };
1148 Err(datadog::Error::ResponseError(local_error))
1149 }
1150 }
1151
1152 pub async fn get_budget(
1154 &self,
1155 budget_id: String,
1156 ) -> Result<crate::datadogV2::model::BudgetWithEntries, datadog::Error<GetBudgetError>> {
1157 match self.get_budget_with_http_info(budget_id).await {
1158 Ok(response_content) => {
1159 if let Some(e) = response_content.entity {
1160 Ok(e)
1161 } else {
1162 Err(datadog::Error::Serde(serde::de::Error::custom(
1163 "response content was None",
1164 )))
1165 }
1166 }
1167 Err(err) => Err(err),
1168 }
1169 }
1170
1171 pub async fn get_budget_with_http_info(
1173 &self,
1174 budget_id: String,
1175 ) -> Result<
1176 datadog::ResponseContent<crate::datadogV2::model::BudgetWithEntries>,
1177 datadog::Error<GetBudgetError>,
1178 > {
1179 let local_configuration = &self.config;
1180 let operation_id = "v2.get_budget";
1181
1182 let local_client = &self.client;
1183
1184 let local_uri_str = format!(
1185 "{}/api/v2/cost/budget/{budget_id}",
1186 local_configuration.get_operation_host(operation_id),
1187 budget_id = datadog::urlencode(budget_id)
1188 );
1189 let mut local_req_builder =
1190 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1191
1192 let mut headers = HeaderMap::new();
1194 headers.insert("Accept", HeaderValue::from_static("application/json"));
1195
1196 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1198 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1199 Err(e) => {
1200 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1201 headers.insert(
1202 reqwest::header::USER_AGENT,
1203 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1204 )
1205 }
1206 };
1207
1208 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1210 headers.insert(
1211 "DD-API-KEY",
1212 HeaderValue::from_str(local_key.key.as_str())
1213 .expect("failed to parse DD-API-KEY header"),
1214 );
1215 };
1216 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1217 headers.insert(
1218 "DD-APPLICATION-KEY",
1219 HeaderValue::from_str(local_key.key.as_str())
1220 .expect("failed to parse DD-APPLICATION-KEY header"),
1221 );
1222 };
1223
1224 local_req_builder = local_req_builder.headers(headers);
1225 let local_req = local_req_builder.build()?;
1226 log::debug!("request content: {:?}", local_req.body());
1227 let local_resp = local_client.execute(local_req).await?;
1228
1229 let local_status = local_resp.status();
1230 let local_content = local_resp.text().await?;
1231 log::debug!("response content: {}", local_content);
1232
1233 if !local_status.is_client_error() && !local_status.is_server_error() {
1234 match serde_json::from_str::<crate::datadogV2::model::BudgetWithEntries>(&local_content)
1235 {
1236 Ok(e) => {
1237 return Ok(datadog::ResponseContent {
1238 status: local_status,
1239 content: local_content,
1240 entity: Some(e),
1241 })
1242 }
1243 Err(e) => return Err(datadog::Error::Serde(e)),
1244 };
1245 } else {
1246 let local_entity: Option<GetBudgetError> = serde_json::from_str(&local_content).ok();
1247 let local_error = datadog::ResponseContent {
1248 status: local_status,
1249 content: local_content,
1250 entity: local_entity,
1251 };
1252 Err(datadog::Error::ResponseError(local_error))
1253 }
1254 }
1255
1256 pub async fn get_custom_costs_file(
1258 &self,
1259 file_id: String,
1260 ) -> Result<
1261 crate::datadogV2::model::CustomCostsFileGetResponse,
1262 datadog::Error<GetCustomCostsFileError>,
1263 > {
1264 match self.get_custom_costs_file_with_http_info(file_id).await {
1265 Ok(response_content) => {
1266 if let Some(e) = response_content.entity {
1267 Ok(e)
1268 } else {
1269 Err(datadog::Error::Serde(serde::de::Error::custom(
1270 "response content was None",
1271 )))
1272 }
1273 }
1274 Err(err) => Err(err),
1275 }
1276 }
1277
1278 pub async fn get_custom_costs_file_with_http_info(
1280 &self,
1281 file_id: String,
1282 ) -> Result<
1283 datadog::ResponseContent<crate::datadogV2::model::CustomCostsFileGetResponse>,
1284 datadog::Error<GetCustomCostsFileError>,
1285 > {
1286 let local_configuration = &self.config;
1287 let operation_id = "v2.get_custom_costs_file";
1288
1289 let local_client = &self.client;
1290
1291 let local_uri_str = format!(
1292 "{}/api/v2/cost/custom_costs/{file_id}",
1293 local_configuration.get_operation_host(operation_id),
1294 file_id = datadog::urlencode(file_id)
1295 );
1296 let mut local_req_builder =
1297 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1298
1299 let mut headers = HeaderMap::new();
1301 headers.insert("Accept", HeaderValue::from_static("application/json"));
1302
1303 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1305 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1306 Err(e) => {
1307 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1308 headers.insert(
1309 reqwest::header::USER_AGENT,
1310 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1311 )
1312 }
1313 };
1314
1315 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1317 headers.insert(
1318 "DD-API-KEY",
1319 HeaderValue::from_str(local_key.key.as_str())
1320 .expect("failed to parse DD-API-KEY header"),
1321 );
1322 };
1323 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1324 headers.insert(
1325 "DD-APPLICATION-KEY",
1326 HeaderValue::from_str(local_key.key.as_str())
1327 .expect("failed to parse DD-APPLICATION-KEY header"),
1328 );
1329 };
1330
1331 local_req_builder = local_req_builder.headers(headers);
1332 let local_req = local_req_builder.build()?;
1333 log::debug!("request content: {:?}", local_req.body());
1334 let local_resp = local_client.execute(local_req).await?;
1335
1336 let local_status = local_resp.status();
1337 let local_content = local_resp.text().await?;
1338 log::debug!("response content: {}", local_content);
1339
1340 if !local_status.is_client_error() && !local_status.is_server_error() {
1341 match serde_json::from_str::<crate::datadogV2::model::CustomCostsFileGetResponse>(
1342 &local_content,
1343 ) {
1344 Ok(e) => {
1345 return Ok(datadog::ResponseContent {
1346 status: local_status,
1347 content: local_content,
1348 entity: Some(e),
1349 })
1350 }
1351 Err(e) => return Err(datadog::Error::Serde(e)),
1352 };
1353 } else {
1354 let local_entity: Option<GetCustomCostsFileError> =
1355 serde_json::from_str(&local_content).ok();
1356 let local_error = datadog::ResponseContent {
1357 status: local_status,
1358 content: local_content,
1359 entity: local_entity,
1360 };
1361 Err(datadog::Error::ResponseError(local_error))
1362 }
1363 }
1364
1365 pub async fn list_budgets(
1367 &self,
1368 ) -> Result<crate::datadogV2::model::BudgetArray, datadog::Error<ListBudgetsError>> {
1369 match self.list_budgets_with_http_info().await {
1370 Ok(response_content) => {
1371 if let Some(e) = response_content.entity {
1372 Ok(e)
1373 } else {
1374 Err(datadog::Error::Serde(serde::de::Error::custom(
1375 "response content was None",
1376 )))
1377 }
1378 }
1379 Err(err) => Err(err),
1380 }
1381 }
1382
1383 pub async fn list_budgets_with_http_info(
1385 &self,
1386 ) -> Result<
1387 datadog::ResponseContent<crate::datadogV2::model::BudgetArray>,
1388 datadog::Error<ListBudgetsError>,
1389 > {
1390 let local_configuration = &self.config;
1391 let operation_id = "v2.list_budgets";
1392
1393 let local_client = &self.client;
1394
1395 let local_uri_str = format!(
1396 "{}/api/v2/cost/budgets",
1397 local_configuration.get_operation_host(operation_id)
1398 );
1399 let mut local_req_builder =
1400 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1401
1402 let mut headers = HeaderMap::new();
1404 headers.insert("Accept", HeaderValue::from_static("application/json"));
1405
1406 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1408 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1409 Err(e) => {
1410 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1411 headers.insert(
1412 reqwest::header::USER_AGENT,
1413 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1414 )
1415 }
1416 };
1417
1418 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1420 headers.insert(
1421 "DD-API-KEY",
1422 HeaderValue::from_str(local_key.key.as_str())
1423 .expect("failed to parse DD-API-KEY header"),
1424 );
1425 };
1426 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1427 headers.insert(
1428 "DD-APPLICATION-KEY",
1429 HeaderValue::from_str(local_key.key.as_str())
1430 .expect("failed to parse DD-APPLICATION-KEY header"),
1431 );
1432 };
1433
1434 local_req_builder = local_req_builder.headers(headers);
1435 let local_req = local_req_builder.build()?;
1436 log::debug!("request content: {:?}", local_req.body());
1437 let local_resp = local_client.execute(local_req).await?;
1438
1439 let local_status = local_resp.status();
1440 let local_content = local_resp.text().await?;
1441 log::debug!("response content: {}", local_content);
1442
1443 if !local_status.is_client_error() && !local_status.is_server_error() {
1444 match serde_json::from_str::<crate::datadogV2::model::BudgetArray>(&local_content) {
1445 Ok(e) => {
1446 return Ok(datadog::ResponseContent {
1447 status: local_status,
1448 content: local_content,
1449 entity: Some(e),
1450 })
1451 }
1452 Err(e) => return Err(datadog::Error::Serde(e)),
1453 };
1454 } else {
1455 let local_entity: Option<ListBudgetsError> = serde_json::from_str(&local_content).ok();
1456 let local_error = datadog::ResponseContent {
1457 status: local_status,
1458 content: local_content,
1459 entity: local_entity,
1460 };
1461 Err(datadog::Error::ResponseError(local_error))
1462 }
1463 }
1464
1465 pub async fn list_cost_awscur_configs(
1467 &self,
1468 ) -> Result<
1469 crate::datadogV2::model::AwsCURConfigsResponse,
1470 datadog::Error<ListCostAWSCURConfigsError>,
1471 > {
1472 match self.list_cost_awscur_configs_with_http_info().await {
1473 Ok(response_content) => {
1474 if let Some(e) = response_content.entity {
1475 Ok(e)
1476 } else {
1477 Err(datadog::Error::Serde(serde::de::Error::custom(
1478 "response content was None",
1479 )))
1480 }
1481 }
1482 Err(err) => Err(err),
1483 }
1484 }
1485
1486 pub async fn list_cost_awscur_configs_with_http_info(
1488 &self,
1489 ) -> Result<
1490 datadog::ResponseContent<crate::datadogV2::model::AwsCURConfigsResponse>,
1491 datadog::Error<ListCostAWSCURConfigsError>,
1492 > {
1493 let local_configuration = &self.config;
1494 let operation_id = "v2.list_cost_awscur_configs";
1495
1496 let local_client = &self.client;
1497
1498 let local_uri_str = format!(
1499 "{}/api/v2/cost/aws_cur_config",
1500 local_configuration.get_operation_host(operation_id)
1501 );
1502 let mut local_req_builder =
1503 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1504
1505 let mut headers = HeaderMap::new();
1507 headers.insert("Accept", HeaderValue::from_static("application/json"));
1508
1509 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1511 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1512 Err(e) => {
1513 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1514 headers.insert(
1515 reqwest::header::USER_AGENT,
1516 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1517 )
1518 }
1519 };
1520
1521 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1523 headers.insert(
1524 "DD-API-KEY",
1525 HeaderValue::from_str(local_key.key.as_str())
1526 .expect("failed to parse DD-API-KEY header"),
1527 );
1528 };
1529 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1530 headers.insert(
1531 "DD-APPLICATION-KEY",
1532 HeaderValue::from_str(local_key.key.as_str())
1533 .expect("failed to parse DD-APPLICATION-KEY header"),
1534 );
1535 };
1536
1537 local_req_builder = local_req_builder.headers(headers);
1538 let local_req = local_req_builder.build()?;
1539 log::debug!("request content: {:?}", local_req.body());
1540 let local_resp = local_client.execute(local_req).await?;
1541
1542 let local_status = local_resp.status();
1543 let local_content = local_resp.text().await?;
1544 log::debug!("response content: {}", local_content);
1545
1546 if !local_status.is_client_error() && !local_status.is_server_error() {
1547 match serde_json::from_str::<crate::datadogV2::model::AwsCURConfigsResponse>(
1548 &local_content,
1549 ) {
1550 Ok(e) => {
1551 return Ok(datadog::ResponseContent {
1552 status: local_status,
1553 content: local_content,
1554 entity: Some(e),
1555 })
1556 }
1557 Err(e) => return Err(datadog::Error::Serde(e)),
1558 };
1559 } else {
1560 let local_entity: Option<ListCostAWSCURConfigsError> =
1561 serde_json::from_str(&local_content).ok();
1562 let local_error = datadog::ResponseContent {
1563 status: local_status,
1564 content: local_content,
1565 entity: local_entity,
1566 };
1567 Err(datadog::Error::ResponseError(local_error))
1568 }
1569 }
1570
1571 pub async fn list_cost_azure_uc_configs(
1573 &self,
1574 ) -> Result<
1575 crate::datadogV2::model::AzureUCConfigsResponse,
1576 datadog::Error<ListCostAzureUCConfigsError>,
1577 > {
1578 match self.list_cost_azure_uc_configs_with_http_info().await {
1579 Ok(response_content) => {
1580 if let Some(e) = response_content.entity {
1581 Ok(e)
1582 } else {
1583 Err(datadog::Error::Serde(serde::de::Error::custom(
1584 "response content was None",
1585 )))
1586 }
1587 }
1588 Err(err) => Err(err),
1589 }
1590 }
1591
1592 pub async fn list_cost_azure_uc_configs_with_http_info(
1594 &self,
1595 ) -> Result<
1596 datadog::ResponseContent<crate::datadogV2::model::AzureUCConfigsResponse>,
1597 datadog::Error<ListCostAzureUCConfigsError>,
1598 > {
1599 let local_configuration = &self.config;
1600 let operation_id = "v2.list_cost_azure_uc_configs";
1601
1602 let local_client = &self.client;
1603
1604 let local_uri_str = format!(
1605 "{}/api/v2/cost/azure_uc_config",
1606 local_configuration.get_operation_host(operation_id)
1607 );
1608 let mut local_req_builder =
1609 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1610
1611 let mut headers = HeaderMap::new();
1613 headers.insert("Accept", HeaderValue::from_static("application/json"));
1614
1615 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1617 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1618 Err(e) => {
1619 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1620 headers.insert(
1621 reqwest::header::USER_AGENT,
1622 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1623 )
1624 }
1625 };
1626
1627 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1629 headers.insert(
1630 "DD-API-KEY",
1631 HeaderValue::from_str(local_key.key.as_str())
1632 .expect("failed to parse DD-API-KEY header"),
1633 );
1634 };
1635 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1636 headers.insert(
1637 "DD-APPLICATION-KEY",
1638 HeaderValue::from_str(local_key.key.as_str())
1639 .expect("failed to parse DD-APPLICATION-KEY header"),
1640 );
1641 };
1642
1643 local_req_builder = local_req_builder.headers(headers);
1644 let local_req = local_req_builder.build()?;
1645 log::debug!("request content: {:?}", local_req.body());
1646 let local_resp = local_client.execute(local_req).await?;
1647
1648 let local_status = local_resp.status();
1649 let local_content = local_resp.text().await?;
1650 log::debug!("response content: {}", local_content);
1651
1652 if !local_status.is_client_error() && !local_status.is_server_error() {
1653 match serde_json::from_str::<crate::datadogV2::model::AzureUCConfigsResponse>(
1654 &local_content,
1655 ) {
1656 Ok(e) => {
1657 return Ok(datadog::ResponseContent {
1658 status: local_status,
1659 content: local_content,
1660 entity: Some(e),
1661 })
1662 }
1663 Err(e) => return Err(datadog::Error::Serde(e)),
1664 };
1665 } else {
1666 let local_entity: Option<ListCostAzureUCConfigsError> =
1667 serde_json::from_str(&local_content).ok();
1668 let local_error = datadog::ResponseContent {
1669 status: local_status,
1670 content: local_content,
1671 entity: local_entity,
1672 };
1673 Err(datadog::Error::ResponseError(local_error))
1674 }
1675 }
1676
1677 pub async fn list_cost_gcp_usage_cost_configs(
1679 &self,
1680 ) -> Result<
1681 crate::datadogV2::model::GCPUsageCostConfigsResponse,
1682 datadog::Error<ListCostGCPUsageCostConfigsError>,
1683 > {
1684 match self.list_cost_gcp_usage_cost_configs_with_http_info().await {
1685 Ok(response_content) => {
1686 if let Some(e) = response_content.entity {
1687 Ok(e)
1688 } else {
1689 Err(datadog::Error::Serde(serde::de::Error::custom(
1690 "response content was None",
1691 )))
1692 }
1693 }
1694 Err(err) => Err(err),
1695 }
1696 }
1697
1698 pub async fn list_cost_gcp_usage_cost_configs_with_http_info(
1700 &self,
1701 ) -> Result<
1702 datadog::ResponseContent<crate::datadogV2::model::GCPUsageCostConfigsResponse>,
1703 datadog::Error<ListCostGCPUsageCostConfigsError>,
1704 > {
1705 let local_configuration = &self.config;
1706 let operation_id = "v2.list_cost_gcp_usage_cost_configs";
1707
1708 let local_client = &self.client;
1709
1710 let local_uri_str = format!(
1711 "{}/api/v2/cost/gcp_uc_config",
1712 local_configuration.get_operation_host(operation_id)
1713 );
1714 let mut local_req_builder =
1715 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1716
1717 let mut headers = HeaderMap::new();
1719 headers.insert("Accept", HeaderValue::from_static("application/json"));
1720
1721 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1723 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1724 Err(e) => {
1725 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1726 headers.insert(
1727 reqwest::header::USER_AGENT,
1728 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1729 )
1730 }
1731 };
1732
1733 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1735 headers.insert(
1736 "DD-API-KEY",
1737 HeaderValue::from_str(local_key.key.as_str())
1738 .expect("failed to parse DD-API-KEY header"),
1739 );
1740 };
1741 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1742 headers.insert(
1743 "DD-APPLICATION-KEY",
1744 HeaderValue::from_str(local_key.key.as_str())
1745 .expect("failed to parse DD-APPLICATION-KEY header"),
1746 );
1747 };
1748
1749 local_req_builder = local_req_builder.headers(headers);
1750 let local_req = local_req_builder.build()?;
1751 log::debug!("request content: {:?}", local_req.body());
1752 let local_resp = local_client.execute(local_req).await?;
1753
1754 let local_status = local_resp.status();
1755 let local_content = local_resp.text().await?;
1756 log::debug!("response content: {}", local_content);
1757
1758 if !local_status.is_client_error() && !local_status.is_server_error() {
1759 match serde_json::from_str::<crate::datadogV2::model::GCPUsageCostConfigsResponse>(
1760 &local_content,
1761 ) {
1762 Ok(e) => {
1763 return Ok(datadog::ResponseContent {
1764 status: local_status,
1765 content: local_content,
1766 entity: Some(e),
1767 })
1768 }
1769 Err(e) => return Err(datadog::Error::Serde(e)),
1770 };
1771 } else {
1772 let local_entity: Option<ListCostGCPUsageCostConfigsError> =
1773 serde_json::from_str(&local_content).ok();
1774 let local_error = datadog::ResponseContent {
1775 status: local_status,
1776 content: local_content,
1777 entity: local_entity,
1778 };
1779 Err(datadog::Error::ResponseError(local_error))
1780 }
1781 }
1782
1783 pub async fn list_custom_costs_files(
1785 &self,
1786 ) -> Result<
1787 crate::datadogV2::model::CustomCostsFileListResponse,
1788 datadog::Error<ListCustomCostsFilesError>,
1789 > {
1790 match self.list_custom_costs_files_with_http_info().await {
1791 Ok(response_content) => {
1792 if let Some(e) = response_content.entity {
1793 Ok(e)
1794 } else {
1795 Err(datadog::Error::Serde(serde::de::Error::custom(
1796 "response content was None",
1797 )))
1798 }
1799 }
1800 Err(err) => Err(err),
1801 }
1802 }
1803
1804 pub async fn list_custom_costs_files_with_http_info(
1806 &self,
1807 ) -> Result<
1808 datadog::ResponseContent<crate::datadogV2::model::CustomCostsFileListResponse>,
1809 datadog::Error<ListCustomCostsFilesError>,
1810 > {
1811 let local_configuration = &self.config;
1812 let operation_id = "v2.list_custom_costs_files";
1813
1814 let local_client = &self.client;
1815
1816 let local_uri_str = format!(
1817 "{}/api/v2/cost/custom_costs",
1818 local_configuration.get_operation_host(operation_id)
1819 );
1820 let mut local_req_builder =
1821 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1822
1823 let mut headers = HeaderMap::new();
1825 headers.insert("Accept", HeaderValue::from_static("application/json"));
1826
1827 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1829 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1830 Err(e) => {
1831 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1832 headers.insert(
1833 reqwest::header::USER_AGENT,
1834 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1835 )
1836 }
1837 };
1838
1839 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1841 headers.insert(
1842 "DD-API-KEY",
1843 HeaderValue::from_str(local_key.key.as_str())
1844 .expect("failed to parse DD-API-KEY header"),
1845 );
1846 };
1847 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1848 headers.insert(
1849 "DD-APPLICATION-KEY",
1850 HeaderValue::from_str(local_key.key.as_str())
1851 .expect("failed to parse DD-APPLICATION-KEY header"),
1852 );
1853 };
1854
1855 local_req_builder = local_req_builder.headers(headers);
1856 let local_req = local_req_builder.build()?;
1857 log::debug!("request content: {:?}", local_req.body());
1858 let local_resp = local_client.execute(local_req).await?;
1859
1860 let local_status = local_resp.status();
1861 let local_content = local_resp.text().await?;
1862 log::debug!("response content: {}", local_content);
1863
1864 if !local_status.is_client_error() && !local_status.is_server_error() {
1865 match serde_json::from_str::<crate::datadogV2::model::CustomCostsFileListResponse>(
1866 &local_content,
1867 ) {
1868 Ok(e) => {
1869 return Ok(datadog::ResponseContent {
1870 status: local_status,
1871 content: local_content,
1872 entity: Some(e),
1873 })
1874 }
1875 Err(e) => return Err(datadog::Error::Serde(e)),
1876 };
1877 } else {
1878 let local_entity: Option<ListCustomCostsFilesError> =
1879 serde_json::from_str(&local_content).ok();
1880 let local_error = datadog::ResponseContent {
1881 status: local_status,
1882 content: local_content,
1883 entity: local_entity,
1884 };
1885 Err(datadog::Error::ResponseError(local_error))
1886 }
1887 }
1888
1889 pub async fn update_cost_awscur_config(
1891 &self,
1892 cloud_account_id: String,
1893 body: crate::datadogV2::model::AwsCURConfigPatchRequest,
1894 ) -> Result<
1895 crate::datadogV2::model::AwsCURConfigsResponse,
1896 datadog::Error<UpdateCostAWSCURConfigError>,
1897 > {
1898 match self
1899 .update_cost_awscur_config_with_http_info(cloud_account_id, body)
1900 .await
1901 {
1902 Ok(response_content) => {
1903 if let Some(e) = response_content.entity {
1904 Ok(e)
1905 } else {
1906 Err(datadog::Error::Serde(serde::de::Error::custom(
1907 "response content was None",
1908 )))
1909 }
1910 }
1911 Err(err) => Err(err),
1912 }
1913 }
1914
1915 pub async fn update_cost_awscur_config_with_http_info(
1917 &self,
1918 cloud_account_id: String,
1919 body: crate::datadogV2::model::AwsCURConfigPatchRequest,
1920 ) -> Result<
1921 datadog::ResponseContent<crate::datadogV2::model::AwsCURConfigsResponse>,
1922 datadog::Error<UpdateCostAWSCURConfigError>,
1923 > {
1924 let local_configuration = &self.config;
1925 let operation_id = "v2.update_cost_awscur_config";
1926
1927 let local_client = &self.client;
1928
1929 let local_uri_str = format!(
1930 "{}/api/v2/cost/aws_cur_config/{cloud_account_id}",
1931 local_configuration.get_operation_host(operation_id),
1932 cloud_account_id = datadog::urlencode(cloud_account_id)
1933 );
1934 let mut local_req_builder =
1935 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1936
1937 let mut headers = HeaderMap::new();
1939 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1940 headers.insert("Accept", HeaderValue::from_static("application/json"));
1941
1942 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1944 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1945 Err(e) => {
1946 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1947 headers.insert(
1948 reqwest::header::USER_AGENT,
1949 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1950 )
1951 }
1952 };
1953
1954 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1956 headers.insert(
1957 "DD-API-KEY",
1958 HeaderValue::from_str(local_key.key.as_str())
1959 .expect("failed to parse DD-API-KEY header"),
1960 );
1961 };
1962 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1963 headers.insert(
1964 "DD-APPLICATION-KEY",
1965 HeaderValue::from_str(local_key.key.as_str())
1966 .expect("failed to parse DD-APPLICATION-KEY header"),
1967 );
1968 };
1969
1970 let output = Vec::new();
1972 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1973 if body.serialize(&mut ser).is_ok() {
1974 if let Some(content_encoding) = headers.get("Content-Encoding") {
1975 match content_encoding.to_str().unwrap_or_default() {
1976 "gzip" => {
1977 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1978 let _ = enc.write_all(ser.into_inner().as_slice());
1979 match enc.finish() {
1980 Ok(buf) => {
1981 local_req_builder = local_req_builder.body(buf);
1982 }
1983 Err(e) => return Err(datadog::Error::Io(e)),
1984 }
1985 }
1986 "deflate" => {
1987 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1988 let _ = enc.write_all(ser.into_inner().as_slice());
1989 match enc.finish() {
1990 Ok(buf) => {
1991 local_req_builder = local_req_builder.body(buf);
1992 }
1993 Err(e) => return Err(datadog::Error::Io(e)),
1994 }
1995 }
1996 "zstd1" => {
1997 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1998 let _ = enc.write_all(ser.into_inner().as_slice());
1999 match enc.finish() {
2000 Ok(buf) => {
2001 local_req_builder = local_req_builder.body(buf);
2002 }
2003 Err(e) => return Err(datadog::Error::Io(e)),
2004 }
2005 }
2006 _ => {
2007 local_req_builder = local_req_builder.body(ser.into_inner());
2008 }
2009 }
2010 } else {
2011 local_req_builder = local_req_builder.body(ser.into_inner());
2012 }
2013 }
2014
2015 local_req_builder = local_req_builder.headers(headers);
2016 let local_req = local_req_builder.build()?;
2017 log::debug!("request content: {:?}", local_req.body());
2018 let local_resp = local_client.execute(local_req).await?;
2019
2020 let local_status = local_resp.status();
2021 let local_content = local_resp.text().await?;
2022 log::debug!("response content: {}", local_content);
2023
2024 if !local_status.is_client_error() && !local_status.is_server_error() {
2025 match serde_json::from_str::<crate::datadogV2::model::AwsCURConfigsResponse>(
2026 &local_content,
2027 ) {
2028 Ok(e) => {
2029 return Ok(datadog::ResponseContent {
2030 status: local_status,
2031 content: local_content,
2032 entity: Some(e),
2033 })
2034 }
2035 Err(e) => return Err(datadog::Error::Serde(e)),
2036 };
2037 } else {
2038 let local_entity: Option<UpdateCostAWSCURConfigError> =
2039 serde_json::from_str(&local_content).ok();
2040 let local_error = datadog::ResponseContent {
2041 status: local_status,
2042 content: local_content,
2043 entity: local_entity,
2044 };
2045 Err(datadog::Error::ResponseError(local_error))
2046 }
2047 }
2048
2049 pub async fn update_cost_azure_uc_configs(
2051 &self,
2052 cloud_account_id: String,
2053 body: crate::datadogV2::model::AzureUCConfigPatchRequest,
2054 ) -> Result<
2055 crate::datadogV2::model::AzureUCConfigPairsResponse,
2056 datadog::Error<UpdateCostAzureUCConfigsError>,
2057 > {
2058 match self
2059 .update_cost_azure_uc_configs_with_http_info(cloud_account_id, body)
2060 .await
2061 {
2062 Ok(response_content) => {
2063 if let Some(e) = response_content.entity {
2064 Ok(e)
2065 } else {
2066 Err(datadog::Error::Serde(serde::de::Error::custom(
2067 "response content was None",
2068 )))
2069 }
2070 }
2071 Err(err) => Err(err),
2072 }
2073 }
2074
2075 pub async fn update_cost_azure_uc_configs_with_http_info(
2077 &self,
2078 cloud_account_id: String,
2079 body: crate::datadogV2::model::AzureUCConfigPatchRequest,
2080 ) -> Result<
2081 datadog::ResponseContent<crate::datadogV2::model::AzureUCConfigPairsResponse>,
2082 datadog::Error<UpdateCostAzureUCConfigsError>,
2083 > {
2084 let local_configuration = &self.config;
2085 let operation_id = "v2.update_cost_azure_uc_configs";
2086
2087 let local_client = &self.client;
2088
2089 let local_uri_str = format!(
2090 "{}/api/v2/cost/azure_uc_config/{cloud_account_id}",
2091 local_configuration.get_operation_host(operation_id),
2092 cloud_account_id = datadog::urlencode(cloud_account_id)
2093 );
2094 let mut local_req_builder =
2095 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2096
2097 let mut headers = HeaderMap::new();
2099 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2100 headers.insert("Accept", HeaderValue::from_static("application/json"));
2101
2102 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2104 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2105 Err(e) => {
2106 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2107 headers.insert(
2108 reqwest::header::USER_AGENT,
2109 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2110 )
2111 }
2112 };
2113
2114 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2116 headers.insert(
2117 "DD-API-KEY",
2118 HeaderValue::from_str(local_key.key.as_str())
2119 .expect("failed to parse DD-API-KEY header"),
2120 );
2121 };
2122 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2123 headers.insert(
2124 "DD-APPLICATION-KEY",
2125 HeaderValue::from_str(local_key.key.as_str())
2126 .expect("failed to parse DD-APPLICATION-KEY header"),
2127 );
2128 };
2129
2130 let output = Vec::new();
2132 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2133 if body.serialize(&mut ser).is_ok() {
2134 if let Some(content_encoding) = headers.get("Content-Encoding") {
2135 match content_encoding.to_str().unwrap_or_default() {
2136 "gzip" => {
2137 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2138 let _ = enc.write_all(ser.into_inner().as_slice());
2139 match enc.finish() {
2140 Ok(buf) => {
2141 local_req_builder = local_req_builder.body(buf);
2142 }
2143 Err(e) => return Err(datadog::Error::Io(e)),
2144 }
2145 }
2146 "deflate" => {
2147 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2148 let _ = enc.write_all(ser.into_inner().as_slice());
2149 match enc.finish() {
2150 Ok(buf) => {
2151 local_req_builder = local_req_builder.body(buf);
2152 }
2153 Err(e) => return Err(datadog::Error::Io(e)),
2154 }
2155 }
2156 "zstd1" => {
2157 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2158 let _ = enc.write_all(ser.into_inner().as_slice());
2159 match enc.finish() {
2160 Ok(buf) => {
2161 local_req_builder = local_req_builder.body(buf);
2162 }
2163 Err(e) => return Err(datadog::Error::Io(e)),
2164 }
2165 }
2166 _ => {
2167 local_req_builder = local_req_builder.body(ser.into_inner());
2168 }
2169 }
2170 } else {
2171 local_req_builder = local_req_builder.body(ser.into_inner());
2172 }
2173 }
2174
2175 local_req_builder = local_req_builder.headers(headers);
2176 let local_req = local_req_builder.build()?;
2177 log::debug!("request content: {:?}", local_req.body());
2178 let local_resp = local_client.execute(local_req).await?;
2179
2180 let local_status = local_resp.status();
2181 let local_content = local_resp.text().await?;
2182 log::debug!("response content: {}", local_content);
2183
2184 if !local_status.is_client_error() && !local_status.is_server_error() {
2185 match serde_json::from_str::<crate::datadogV2::model::AzureUCConfigPairsResponse>(
2186 &local_content,
2187 ) {
2188 Ok(e) => {
2189 return Ok(datadog::ResponseContent {
2190 status: local_status,
2191 content: local_content,
2192 entity: Some(e),
2193 })
2194 }
2195 Err(e) => return Err(datadog::Error::Serde(e)),
2196 };
2197 } else {
2198 let local_entity: Option<UpdateCostAzureUCConfigsError> =
2199 serde_json::from_str(&local_content).ok();
2200 let local_error = datadog::ResponseContent {
2201 status: local_status,
2202 content: local_content,
2203 entity: local_entity,
2204 };
2205 Err(datadog::Error::ResponseError(local_error))
2206 }
2207 }
2208
2209 pub async fn update_cost_gcp_usage_cost_config(
2211 &self,
2212 cloud_account_id: String,
2213 body: crate::datadogV2::model::GCPUsageCostConfigPatchRequest,
2214 ) -> Result<
2215 crate::datadogV2::model::GCPUsageCostConfigResponse,
2216 datadog::Error<UpdateCostGCPUsageCostConfigError>,
2217 > {
2218 match self
2219 .update_cost_gcp_usage_cost_config_with_http_info(cloud_account_id, body)
2220 .await
2221 {
2222 Ok(response_content) => {
2223 if let Some(e) = response_content.entity {
2224 Ok(e)
2225 } else {
2226 Err(datadog::Error::Serde(serde::de::Error::custom(
2227 "response content was None",
2228 )))
2229 }
2230 }
2231 Err(err) => Err(err),
2232 }
2233 }
2234
2235 pub async fn update_cost_gcp_usage_cost_config_with_http_info(
2237 &self,
2238 cloud_account_id: String,
2239 body: crate::datadogV2::model::GCPUsageCostConfigPatchRequest,
2240 ) -> Result<
2241 datadog::ResponseContent<crate::datadogV2::model::GCPUsageCostConfigResponse>,
2242 datadog::Error<UpdateCostGCPUsageCostConfigError>,
2243 > {
2244 let local_configuration = &self.config;
2245 let operation_id = "v2.update_cost_gcp_usage_cost_config";
2246
2247 let local_client = &self.client;
2248
2249 let local_uri_str = format!(
2250 "{}/api/v2/cost/gcp_uc_config/{cloud_account_id}",
2251 local_configuration.get_operation_host(operation_id),
2252 cloud_account_id = datadog::urlencode(cloud_account_id)
2253 );
2254 let mut local_req_builder =
2255 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2256
2257 let mut headers = HeaderMap::new();
2259 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2260 headers.insert("Accept", HeaderValue::from_static("application/json"));
2261
2262 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2264 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2265 Err(e) => {
2266 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2267 headers.insert(
2268 reqwest::header::USER_AGENT,
2269 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2270 )
2271 }
2272 };
2273
2274 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2276 headers.insert(
2277 "DD-API-KEY",
2278 HeaderValue::from_str(local_key.key.as_str())
2279 .expect("failed to parse DD-API-KEY header"),
2280 );
2281 };
2282 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2283 headers.insert(
2284 "DD-APPLICATION-KEY",
2285 HeaderValue::from_str(local_key.key.as_str())
2286 .expect("failed to parse DD-APPLICATION-KEY header"),
2287 );
2288 };
2289
2290 let output = Vec::new();
2292 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2293 if body.serialize(&mut ser).is_ok() {
2294 if let Some(content_encoding) = headers.get("Content-Encoding") {
2295 match content_encoding.to_str().unwrap_or_default() {
2296 "gzip" => {
2297 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2298 let _ = enc.write_all(ser.into_inner().as_slice());
2299 match enc.finish() {
2300 Ok(buf) => {
2301 local_req_builder = local_req_builder.body(buf);
2302 }
2303 Err(e) => return Err(datadog::Error::Io(e)),
2304 }
2305 }
2306 "deflate" => {
2307 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2308 let _ = enc.write_all(ser.into_inner().as_slice());
2309 match enc.finish() {
2310 Ok(buf) => {
2311 local_req_builder = local_req_builder.body(buf);
2312 }
2313 Err(e) => return Err(datadog::Error::Io(e)),
2314 }
2315 }
2316 "zstd1" => {
2317 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2318 let _ = enc.write_all(ser.into_inner().as_slice());
2319 match enc.finish() {
2320 Ok(buf) => {
2321 local_req_builder = local_req_builder.body(buf);
2322 }
2323 Err(e) => return Err(datadog::Error::Io(e)),
2324 }
2325 }
2326 _ => {
2327 local_req_builder = local_req_builder.body(ser.into_inner());
2328 }
2329 }
2330 } else {
2331 local_req_builder = local_req_builder.body(ser.into_inner());
2332 }
2333 }
2334
2335 local_req_builder = local_req_builder.headers(headers);
2336 let local_req = local_req_builder.build()?;
2337 log::debug!("request content: {:?}", local_req.body());
2338 let local_resp = local_client.execute(local_req).await?;
2339
2340 let local_status = local_resp.status();
2341 let local_content = local_resp.text().await?;
2342 log::debug!("response content: {}", local_content);
2343
2344 if !local_status.is_client_error() && !local_status.is_server_error() {
2345 match serde_json::from_str::<crate::datadogV2::model::GCPUsageCostConfigResponse>(
2346 &local_content,
2347 ) {
2348 Ok(e) => {
2349 return Ok(datadog::ResponseContent {
2350 status: local_status,
2351 content: local_content,
2352 entity: Some(e),
2353 })
2354 }
2355 Err(e) => return Err(datadog::Error::Serde(e)),
2356 };
2357 } else {
2358 let local_entity: Option<UpdateCostGCPUsageCostConfigError> =
2359 serde_json::from_str(&local_content).ok();
2360 let local_error = datadog::ResponseContent {
2361 status: local_status,
2362 content: local_content,
2363 entity: local_entity,
2364 };
2365 Err(datadog::Error::ResponseError(local_error))
2366 }
2367 }
2368
2369 pub async fn upload_custom_costs_file(
2371 &self,
2372 body: Vec<crate::datadogV2::model::CustomCostsFileLineItem>,
2373 ) -> Result<
2374 crate::datadogV2::model::CustomCostsFileUploadResponse,
2375 datadog::Error<UploadCustomCostsFileError>,
2376 > {
2377 match self.upload_custom_costs_file_with_http_info(body).await {
2378 Ok(response_content) => {
2379 if let Some(e) = response_content.entity {
2380 Ok(e)
2381 } else {
2382 Err(datadog::Error::Serde(serde::de::Error::custom(
2383 "response content was None",
2384 )))
2385 }
2386 }
2387 Err(err) => Err(err),
2388 }
2389 }
2390
2391 pub async fn upload_custom_costs_file_with_http_info(
2393 &self,
2394 body: Vec<crate::datadogV2::model::CustomCostsFileLineItem>,
2395 ) -> Result<
2396 datadog::ResponseContent<crate::datadogV2::model::CustomCostsFileUploadResponse>,
2397 datadog::Error<UploadCustomCostsFileError>,
2398 > {
2399 let local_configuration = &self.config;
2400 let operation_id = "v2.upload_custom_costs_file";
2401
2402 let local_client = &self.client;
2403
2404 let local_uri_str = format!(
2405 "{}/api/v2/cost/custom_costs",
2406 local_configuration.get_operation_host(operation_id)
2407 );
2408 let mut local_req_builder =
2409 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
2410
2411 let mut headers = HeaderMap::new();
2413 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2414 headers.insert("Accept", HeaderValue::from_static("application/json"));
2415
2416 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2418 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2419 Err(e) => {
2420 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2421 headers.insert(
2422 reqwest::header::USER_AGENT,
2423 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2424 )
2425 }
2426 };
2427
2428 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2430 headers.insert(
2431 "DD-API-KEY",
2432 HeaderValue::from_str(local_key.key.as_str())
2433 .expect("failed to parse DD-API-KEY header"),
2434 );
2435 };
2436 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2437 headers.insert(
2438 "DD-APPLICATION-KEY",
2439 HeaderValue::from_str(local_key.key.as_str())
2440 .expect("failed to parse DD-APPLICATION-KEY header"),
2441 );
2442 };
2443
2444 let output = Vec::new();
2446 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2447 if body.serialize(&mut ser).is_ok() {
2448 if let Some(content_encoding) = headers.get("Content-Encoding") {
2449 match content_encoding.to_str().unwrap_or_default() {
2450 "gzip" => {
2451 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2452 let _ = enc.write_all(ser.into_inner().as_slice());
2453 match enc.finish() {
2454 Ok(buf) => {
2455 local_req_builder = local_req_builder.body(buf);
2456 }
2457 Err(e) => return Err(datadog::Error::Io(e)),
2458 }
2459 }
2460 "deflate" => {
2461 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2462 let _ = enc.write_all(ser.into_inner().as_slice());
2463 match enc.finish() {
2464 Ok(buf) => {
2465 local_req_builder = local_req_builder.body(buf);
2466 }
2467 Err(e) => return Err(datadog::Error::Io(e)),
2468 }
2469 }
2470 "zstd1" => {
2471 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2472 let _ = enc.write_all(ser.into_inner().as_slice());
2473 match enc.finish() {
2474 Ok(buf) => {
2475 local_req_builder = local_req_builder.body(buf);
2476 }
2477 Err(e) => return Err(datadog::Error::Io(e)),
2478 }
2479 }
2480 _ => {
2481 local_req_builder = local_req_builder.body(ser.into_inner());
2482 }
2483 }
2484 } else {
2485 local_req_builder = local_req_builder.body(ser.into_inner());
2486 }
2487 }
2488
2489 local_req_builder = local_req_builder.headers(headers);
2490 let local_req = local_req_builder.build()?;
2491 log::debug!("request content: {:?}", local_req.body());
2492 let local_resp = local_client.execute(local_req).await?;
2493
2494 let local_status = local_resp.status();
2495 let local_content = local_resp.text().await?;
2496 log::debug!("response content: {}", local_content);
2497
2498 if !local_status.is_client_error() && !local_status.is_server_error() {
2499 match serde_json::from_str::<crate::datadogV2::model::CustomCostsFileUploadResponse>(
2500 &local_content,
2501 ) {
2502 Ok(e) => {
2503 return Ok(datadog::ResponseContent {
2504 status: local_status,
2505 content: local_content,
2506 entity: Some(e),
2507 })
2508 }
2509 Err(e) => return Err(datadog::Error::Serde(e)),
2510 };
2511 } else {
2512 let local_entity: Option<UploadCustomCostsFileError> =
2513 serde_json::from_str(&local_content).ok();
2514 let local_error = datadog::ResponseContent {
2515 status: local_status,
2516 content: local_content,
2517 entity: local_entity,
2518 };
2519 Err(datadog::Error::ResponseError(local_error))
2520 }
2521 }
2522
2523 pub async fn upsert_budget(
2525 &self,
2526 body: crate::datadogV2::model::BudgetWithEntries,
2527 ) -> Result<crate::datadogV2::model::BudgetWithEntries, datadog::Error<UpsertBudgetError>> {
2528 match self.upsert_budget_with_http_info(body).await {
2529 Ok(response_content) => {
2530 if let Some(e) = response_content.entity {
2531 Ok(e)
2532 } else {
2533 Err(datadog::Error::Serde(serde::de::Error::custom(
2534 "response content was None",
2535 )))
2536 }
2537 }
2538 Err(err) => Err(err),
2539 }
2540 }
2541
2542 pub async fn upsert_budget_with_http_info(
2544 &self,
2545 body: crate::datadogV2::model::BudgetWithEntries,
2546 ) -> Result<
2547 datadog::ResponseContent<crate::datadogV2::model::BudgetWithEntries>,
2548 datadog::Error<UpsertBudgetError>,
2549 > {
2550 let local_configuration = &self.config;
2551 let operation_id = "v2.upsert_budget";
2552
2553 let local_client = &self.client;
2554
2555 let local_uri_str = format!(
2556 "{}/api/v2/cost/budget",
2557 local_configuration.get_operation_host(operation_id)
2558 );
2559 let mut local_req_builder =
2560 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
2561
2562 let mut headers = HeaderMap::new();
2564 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2565 headers.insert("Accept", HeaderValue::from_static("application/json"));
2566
2567 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2569 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2570 Err(e) => {
2571 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2572 headers.insert(
2573 reqwest::header::USER_AGENT,
2574 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2575 )
2576 }
2577 };
2578
2579 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2581 headers.insert(
2582 "DD-API-KEY",
2583 HeaderValue::from_str(local_key.key.as_str())
2584 .expect("failed to parse DD-API-KEY header"),
2585 );
2586 };
2587 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2588 headers.insert(
2589 "DD-APPLICATION-KEY",
2590 HeaderValue::from_str(local_key.key.as_str())
2591 .expect("failed to parse DD-APPLICATION-KEY header"),
2592 );
2593 };
2594
2595 let output = Vec::new();
2597 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2598 if body.serialize(&mut ser).is_ok() {
2599 if let Some(content_encoding) = headers.get("Content-Encoding") {
2600 match content_encoding.to_str().unwrap_or_default() {
2601 "gzip" => {
2602 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2603 let _ = enc.write_all(ser.into_inner().as_slice());
2604 match enc.finish() {
2605 Ok(buf) => {
2606 local_req_builder = local_req_builder.body(buf);
2607 }
2608 Err(e) => return Err(datadog::Error::Io(e)),
2609 }
2610 }
2611 "deflate" => {
2612 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2613 let _ = enc.write_all(ser.into_inner().as_slice());
2614 match enc.finish() {
2615 Ok(buf) => {
2616 local_req_builder = local_req_builder.body(buf);
2617 }
2618 Err(e) => return Err(datadog::Error::Io(e)),
2619 }
2620 }
2621 "zstd1" => {
2622 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2623 let _ = enc.write_all(ser.into_inner().as_slice());
2624 match enc.finish() {
2625 Ok(buf) => {
2626 local_req_builder = local_req_builder.body(buf);
2627 }
2628 Err(e) => return Err(datadog::Error::Io(e)),
2629 }
2630 }
2631 _ => {
2632 local_req_builder = local_req_builder.body(ser.into_inner());
2633 }
2634 }
2635 } else {
2636 local_req_builder = local_req_builder.body(ser.into_inner());
2637 }
2638 }
2639
2640 local_req_builder = local_req_builder.headers(headers);
2641 let local_req = local_req_builder.build()?;
2642 log::debug!("request content: {:?}", local_req.body());
2643 let local_resp = local_client.execute(local_req).await?;
2644
2645 let local_status = local_resp.status();
2646 let local_content = local_resp.text().await?;
2647 log::debug!("response content: {}", local_content);
2648
2649 if !local_status.is_client_error() && !local_status.is_server_error() {
2650 match serde_json::from_str::<crate::datadogV2::model::BudgetWithEntries>(&local_content)
2651 {
2652 Ok(e) => {
2653 return Ok(datadog::ResponseContent {
2654 status: local_status,
2655 content: local_content,
2656 entity: Some(e),
2657 })
2658 }
2659 Err(e) => return Err(datadog::Error::Serde(e)),
2660 };
2661 } else {
2662 let local_entity: Option<UpsertBudgetError> = serde_json::from_str(&local_content).ok();
2663 let local_error = datadog::ResponseContent {
2664 status: local_status,
2665 content: local_content,
2666 entity: local_entity,
2667 };
2668 Err(datadog::Error::ResponseError(local_error))
2669 }
2670 }
2671}