1use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7 write::{GzEncoder, ZlibEncoder},
8 Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct DeleteSLOOptionalParams {
19 pub force: Option<String>,
21}
22
23impl DeleteSLOOptionalParams {
24 pub fn force(mut self, value: String) -> Self {
26 self.force = Some(value);
27 self
28 }
29}
30
31#[non_exhaustive]
33#[derive(Clone, Default, Debug)]
34pub struct GetSLOOptionalParams {
35 pub with_configured_alert_ids: Option<bool>,
37}
38
39impl GetSLOOptionalParams {
40 pub fn with_configured_alert_ids(mut self, value: bool) -> Self {
42 self.with_configured_alert_ids = Some(value);
43 self
44 }
45}
46
47#[non_exhaustive]
49#[derive(Clone, Default, Debug)]
50pub struct GetSLOHistoryOptionalParams {
51 pub target: Option<f64>,
53 pub apply_correction: Option<bool>,
56}
57
58impl GetSLOHistoryOptionalParams {
59 pub fn target(mut self, value: f64) -> Self {
61 self.target = Some(value);
62 self
63 }
64 pub fn apply_correction(mut self, value: bool) -> Self {
67 self.apply_correction = Some(value);
68 self
69 }
70}
71
72#[non_exhaustive]
74#[derive(Clone, Default, Debug)]
75pub struct ListSLOsOptionalParams {
76 pub ids: Option<String>,
78 pub query: Option<String>,
80 pub tags_query: Option<String>,
82 pub metrics_query: Option<String>,
84 pub limit: Option<i64>,
86 pub offset: Option<i64>,
88}
89
90impl ListSLOsOptionalParams {
91 pub fn ids(mut self, value: String) -> Self {
93 self.ids = Some(value);
94 self
95 }
96 pub fn query(mut self, value: String) -> Self {
98 self.query = Some(value);
99 self
100 }
101 pub fn tags_query(mut self, value: String) -> Self {
103 self.tags_query = Some(value);
104 self
105 }
106 pub fn metrics_query(mut self, value: String) -> Self {
108 self.metrics_query = Some(value);
109 self
110 }
111 pub fn limit(mut self, value: i64) -> Self {
113 self.limit = Some(value);
114 self
115 }
116 pub fn offset(mut self, value: i64) -> Self {
118 self.offset = Some(value);
119 self
120 }
121}
122
123#[non_exhaustive]
125#[derive(Clone, Default, Debug)]
126pub struct SearchSLOOptionalParams {
127 pub query: Option<String>,
131 pub page_size: Option<i64>,
133 pub page_number: Option<i64>,
135 pub include_facets: Option<bool>,
137}
138
139impl SearchSLOOptionalParams {
140 pub fn query(mut self, value: String) -> Self {
144 self.query = Some(value);
145 self
146 }
147 pub fn page_size(mut self, value: i64) -> Self {
149 self.page_size = Some(value);
150 self
151 }
152 pub fn page_number(mut self, value: i64) -> Self {
154 self.page_number = Some(value);
155 self
156 }
157 pub fn include_facets(mut self, value: bool) -> Self {
159 self.include_facets = Some(value);
160 self
161 }
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
166#[serde(untagged)]
167pub enum CheckCanDeleteSLOError {
168 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
169 CheckCanDeleteSLOResponse(crate::datadogV1::model::CheckCanDeleteSLOResponse),
170 UnknownValue(serde_json::Value),
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize)]
175#[serde(untagged)]
176pub enum CreateSLOError {
177 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
178 UnknownValue(serde_json::Value),
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(untagged)]
184pub enum DeleteSLOError {
185 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
186 SLODeleteResponse(crate::datadogV1::model::SLODeleteResponse),
187 UnknownValue(serde_json::Value),
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum DeleteSLOTimeframeInBulkError {
194 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
195 UnknownValue(serde_json::Value),
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum GetSLOError {
202 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
203 UnknownValue(serde_json::Value),
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum GetSLOCorrectionsError {
210 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
211 UnknownValue(serde_json::Value),
212}
213
214#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum GetSLOHistoryError {
218 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
219 UnknownValue(serde_json::Value),
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(untagged)]
225pub enum ListSLOsError {
226 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
227 UnknownValue(serde_json::Value),
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum SearchSLOError {
234 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
235 UnknownValue(serde_json::Value),
236}
237
238#[derive(Debug, Clone, Serialize, Deserialize)]
240#[serde(untagged)]
241pub enum UpdateSLOError {
242 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
243 UnknownValue(serde_json::Value),
244}
245
246#[derive(Debug, Clone)]
253pub struct ServiceLevelObjectivesAPI {
254 config: datadog::Configuration,
255 client: reqwest_middleware::ClientWithMiddleware,
256}
257
258impl Default for ServiceLevelObjectivesAPI {
259 fn default() -> Self {
260 Self::with_config(datadog::Configuration::default())
261 }
262}
263
264impl ServiceLevelObjectivesAPI {
265 pub fn new() -> Self {
266 Self::default()
267 }
268 pub fn with_config(config: datadog::Configuration) -> Self {
269 let mut reqwest_client_builder = reqwest::Client::builder();
270
271 if let Some(proxy_url) = &config.proxy_url {
272 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
273 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
274 }
275
276 let mut middleware_client_builder =
277 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
278
279 if config.enable_retry {
280 struct RetryableStatus;
281 impl reqwest_retry::RetryableStrategy for RetryableStatus {
282 fn handle(
283 &self,
284 res: &Result<reqwest::Response, reqwest_middleware::Error>,
285 ) -> Option<reqwest_retry::Retryable> {
286 match res {
287 Ok(success) => reqwest_retry::default_on_request_success(success),
288 Err(_) => None,
289 }
290 }
291 }
292 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
293 .build_with_max_retries(config.max_retries);
294
295 let retry_middleware =
296 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
297 backoff_policy,
298 RetryableStatus,
299 );
300
301 middleware_client_builder = middleware_client_builder.with(retry_middleware);
302 }
303
304 let client = middleware_client_builder.build();
305
306 Self { config, client }
307 }
308
309 pub fn with_client_and_config(
310 config: datadog::Configuration,
311 client: reqwest_middleware::ClientWithMiddleware,
312 ) -> Self {
313 Self { config, client }
314 }
315
316 pub async fn check_can_delete_slo(
319 &self,
320 ids: String,
321 ) -> Result<
322 crate::datadogV1::model::CheckCanDeleteSLOResponse,
323 datadog::Error<CheckCanDeleteSLOError>,
324 > {
325 match self.check_can_delete_slo_with_http_info(ids).await {
326 Ok(response_content) => {
327 if let Some(e) = response_content.entity {
328 Ok(e)
329 } else {
330 Err(datadog::Error::Serde(serde::de::Error::custom(
331 "response content was None",
332 )))
333 }
334 }
335 Err(err) => Err(err),
336 }
337 }
338
339 pub async fn check_can_delete_slo_with_http_info(
342 &self,
343 ids: String,
344 ) -> Result<
345 datadog::ResponseContent<crate::datadogV1::model::CheckCanDeleteSLOResponse>,
346 datadog::Error<CheckCanDeleteSLOError>,
347 > {
348 let local_configuration = &self.config;
349 let operation_id = "v1.check_can_delete_slo";
350
351 let local_client = &self.client;
352
353 let local_uri_str = format!(
354 "{}/api/v1/slo/can_delete",
355 local_configuration.get_operation_host(operation_id)
356 );
357 let mut local_req_builder =
358 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
359
360 local_req_builder = local_req_builder.query(&[("ids", &ids.to_string())]);
361
362 let mut headers = HeaderMap::new();
364 headers.insert("Accept", HeaderValue::from_static("application/json"));
365
366 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
368 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
369 Err(e) => {
370 log::warn!("Failed to parse user agent header: {e}, falling back to default");
371 headers.insert(
372 reqwest::header::USER_AGENT,
373 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
374 )
375 }
376 };
377
378 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
380 headers.insert(
381 "DD-API-KEY",
382 HeaderValue::from_str(local_key.key.as_str())
383 .expect("failed to parse DD-API-KEY header"),
384 );
385 };
386 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
387 headers.insert(
388 "DD-APPLICATION-KEY",
389 HeaderValue::from_str(local_key.key.as_str())
390 .expect("failed to parse DD-APPLICATION-KEY header"),
391 );
392 };
393
394 local_req_builder = local_req_builder.headers(headers);
395 let local_req = local_req_builder.build()?;
396 log::debug!("request content: {:?}", local_req.body());
397 let local_resp = local_client.execute(local_req).await?;
398
399 let local_status = local_resp.status();
400 let local_content = local_resp.text().await?;
401 log::debug!("response content: {}", local_content);
402
403 if !local_status.is_client_error() && !local_status.is_server_error() {
404 match serde_json::from_str::<crate::datadogV1::model::CheckCanDeleteSLOResponse>(
405 &local_content,
406 ) {
407 Ok(e) => {
408 return Ok(datadog::ResponseContent {
409 status: local_status,
410 content: local_content,
411 entity: Some(e),
412 })
413 }
414 Err(e) => return Err(datadog::Error::Serde(e)),
415 };
416 } else {
417 let local_entity: Option<CheckCanDeleteSLOError> =
418 serde_json::from_str(&local_content).ok();
419 let local_error = datadog::ResponseContent {
420 status: local_status,
421 content: local_content,
422 entity: local_entity,
423 };
424 Err(datadog::Error::ResponseError(local_error))
425 }
426 }
427
428 pub async fn create_slo(
430 &self,
431 body: crate::datadogV1::model::ServiceLevelObjectiveRequest,
432 ) -> Result<crate::datadogV1::model::SLOListResponse, datadog::Error<CreateSLOError>> {
433 match self.create_slo_with_http_info(body).await {
434 Ok(response_content) => {
435 if let Some(e) = response_content.entity {
436 Ok(e)
437 } else {
438 Err(datadog::Error::Serde(serde::de::Error::custom(
439 "response content was None",
440 )))
441 }
442 }
443 Err(err) => Err(err),
444 }
445 }
446
447 pub async fn create_slo_with_http_info(
449 &self,
450 body: crate::datadogV1::model::ServiceLevelObjectiveRequest,
451 ) -> Result<
452 datadog::ResponseContent<crate::datadogV1::model::SLOListResponse>,
453 datadog::Error<CreateSLOError>,
454 > {
455 let local_configuration = &self.config;
456 let operation_id = "v1.create_slo";
457
458 let local_client = &self.client;
459
460 let local_uri_str = format!(
461 "{}/api/v1/slo",
462 local_configuration.get_operation_host(operation_id)
463 );
464 let mut local_req_builder =
465 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
466
467 let mut headers = HeaderMap::new();
469 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
470 headers.insert("Accept", HeaderValue::from_static("application/json"));
471
472 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
474 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
475 Err(e) => {
476 log::warn!("Failed to parse user agent header: {e}, falling back to default");
477 headers.insert(
478 reqwest::header::USER_AGENT,
479 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
480 )
481 }
482 };
483
484 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
486 headers.insert(
487 "DD-API-KEY",
488 HeaderValue::from_str(local_key.key.as_str())
489 .expect("failed to parse DD-API-KEY header"),
490 );
491 };
492 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
493 headers.insert(
494 "DD-APPLICATION-KEY",
495 HeaderValue::from_str(local_key.key.as_str())
496 .expect("failed to parse DD-APPLICATION-KEY header"),
497 );
498 };
499
500 let output = Vec::new();
502 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
503 if body.serialize(&mut ser).is_ok() {
504 if let Some(content_encoding) = headers.get("Content-Encoding") {
505 match content_encoding.to_str().unwrap_or_default() {
506 "gzip" => {
507 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
508 let _ = enc.write_all(ser.into_inner().as_slice());
509 match enc.finish() {
510 Ok(buf) => {
511 local_req_builder = local_req_builder.body(buf);
512 }
513 Err(e) => return Err(datadog::Error::Io(e)),
514 }
515 }
516 "deflate" => {
517 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
518 let _ = enc.write_all(ser.into_inner().as_slice());
519 match enc.finish() {
520 Ok(buf) => {
521 local_req_builder = local_req_builder.body(buf);
522 }
523 Err(e) => return Err(datadog::Error::Io(e)),
524 }
525 }
526 "zstd1" => {
527 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
528 let _ = enc.write_all(ser.into_inner().as_slice());
529 match enc.finish() {
530 Ok(buf) => {
531 local_req_builder = local_req_builder.body(buf);
532 }
533 Err(e) => return Err(datadog::Error::Io(e)),
534 }
535 }
536 _ => {
537 local_req_builder = local_req_builder.body(ser.into_inner());
538 }
539 }
540 } else {
541 local_req_builder = local_req_builder.body(ser.into_inner());
542 }
543 }
544
545 local_req_builder = local_req_builder.headers(headers);
546 let local_req = local_req_builder.build()?;
547 log::debug!("request content: {:?}", local_req.body());
548 let local_resp = local_client.execute(local_req).await?;
549
550 let local_status = local_resp.status();
551 let local_content = local_resp.text().await?;
552 log::debug!("response content: {}", local_content);
553
554 if !local_status.is_client_error() && !local_status.is_server_error() {
555 match serde_json::from_str::<crate::datadogV1::model::SLOListResponse>(&local_content) {
556 Ok(e) => {
557 return Ok(datadog::ResponseContent {
558 status: local_status,
559 content: local_content,
560 entity: Some(e),
561 })
562 }
563 Err(e) => return Err(datadog::Error::Serde(e)),
564 };
565 } else {
566 let local_entity: Option<CreateSLOError> = serde_json::from_str(&local_content).ok();
567 let local_error = datadog::ResponseContent {
568 status: local_status,
569 content: local_content,
570 entity: local_entity,
571 };
572 Err(datadog::Error::ResponseError(local_error))
573 }
574 }
575
576 pub async fn delete_slo(
581 &self,
582 slo_id: String,
583 params: DeleteSLOOptionalParams,
584 ) -> Result<crate::datadogV1::model::SLODeleteResponse, datadog::Error<DeleteSLOError>> {
585 match self.delete_slo_with_http_info(slo_id, params).await {
586 Ok(response_content) => {
587 if let Some(e) = response_content.entity {
588 Ok(e)
589 } else {
590 Err(datadog::Error::Serde(serde::de::Error::custom(
591 "response content was None",
592 )))
593 }
594 }
595 Err(err) => Err(err),
596 }
597 }
598
599 pub async fn delete_slo_with_http_info(
604 &self,
605 slo_id: String,
606 params: DeleteSLOOptionalParams,
607 ) -> Result<
608 datadog::ResponseContent<crate::datadogV1::model::SLODeleteResponse>,
609 datadog::Error<DeleteSLOError>,
610 > {
611 let local_configuration = &self.config;
612 let operation_id = "v1.delete_slo";
613
614 let force = params.force;
616
617 let local_client = &self.client;
618
619 let local_uri_str = format!(
620 "{}/api/v1/slo/{slo_id}",
621 local_configuration.get_operation_host(operation_id),
622 slo_id = datadog::urlencode(slo_id)
623 );
624 let mut local_req_builder =
625 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
626
627 if let Some(ref local_query_param) = force {
628 local_req_builder =
629 local_req_builder.query(&[("force", &local_query_param.to_string())]);
630 };
631
632 let mut headers = HeaderMap::new();
634 headers.insert("Accept", HeaderValue::from_static("application/json"));
635
636 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
638 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
639 Err(e) => {
640 log::warn!("Failed to parse user agent header: {e}, falling back to default");
641 headers.insert(
642 reqwest::header::USER_AGENT,
643 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
644 )
645 }
646 };
647
648 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
650 headers.insert(
651 "DD-API-KEY",
652 HeaderValue::from_str(local_key.key.as_str())
653 .expect("failed to parse DD-API-KEY header"),
654 );
655 };
656 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
657 headers.insert(
658 "DD-APPLICATION-KEY",
659 HeaderValue::from_str(local_key.key.as_str())
660 .expect("failed to parse DD-APPLICATION-KEY header"),
661 );
662 };
663
664 local_req_builder = local_req_builder.headers(headers);
665 let local_req = local_req_builder.build()?;
666 log::debug!("request content: {:?}", local_req.body());
667 let local_resp = local_client.execute(local_req).await?;
668
669 let local_status = local_resp.status();
670 let local_content = local_resp.text().await?;
671 log::debug!("response content: {}", local_content);
672
673 if !local_status.is_client_error() && !local_status.is_server_error() {
674 match serde_json::from_str::<crate::datadogV1::model::SLODeleteResponse>(&local_content)
675 {
676 Ok(e) => {
677 return Ok(datadog::ResponseContent {
678 status: local_status,
679 content: local_content,
680 entity: Some(e),
681 })
682 }
683 Err(e) => return Err(datadog::Error::Serde(e)),
684 };
685 } else {
686 let local_entity: Option<DeleteSLOError> = serde_json::from_str(&local_content).ok();
687 let local_error = datadog::ResponseContent {
688 status: local_status,
689 content: local_content,
690 entity: local_entity,
691 };
692 Err(datadog::Error::ResponseError(local_error))
693 }
694 }
695
696 pub async fn delete_slo_timeframe_in_bulk(
702 &self,
703 body: std::collections::BTreeMap<String, Vec<crate::datadogV1::model::SLOTimeframe>>,
704 ) -> Result<
705 crate::datadogV1::model::SLOBulkDeleteResponse,
706 datadog::Error<DeleteSLOTimeframeInBulkError>,
707 > {
708 match self.delete_slo_timeframe_in_bulk_with_http_info(body).await {
709 Ok(response_content) => {
710 if let Some(e) = response_content.entity {
711 Ok(e)
712 } else {
713 Err(datadog::Error::Serde(serde::de::Error::custom(
714 "response content was None",
715 )))
716 }
717 }
718 Err(err) => Err(err),
719 }
720 }
721
722 pub async fn delete_slo_timeframe_in_bulk_with_http_info(
728 &self,
729 body: std::collections::BTreeMap<String, Vec<crate::datadogV1::model::SLOTimeframe>>,
730 ) -> Result<
731 datadog::ResponseContent<crate::datadogV1::model::SLOBulkDeleteResponse>,
732 datadog::Error<DeleteSLOTimeframeInBulkError>,
733 > {
734 let local_configuration = &self.config;
735 let operation_id = "v1.delete_slo_timeframe_in_bulk";
736
737 let local_client = &self.client;
738
739 let local_uri_str = format!(
740 "{}/api/v1/slo/bulk_delete",
741 local_configuration.get_operation_host(operation_id)
742 );
743 let mut local_req_builder =
744 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
745
746 let mut headers = HeaderMap::new();
748 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
749 headers.insert("Accept", HeaderValue::from_static("application/json"));
750
751 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
753 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
754 Err(e) => {
755 log::warn!("Failed to parse user agent header: {e}, falling back to default");
756 headers.insert(
757 reqwest::header::USER_AGENT,
758 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
759 )
760 }
761 };
762
763 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
765 headers.insert(
766 "DD-API-KEY",
767 HeaderValue::from_str(local_key.key.as_str())
768 .expect("failed to parse DD-API-KEY header"),
769 );
770 };
771 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
772 headers.insert(
773 "DD-APPLICATION-KEY",
774 HeaderValue::from_str(local_key.key.as_str())
775 .expect("failed to parse DD-APPLICATION-KEY header"),
776 );
777 };
778
779 let output = Vec::new();
781 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
782 if body.serialize(&mut ser).is_ok() {
783 if let Some(content_encoding) = headers.get("Content-Encoding") {
784 match content_encoding.to_str().unwrap_or_default() {
785 "gzip" => {
786 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
787 let _ = enc.write_all(ser.into_inner().as_slice());
788 match enc.finish() {
789 Ok(buf) => {
790 local_req_builder = local_req_builder.body(buf);
791 }
792 Err(e) => return Err(datadog::Error::Io(e)),
793 }
794 }
795 "deflate" => {
796 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
797 let _ = enc.write_all(ser.into_inner().as_slice());
798 match enc.finish() {
799 Ok(buf) => {
800 local_req_builder = local_req_builder.body(buf);
801 }
802 Err(e) => return Err(datadog::Error::Io(e)),
803 }
804 }
805 "zstd1" => {
806 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
807 let _ = enc.write_all(ser.into_inner().as_slice());
808 match enc.finish() {
809 Ok(buf) => {
810 local_req_builder = local_req_builder.body(buf);
811 }
812 Err(e) => return Err(datadog::Error::Io(e)),
813 }
814 }
815 _ => {
816 local_req_builder = local_req_builder.body(ser.into_inner());
817 }
818 }
819 } else {
820 local_req_builder = local_req_builder.body(ser.into_inner());
821 }
822 }
823
824 local_req_builder = local_req_builder.headers(headers);
825 let local_req = local_req_builder.build()?;
826 log::debug!("request content: {:?}", local_req.body());
827 let local_resp = local_client.execute(local_req).await?;
828
829 let local_status = local_resp.status();
830 let local_content = local_resp.text().await?;
831 log::debug!("response content: {}", local_content);
832
833 if !local_status.is_client_error() && !local_status.is_server_error() {
834 match serde_json::from_str::<crate::datadogV1::model::SLOBulkDeleteResponse>(
835 &local_content,
836 ) {
837 Ok(e) => {
838 return Ok(datadog::ResponseContent {
839 status: local_status,
840 content: local_content,
841 entity: Some(e),
842 })
843 }
844 Err(e) => return Err(datadog::Error::Serde(e)),
845 };
846 } else {
847 let local_entity: Option<DeleteSLOTimeframeInBulkError> =
848 serde_json::from_str(&local_content).ok();
849 let local_error = datadog::ResponseContent {
850 status: local_status,
851 content: local_content,
852 entity: local_entity,
853 };
854 Err(datadog::Error::ResponseError(local_error))
855 }
856 }
857
858 pub async fn get_slo(
860 &self,
861 slo_id: String,
862 params: GetSLOOptionalParams,
863 ) -> Result<crate::datadogV1::model::SLOResponse, datadog::Error<GetSLOError>> {
864 match self.get_slo_with_http_info(slo_id, params).await {
865 Ok(response_content) => {
866 if let Some(e) = response_content.entity {
867 Ok(e)
868 } else {
869 Err(datadog::Error::Serde(serde::de::Error::custom(
870 "response content was None",
871 )))
872 }
873 }
874 Err(err) => Err(err),
875 }
876 }
877
878 pub async fn get_slo_with_http_info(
880 &self,
881 slo_id: String,
882 params: GetSLOOptionalParams,
883 ) -> Result<
884 datadog::ResponseContent<crate::datadogV1::model::SLOResponse>,
885 datadog::Error<GetSLOError>,
886 > {
887 let local_configuration = &self.config;
888 let operation_id = "v1.get_slo";
889
890 let with_configured_alert_ids = params.with_configured_alert_ids;
892
893 let local_client = &self.client;
894
895 let local_uri_str = format!(
896 "{}/api/v1/slo/{slo_id}",
897 local_configuration.get_operation_host(operation_id),
898 slo_id = datadog::urlencode(slo_id)
899 );
900 let mut local_req_builder =
901 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
902
903 if let Some(ref local_query_param) = with_configured_alert_ids {
904 local_req_builder = local_req_builder
905 .query(&[("with_configured_alert_ids", &local_query_param.to_string())]);
906 };
907
908 let mut headers = HeaderMap::new();
910 headers.insert("Accept", HeaderValue::from_static("application/json"));
911
912 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
914 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
915 Err(e) => {
916 log::warn!("Failed to parse user agent header: {e}, falling back to default");
917 headers.insert(
918 reqwest::header::USER_AGENT,
919 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
920 )
921 }
922 };
923
924 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
926 headers.insert(
927 "DD-API-KEY",
928 HeaderValue::from_str(local_key.key.as_str())
929 .expect("failed to parse DD-API-KEY header"),
930 );
931 };
932 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
933 headers.insert(
934 "DD-APPLICATION-KEY",
935 HeaderValue::from_str(local_key.key.as_str())
936 .expect("failed to parse DD-APPLICATION-KEY header"),
937 );
938 };
939
940 local_req_builder = local_req_builder.headers(headers);
941 let local_req = local_req_builder.build()?;
942 log::debug!("request content: {:?}", local_req.body());
943 let local_resp = local_client.execute(local_req).await?;
944
945 let local_status = local_resp.status();
946 let local_content = local_resp.text().await?;
947 log::debug!("response content: {}", local_content);
948
949 if !local_status.is_client_error() && !local_status.is_server_error() {
950 match serde_json::from_str::<crate::datadogV1::model::SLOResponse>(&local_content) {
951 Ok(e) => {
952 return Ok(datadog::ResponseContent {
953 status: local_status,
954 content: local_content,
955 entity: Some(e),
956 })
957 }
958 Err(e) => return Err(datadog::Error::Serde(e)),
959 };
960 } else {
961 let local_entity: Option<GetSLOError> = serde_json::from_str(&local_content).ok();
962 let local_error = datadog::ResponseContent {
963 status: local_status,
964 content: local_content,
965 entity: local_entity,
966 };
967 Err(datadog::Error::ResponseError(local_error))
968 }
969 }
970
971 pub async fn get_slo_corrections(
973 &self,
974 slo_id: String,
975 ) -> Result<
976 crate::datadogV1::model::SLOCorrectionListResponse,
977 datadog::Error<GetSLOCorrectionsError>,
978 > {
979 match self.get_slo_corrections_with_http_info(slo_id).await {
980 Ok(response_content) => {
981 if let Some(e) = response_content.entity {
982 Ok(e)
983 } else {
984 Err(datadog::Error::Serde(serde::de::Error::custom(
985 "response content was None",
986 )))
987 }
988 }
989 Err(err) => Err(err),
990 }
991 }
992
993 pub async fn get_slo_corrections_with_http_info(
995 &self,
996 slo_id: String,
997 ) -> Result<
998 datadog::ResponseContent<crate::datadogV1::model::SLOCorrectionListResponse>,
999 datadog::Error<GetSLOCorrectionsError>,
1000 > {
1001 let local_configuration = &self.config;
1002 let operation_id = "v1.get_slo_corrections";
1003
1004 let local_client = &self.client;
1005
1006 let local_uri_str = format!(
1007 "{}/api/v1/slo/{slo_id}/corrections",
1008 local_configuration.get_operation_host(operation_id),
1009 slo_id = datadog::urlencode(slo_id)
1010 );
1011 let mut local_req_builder =
1012 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1013
1014 let mut headers = HeaderMap::new();
1016 headers.insert("Accept", HeaderValue::from_static("application/json"));
1017
1018 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1020 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1021 Err(e) => {
1022 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1023 headers.insert(
1024 reqwest::header::USER_AGENT,
1025 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1026 )
1027 }
1028 };
1029
1030 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1032 headers.insert(
1033 "DD-API-KEY",
1034 HeaderValue::from_str(local_key.key.as_str())
1035 .expect("failed to parse DD-API-KEY header"),
1036 );
1037 };
1038 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1039 headers.insert(
1040 "DD-APPLICATION-KEY",
1041 HeaderValue::from_str(local_key.key.as_str())
1042 .expect("failed to parse DD-APPLICATION-KEY header"),
1043 );
1044 };
1045
1046 local_req_builder = local_req_builder.headers(headers);
1047 let local_req = local_req_builder.build()?;
1048 log::debug!("request content: {:?}", local_req.body());
1049 let local_resp = local_client.execute(local_req).await?;
1050
1051 let local_status = local_resp.status();
1052 let local_content = local_resp.text().await?;
1053 log::debug!("response content: {}", local_content);
1054
1055 if !local_status.is_client_error() && !local_status.is_server_error() {
1056 match serde_json::from_str::<crate::datadogV1::model::SLOCorrectionListResponse>(
1057 &local_content,
1058 ) {
1059 Ok(e) => {
1060 return Ok(datadog::ResponseContent {
1061 status: local_status,
1062 content: local_content,
1063 entity: Some(e),
1064 })
1065 }
1066 Err(e) => return Err(datadog::Error::Serde(e)),
1067 };
1068 } else {
1069 let local_entity: Option<GetSLOCorrectionsError> =
1070 serde_json::from_str(&local_content).ok();
1071 let local_error = datadog::ResponseContent {
1072 status: local_status,
1073 content: local_content,
1074 entity: local_entity,
1075 };
1076 Err(datadog::Error::ResponseError(local_error))
1077 }
1078 }
1079
1080 pub async fn get_slo_history(
1089 &self,
1090 slo_id: String,
1091 from_ts: i64,
1092 to_ts: i64,
1093 params: GetSLOHistoryOptionalParams,
1094 ) -> Result<crate::datadogV1::model::SLOHistoryResponse, datadog::Error<GetSLOHistoryError>>
1095 {
1096 match self
1097 .get_slo_history_with_http_info(slo_id, from_ts, to_ts, params)
1098 .await
1099 {
1100 Ok(response_content) => {
1101 if let Some(e) = response_content.entity {
1102 Ok(e)
1103 } else {
1104 Err(datadog::Error::Serde(serde::de::Error::custom(
1105 "response content was None",
1106 )))
1107 }
1108 }
1109 Err(err) => Err(err),
1110 }
1111 }
1112
1113 pub async fn get_slo_history_with_http_info(
1122 &self,
1123 slo_id: String,
1124 from_ts: i64,
1125 to_ts: i64,
1126 params: GetSLOHistoryOptionalParams,
1127 ) -> Result<
1128 datadog::ResponseContent<crate::datadogV1::model::SLOHistoryResponse>,
1129 datadog::Error<GetSLOHistoryError>,
1130 > {
1131 let local_configuration = &self.config;
1132 let operation_id = "v1.get_slo_history";
1133
1134 let target = params.target;
1136 let apply_correction = params.apply_correction;
1137
1138 let local_client = &self.client;
1139
1140 let local_uri_str = format!(
1141 "{}/api/v1/slo/{slo_id}/history",
1142 local_configuration.get_operation_host(operation_id),
1143 slo_id = datadog::urlencode(slo_id)
1144 );
1145 let mut local_req_builder =
1146 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1147
1148 local_req_builder = local_req_builder.query(&[("from_ts", &from_ts.to_string())]);
1149 local_req_builder = local_req_builder.query(&[("to_ts", &to_ts.to_string())]);
1150 if let Some(ref local_query_param) = target {
1151 local_req_builder =
1152 local_req_builder.query(&[("target", &local_query_param.to_string())]);
1153 };
1154 if let Some(ref local_query_param) = apply_correction {
1155 local_req_builder =
1156 local_req_builder.query(&[("apply_correction", &local_query_param.to_string())]);
1157 };
1158
1159 let mut headers = HeaderMap::new();
1161 headers.insert("Accept", HeaderValue::from_static("application/json"));
1162
1163 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1165 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1166 Err(e) => {
1167 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1168 headers.insert(
1169 reqwest::header::USER_AGENT,
1170 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1171 )
1172 }
1173 };
1174
1175 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1177 headers.insert(
1178 "DD-API-KEY",
1179 HeaderValue::from_str(local_key.key.as_str())
1180 .expect("failed to parse DD-API-KEY header"),
1181 );
1182 };
1183 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1184 headers.insert(
1185 "DD-APPLICATION-KEY",
1186 HeaderValue::from_str(local_key.key.as_str())
1187 .expect("failed to parse DD-APPLICATION-KEY header"),
1188 );
1189 };
1190
1191 local_req_builder = local_req_builder.headers(headers);
1192 let local_req = local_req_builder.build()?;
1193 log::debug!("request content: {:?}", local_req.body());
1194 let local_resp = local_client.execute(local_req).await?;
1195
1196 let local_status = local_resp.status();
1197 let local_content = local_resp.text().await?;
1198 log::debug!("response content: {}", local_content);
1199
1200 if !local_status.is_client_error() && !local_status.is_server_error() {
1201 match serde_json::from_str::<crate::datadogV1::model::SLOHistoryResponse>(
1202 &local_content,
1203 ) {
1204 Ok(e) => {
1205 return Ok(datadog::ResponseContent {
1206 status: local_status,
1207 content: local_content,
1208 entity: Some(e),
1209 })
1210 }
1211 Err(e) => return Err(datadog::Error::Serde(e)),
1212 };
1213 } else {
1214 let local_entity: Option<GetSLOHistoryError> =
1215 serde_json::from_str(&local_content).ok();
1216 let local_error = datadog::ResponseContent {
1217 status: local_status,
1218 content: local_content,
1219 entity: local_entity,
1220 };
1221 Err(datadog::Error::ResponseError(local_error))
1222 }
1223 }
1224
1225 pub async fn list_slos(
1227 &self,
1228 params: ListSLOsOptionalParams,
1229 ) -> Result<crate::datadogV1::model::SLOListResponse, datadog::Error<ListSLOsError>> {
1230 match self.list_slos_with_http_info(params).await {
1231 Ok(response_content) => {
1232 if let Some(e) = response_content.entity {
1233 Ok(e)
1234 } else {
1235 Err(datadog::Error::Serde(serde::de::Error::custom(
1236 "response content was None",
1237 )))
1238 }
1239 }
1240 Err(err) => Err(err),
1241 }
1242 }
1243
1244 pub fn list_slos_with_pagination(
1245 &self,
1246 mut params: ListSLOsOptionalParams,
1247 ) -> impl Stream<
1248 Item = Result<
1249 crate::datadogV1::model::ServiceLevelObjective,
1250 datadog::Error<ListSLOsError>,
1251 >,
1252 > + '_ {
1253 try_stream! {
1254 let mut page_size: i64 = 1000;
1255 if params.limit.is_none() {
1256 params.limit = Some(page_size);
1257 } else {
1258 page_size = params.limit.unwrap().clone();
1259 }
1260 loop {
1261 let resp = self.list_slos(params.clone()).await?;
1262 let Some(data) = resp.data else { break };
1263
1264 let r = data;
1265 let count = r.len();
1266 for team in r {
1267 yield team;
1268 }
1269
1270 if count < page_size as usize {
1271 break;
1272 }
1273 if params.offset.is_none() {
1274 params.offset = Some(page_size.clone());
1275 } else {
1276 params.offset = Some(params.offset.unwrap() + page_size.clone());
1277 }
1278 }
1279 }
1280 }
1281
1282 pub async fn list_slos_with_http_info(
1284 &self,
1285 params: ListSLOsOptionalParams,
1286 ) -> Result<
1287 datadog::ResponseContent<crate::datadogV1::model::SLOListResponse>,
1288 datadog::Error<ListSLOsError>,
1289 > {
1290 let local_configuration = &self.config;
1291 let operation_id = "v1.list_slos";
1292
1293 let ids = params.ids;
1295 let query = params.query;
1296 let tags_query = params.tags_query;
1297 let metrics_query = params.metrics_query;
1298 let limit = params.limit;
1299 let offset = params.offset;
1300
1301 let local_client = &self.client;
1302
1303 let local_uri_str = format!(
1304 "{}/api/v1/slo",
1305 local_configuration.get_operation_host(operation_id)
1306 );
1307 let mut local_req_builder =
1308 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1309
1310 if let Some(ref local_query_param) = ids {
1311 local_req_builder = local_req_builder.query(&[("ids", &local_query_param.to_string())]);
1312 };
1313 if let Some(ref local_query_param) = query {
1314 local_req_builder =
1315 local_req_builder.query(&[("query", &local_query_param.to_string())]);
1316 };
1317 if let Some(ref local_query_param) = tags_query {
1318 local_req_builder =
1319 local_req_builder.query(&[("tags_query", &local_query_param.to_string())]);
1320 };
1321 if let Some(ref local_query_param) = metrics_query {
1322 local_req_builder =
1323 local_req_builder.query(&[("metrics_query", &local_query_param.to_string())]);
1324 };
1325 if let Some(ref local_query_param) = limit {
1326 local_req_builder =
1327 local_req_builder.query(&[("limit", &local_query_param.to_string())]);
1328 };
1329 if let Some(ref local_query_param) = offset {
1330 local_req_builder =
1331 local_req_builder.query(&[("offset", &local_query_param.to_string())]);
1332 };
1333
1334 let mut headers = HeaderMap::new();
1336 headers.insert("Accept", HeaderValue::from_static("application/json"));
1337
1338 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1340 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1341 Err(e) => {
1342 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1343 headers.insert(
1344 reqwest::header::USER_AGENT,
1345 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1346 )
1347 }
1348 };
1349
1350 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1352 headers.insert(
1353 "DD-API-KEY",
1354 HeaderValue::from_str(local_key.key.as_str())
1355 .expect("failed to parse DD-API-KEY header"),
1356 );
1357 };
1358 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1359 headers.insert(
1360 "DD-APPLICATION-KEY",
1361 HeaderValue::from_str(local_key.key.as_str())
1362 .expect("failed to parse DD-APPLICATION-KEY header"),
1363 );
1364 };
1365
1366 local_req_builder = local_req_builder.headers(headers);
1367 let local_req = local_req_builder.build()?;
1368 log::debug!("request content: {:?}", local_req.body());
1369 let local_resp = local_client.execute(local_req).await?;
1370
1371 let local_status = local_resp.status();
1372 let local_content = local_resp.text().await?;
1373 log::debug!("response content: {}", local_content);
1374
1375 if !local_status.is_client_error() && !local_status.is_server_error() {
1376 match serde_json::from_str::<crate::datadogV1::model::SLOListResponse>(&local_content) {
1377 Ok(e) => {
1378 return Ok(datadog::ResponseContent {
1379 status: local_status,
1380 content: local_content,
1381 entity: Some(e),
1382 })
1383 }
1384 Err(e) => return Err(datadog::Error::Serde(e)),
1385 };
1386 } else {
1387 let local_entity: Option<ListSLOsError> = serde_json::from_str(&local_content).ok();
1388 let local_error = datadog::ResponseContent {
1389 status: local_status,
1390 content: local_content,
1391 entity: local_entity,
1392 };
1393 Err(datadog::Error::ResponseError(local_error))
1394 }
1395 }
1396
1397 pub async fn search_slo(
1399 &self,
1400 params: SearchSLOOptionalParams,
1401 ) -> Result<crate::datadogV1::model::SearchSLOResponse, datadog::Error<SearchSLOError>> {
1402 match self.search_slo_with_http_info(params).await {
1403 Ok(response_content) => {
1404 if let Some(e) = response_content.entity {
1405 Ok(e)
1406 } else {
1407 Err(datadog::Error::Serde(serde::de::Error::custom(
1408 "response content was None",
1409 )))
1410 }
1411 }
1412 Err(err) => Err(err),
1413 }
1414 }
1415
1416 pub async fn search_slo_with_http_info(
1418 &self,
1419 params: SearchSLOOptionalParams,
1420 ) -> Result<
1421 datadog::ResponseContent<crate::datadogV1::model::SearchSLOResponse>,
1422 datadog::Error<SearchSLOError>,
1423 > {
1424 let local_configuration = &self.config;
1425 let operation_id = "v1.search_slo";
1426
1427 let query = params.query;
1429 let page_size = params.page_size;
1430 let page_number = params.page_number;
1431 let include_facets = params.include_facets;
1432
1433 let local_client = &self.client;
1434
1435 let local_uri_str = format!(
1436 "{}/api/v1/slo/search",
1437 local_configuration.get_operation_host(operation_id)
1438 );
1439 let mut local_req_builder =
1440 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1441
1442 if let Some(ref local_query_param) = query {
1443 local_req_builder =
1444 local_req_builder.query(&[("query", &local_query_param.to_string())]);
1445 };
1446 if let Some(ref local_query_param) = page_size {
1447 local_req_builder =
1448 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1449 };
1450 if let Some(ref local_query_param) = page_number {
1451 local_req_builder =
1452 local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1453 };
1454 if let Some(ref local_query_param) = include_facets {
1455 local_req_builder =
1456 local_req_builder.query(&[("include_facets", &local_query_param.to_string())]);
1457 };
1458
1459 let mut headers = HeaderMap::new();
1461 headers.insert("Accept", HeaderValue::from_static("application/json"));
1462
1463 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1465 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1466 Err(e) => {
1467 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1468 headers.insert(
1469 reqwest::header::USER_AGENT,
1470 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1471 )
1472 }
1473 };
1474
1475 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1477 headers.insert(
1478 "DD-API-KEY",
1479 HeaderValue::from_str(local_key.key.as_str())
1480 .expect("failed to parse DD-API-KEY header"),
1481 );
1482 };
1483 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1484 headers.insert(
1485 "DD-APPLICATION-KEY",
1486 HeaderValue::from_str(local_key.key.as_str())
1487 .expect("failed to parse DD-APPLICATION-KEY header"),
1488 );
1489 };
1490
1491 local_req_builder = local_req_builder.headers(headers);
1492 let local_req = local_req_builder.build()?;
1493 log::debug!("request content: {:?}", local_req.body());
1494 let local_resp = local_client.execute(local_req).await?;
1495
1496 let local_status = local_resp.status();
1497 let local_content = local_resp.text().await?;
1498 log::debug!("response content: {}", local_content);
1499
1500 if !local_status.is_client_error() && !local_status.is_server_error() {
1501 match serde_json::from_str::<crate::datadogV1::model::SearchSLOResponse>(&local_content)
1502 {
1503 Ok(e) => {
1504 return Ok(datadog::ResponseContent {
1505 status: local_status,
1506 content: local_content,
1507 entity: Some(e),
1508 })
1509 }
1510 Err(e) => return Err(datadog::Error::Serde(e)),
1511 };
1512 } else {
1513 let local_entity: Option<SearchSLOError> = serde_json::from_str(&local_content).ok();
1514 let local_error = datadog::ResponseContent {
1515 status: local_status,
1516 content: local_content,
1517 entity: local_entity,
1518 };
1519 Err(datadog::Error::ResponseError(local_error))
1520 }
1521 }
1522
1523 pub async fn update_slo(
1525 &self,
1526 slo_id: String,
1527 body: crate::datadogV1::model::ServiceLevelObjective,
1528 ) -> Result<crate::datadogV1::model::SLOListResponse, datadog::Error<UpdateSLOError>> {
1529 match self.update_slo_with_http_info(slo_id, body).await {
1530 Ok(response_content) => {
1531 if let Some(e) = response_content.entity {
1532 Ok(e)
1533 } else {
1534 Err(datadog::Error::Serde(serde::de::Error::custom(
1535 "response content was None",
1536 )))
1537 }
1538 }
1539 Err(err) => Err(err),
1540 }
1541 }
1542
1543 pub async fn update_slo_with_http_info(
1545 &self,
1546 slo_id: String,
1547 body: crate::datadogV1::model::ServiceLevelObjective,
1548 ) -> Result<
1549 datadog::ResponseContent<crate::datadogV1::model::SLOListResponse>,
1550 datadog::Error<UpdateSLOError>,
1551 > {
1552 let local_configuration = &self.config;
1553 let operation_id = "v1.update_slo";
1554
1555 let local_client = &self.client;
1556
1557 let local_uri_str = format!(
1558 "{}/api/v1/slo/{slo_id}",
1559 local_configuration.get_operation_host(operation_id),
1560 slo_id = datadog::urlencode(slo_id)
1561 );
1562 let mut local_req_builder =
1563 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1564
1565 let mut headers = HeaderMap::new();
1567 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1568 headers.insert("Accept", HeaderValue::from_static("application/json"));
1569
1570 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1572 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1573 Err(e) => {
1574 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1575 headers.insert(
1576 reqwest::header::USER_AGENT,
1577 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1578 )
1579 }
1580 };
1581
1582 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1584 headers.insert(
1585 "DD-API-KEY",
1586 HeaderValue::from_str(local_key.key.as_str())
1587 .expect("failed to parse DD-API-KEY header"),
1588 );
1589 };
1590 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1591 headers.insert(
1592 "DD-APPLICATION-KEY",
1593 HeaderValue::from_str(local_key.key.as_str())
1594 .expect("failed to parse DD-APPLICATION-KEY header"),
1595 );
1596 };
1597
1598 let output = Vec::new();
1600 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1601 if body.serialize(&mut ser).is_ok() {
1602 if let Some(content_encoding) = headers.get("Content-Encoding") {
1603 match content_encoding.to_str().unwrap_or_default() {
1604 "gzip" => {
1605 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1606 let _ = enc.write_all(ser.into_inner().as_slice());
1607 match enc.finish() {
1608 Ok(buf) => {
1609 local_req_builder = local_req_builder.body(buf);
1610 }
1611 Err(e) => return Err(datadog::Error::Io(e)),
1612 }
1613 }
1614 "deflate" => {
1615 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1616 let _ = enc.write_all(ser.into_inner().as_slice());
1617 match enc.finish() {
1618 Ok(buf) => {
1619 local_req_builder = local_req_builder.body(buf);
1620 }
1621 Err(e) => return Err(datadog::Error::Io(e)),
1622 }
1623 }
1624 "zstd1" => {
1625 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1626 let _ = enc.write_all(ser.into_inner().as_slice());
1627 match enc.finish() {
1628 Ok(buf) => {
1629 local_req_builder = local_req_builder.body(buf);
1630 }
1631 Err(e) => return Err(datadog::Error::Io(e)),
1632 }
1633 }
1634 _ => {
1635 local_req_builder = local_req_builder.body(ser.into_inner());
1636 }
1637 }
1638 } else {
1639 local_req_builder = local_req_builder.body(ser.into_inner());
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::datadogV1::model::SLOListResponse>(&local_content) {
1654 Ok(e) => {
1655 return Ok(datadog::ResponseContent {
1656 status: local_status,
1657 content: local_content,
1658 entity: Some(e),
1659 })
1660 }
1661 Err(e) => return Err(datadog::Error::Serde(e)),
1662 };
1663 } else {
1664 let local_entity: Option<UpdateSLOError> = serde_json::from_str(&local_content).ok();
1665 let local_error = datadog::ResponseContent {
1666 status: local_status,
1667 content: local_content,
1668 entity: local_entity,
1669 };
1670 Err(datadog::Error::ResponseError(local_error))
1671 }
1672 }
1673}