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 ListCatalogEntityOptionalParams {
19 pub page_offset: Option<i64>,
21 pub page_limit: Option<i64>,
23 pub filter_id: Option<String>,
25 pub filter_ref: Option<String>,
27 pub filter_name: Option<String>,
29 pub filter_kind: Option<String>,
31 pub filter_owner: Option<String>,
33 pub filter_relation_type: Option<crate::datadogV2::model::RelationType>,
35 pub filter_exclude_snapshot: Option<String>,
37 pub include: Option<crate::datadogV2::model::IncludeType>,
39}
40
41impl ListCatalogEntityOptionalParams {
42 pub fn page_offset(mut self, value: i64) -> Self {
44 self.page_offset = Some(value);
45 self
46 }
47 pub fn page_limit(mut self, value: i64) -> Self {
49 self.page_limit = Some(value);
50 self
51 }
52 pub fn filter_id(mut self, value: String) -> Self {
54 self.filter_id = Some(value);
55 self
56 }
57 pub fn filter_ref(mut self, value: String) -> Self {
59 self.filter_ref = Some(value);
60 self
61 }
62 pub fn filter_name(mut self, value: String) -> Self {
64 self.filter_name = Some(value);
65 self
66 }
67 pub fn filter_kind(mut self, value: String) -> Self {
69 self.filter_kind = Some(value);
70 self
71 }
72 pub fn filter_owner(mut self, value: String) -> Self {
74 self.filter_owner = Some(value);
75 self
76 }
77 pub fn filter_relation_type(mut self, value: crate::datadogV2::model::RelationType) -> Self {
79 self.filter_relation_type = Some(value);
80 self
81 }
82 pub fn filter_exclude_snapshot(mut self, value: String) -> Self {
84 self.filter_exclude_snapshot = Some(value);
85 self
86 }
87 pub fn include(mut self, value: crate::datadogV2::model::IncludeType) -> Self {
89 self.include = Some(value);
90 self
91 }
92}
93
94#[non_exhaustive]
96#[derive(Clone, Default, Debug)]
97pub struct ListCatalogKindOptionalParams {
98 pub page_offset: Option<i64>,
100 pub page_limit: Option<i64>,
102 pub filter_id: Option<String>,
104 pub filter_name: Option<String>,
106}
107
108impl ListCatalogKindOptionalParams {
109 pub fn page_offset(mut self, value: i64) -> Self {
111 self.page_offset = Some(value);
112 self
113 }
114 pub fn page_limit(mut self, value: i64) -> Self {
116 self.page_limit = Some(value);
117 self
118 }
119 pub fn filter_id(mut self, value: String) -> Self {
121 self.filter_id = Some(value);
122 self
123 }
124 pub fn filter_name(mut self, value: String) -> Self {
126 self.filter_name = Some(value);
127 self
128 }
129}
130
131#[non_exhaustive]
133#[derive(Clone, Default, Debug)]
134pub struct ListCatalogRelationOptionalParams {
135 pub page_offset: Option<i64>,
137 pub page_limit: Option<i64>,
139 pub filter_type: Option<crate::datadogV2::model::RelationType>,
141 pub filter_from_ref: Option<String>,
143 pub filter_to_ref: Option<String>,
145 pub include: Option<crate::datadogV2::model::RelationIncludeType>,
147}
148
149impl ListCatalogRelationOptionalParams {
150 pub fn page_offset(mut self, value: i64) -> Self {
152 self.page_offset = Some(value);
153 self
154 }
155 pub fn page_limit(mut self, value: i64) -> Self {
157 self.page_limit = Some(value);
158 self
159 }
160 pub fn filter_type(mut self, value: crate::datadogV2::model::RelationType) -> Self {
162 self.filter_type = Some(value);
163 self
164 }
165 pub fn filter_from_ref(mut self, value: String) -> Self {
167 self.filter_from_ref = Some(value);
168 self
169 }
170 pub fn filter_to_ref(mut self, value: String) -> Self {
172 self.filter_to_ref = Some(value);
173 self
174 }
175 pub fn include(mut self, value: crate::datadogV2::model::RelationIncludeType) -> Self {
177 self.include = Some(value);
178 self
179 }
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum DeleteCatalogEntityError {
186 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
187 UnknownValue(serde_json::Value),
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum DeleteCatalogKindError {
194 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
195 UnknownValue(serde_json::Value),
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum ListCatalogEntityError {
202 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
203 UnknownValue(serde_json::Value),
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum ListCatalogKindError {
210 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
211 UnknownValue(serde_json::Value),
212}
213
214#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum ListCatalogRelationError {
218 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
219 UnknownValue(serde_json::Value),
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(untagged)]
225pub enum UpsertCatalogEntityError {
226 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
227 UnknownValue(serde_json::Value),
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum UpsertCatalogKindError {
234 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
235 UnknownValue(serde_json::Value),
236}
237
238#[derive(Debug, Clone)]
240pub struct SoftwareCatalogAPI {
241 config: datadog::Configuration,
242 client: reqwest_middleware::ClientWithMiddleware,
243}
244
245impl Default for SoftwareCatalogAPI {
246 fn default() -> Self {
247 Self::with_config(datadog::Configuration::default())
248 }
249}
250
251impl SoftwareCatalogAPI {
252 pub fn new() -> Self {
253 Self::default()
254 }
255 pub fn with_config(config: datadog::Configuration) -> Self {
256 let mut reqwest_client_builder = reqwest::Client::builder();
257
258 if let Some(proxy_url) = &config.proxy_url {
259 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
260 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
261 }
262
263 let mut middleware_client_builder =
264 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
265
266 if config.enable_retry {
267 struct RetryableStatus;
268 impl reqwest_retry::RetryableStrategy for RetryableStatus {
269 fn handle(
270 &self,
271 res: &Result<reqwest::Response, reqwest_middleware::Error>,
272 ) -> Option<reqwest_retry::Retryable> {
273 match res {
274 Ok(success) => reqwest_retry::default_on_request_success(success),
275 Err(_) => None,
276 }
277 }
278 }
279 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
280 .build_with_max_retries(config.max_retries);
281
282 let retry_middleware =
283 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
284 backoff_policy,
285 RetryableStatus,
286 );
287
288 middleware_client_builder = middleware_client_builder.with(retry_middleware);
289 }
290
291 let client = middleware_client_builder.build();
292
293 Self { config, client }
294 }
295
296 pub fn with_client_and_config(
297 config: datadog::Configuration,
298 client: reqwest_middleware::ClientWithMiddleware,
299 ) -> Self {
300 Self { config, client }
301 }
302
303 pub async fn delete_catalog_entity(
305 &self,
306 entity_id: String,
307 ) -> Result<(), datadog::Error<DeleteCatalogEntityError>> {
308 match self.delete_catalog_entity_with_http_info(entity_id).await {
309 Ok(_) => Ok(()),
310 Err(err) => Err(err),
311 }
312 }
313
314 pub async fn delete_catalog_entity_with_http_info(
316 &self,
317 entity_id: String,
318 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCatalogEntityError>> {
319 let local_configuration = &self.config;
320 let operation_id = "v2.delete_catalog_entity";
321
322 let local_client = &self.client;
323
324 let local_uri_str = format!(
325 "{}/api/v2/catalog/entity/{entity_id}",
326 local_configuration.get_operation_host(operation_id),
327 entity_id = datadog::urlencode(entity_id)
328 );
329 let mut local_req_builder =
330 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
331
332 let mut headers = HeaderMap::new();
334 headers.insert("Accept", HeaderValue::from_static("*/*"));
335
336 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
338 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
339 Err(e) => {
340 log::warn!("Failed to parse user agent header: {e}, falling back to default");
341 headers.insert(
342 reqwest::header::USER_AGENT,
343 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
344 )
345 }
346 };
347
348 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
350 headers.insert(
351 "DD-API-KEY",
352 HeaderValue::from_str(local_key.key.as_str())
353 .expect("failed to parse DD-API-KEY header"),
354 );
355 };
356 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
357 headers.insert(
358 "DD-APPLICATION-KEY",
359 HeaderValue::from_str(local_key.key.as_str())
360 .expect("failed to parse DD-APPLICATION-KEY header"),
361 );
362 };
363
364 local_req_builder = local_req_builder.headers(headers);
365 let local_req = local_req_builder.build()?;
366 log::debug!("request content: {:?}", local_req.body());
367 let local_resp = local_client.execute(local_req).await?;
368
369 let local_status = local_resp.status();
370 let local_content = local_resp.text().await?;
371 log::debug!("response content: {}", local_content);
372
373 if !local_status.is_client_error() && !local_status.is_server_error() {
374 Ok(datadog::ResponseContent {
375 status: local_status,
376 content: local_content,
377 entity: None,
378 })
379 } else {
380 let local_entity: Option<DeleteCatalogEntityError> =
381 serde_json::from_str(&local_content).ok();
382 let local_error = datadog::ResponseContent {
383 status: local_status,
384 content: local_content,
385 entity: local_entity,
386 };
387 Err(datadog::Error::ResponseError(local_error))
388 }
389 }
390
391 pub async fn delete_catalog_kind(
393 &self,
394 kind_id: String,
395 ) -> Result<(), datadog::Error<DeleteCatalogKindError>> {
396 match self.delete_catalog_kind_with_http_info(kind_id).await {
397 Ok(_) => Ok(()),
398 Err(err) => Err(err),
399 }
400 }
401
402 pub async fn delete_catalog_kind_with_http_info(
404 &self,
405 kind_id: String,
406 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCatalogKindError>> {
407 let local_configuration = &self.config;
408 let operation_id = "v2.delete_catalog_kind";
409
410 let local_client = &self.client;
411
412 let local_uri_str = format!(
413 "{}/api/v2/catalog/kind/{kind_id}",
414 local_configuration.get_operation_host(operation_id),
415 kind_id = datadog::urlencode(kind_id)
416 );
417 let mut local_req_builder =
418 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
419
420 let mut headers = HeaderMap::new();
422 headers.insert("Accept", HeaderValue::from_static("*/*"));
423
424 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
426 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
427 Err(e) => {
428 log::warn!("Failed to parse user agent header: {e}, falling back to default");
429 headers.insert(
430 reqwest::header::USER_AGENT,
431 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
432 )
433 }
434 };
435
436 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
438 headers.insert(
439 "DD-API-KEY",
440 HeaderValue::from_str(local_key.key.as_str())
441 .expect("failed to parse DD-API-KEY header"),
442 );
443 };
444 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
445 headers.insert(
446 "DD-APPLICATION-KEY",
447 HeaderValue::from_str(local_key.key.as_str())
448 .expect("failed to parse DD-APPLICATION-KEY header"),
449 );
450 };
451
452 local_req_builder = local_req_builder.headers(headers);
453 let local_req = local_req_builder.build()?;
454 log::debug!("request content: {:?}", local_req.body());
455 let local_resp = local_client.execute(local_req).await?;
456
457 let local_status = local_resp.status();
458 let local_content = local_resp.text().await?;
459 log::debug!("response content: {}", local_content);
460
461 if !local_status.is_client_error() && !local_status.is_server_error() {
462 Ok(datadog::ResponseContent {
463 status: local_status,
464 content: local_content,
465 entity: None,
466 })
467 } else {
468 let local_entity: Option<DeleteCatalogKindError> =
469 serde_json::from_str(&local_content).ok();
470 let local_error = datadog::ResponseContent {
471 status: local_status,
472 content: local_content,
473 entity: local_entity,
474 };
475 Err(datadog::Error::ResponseError(local_error))
476 }
477 }
478
479 pub async fn list_catalog_entity(
481 &self,
482 params: ListCatalogEntityOptionalParams,
483 ) -> Result<
484 crate::datadogV2::model::ListEntityCatalogResponse,
485 datadog::Error<ListCatalogEntityError>,
486 > {
487 match self.list_catalog_entity_with_http_info(params).await {
488 Ok(response_content) => {
489 if let Some(e) = response_content.entity {
490 Ok(e)
491 } else {
492 Err(datadog::Error::Serde(serde::de::Error::custom(
493 "response content was None",
494 )))
495 }
496 }
497 Err(err) => Err(err),
498 }
499 }
500
501 pub fn list_catalog_entity_with_pagination(
502 &self,
503 mut params: ListCatalogEntityOptionalParams,
504 ) -> impl Stream<
505 Item = Result<crate::datadogV2::model::EntityData, datadog::Error<ListCatalogEntityError>>,
506 > + '_ {
507 try_stream! {
508 let mut page_size: i64 = 100;
509 if params.page_limit.is_none() {
510 params.page_limit = Some(page_size);
511 } else {
512 page_size = params.page_limit.unwrap().clone();
513 }
514 loop {
515 let resp = self.list_catalog_entity(params.clone()).await?;
516 let Some(data) = resp.data else { break };
517
518 let r = data;
519 let count = r.len();
520 for team in r {
521 yield team;
522 }
523
524 if count < page_size as usize {
525 break;
526 }
527 if params.page_offset.is_none() {
528 params.page_offset = Some(page_size.clone());
529 } else {
530 params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
531 }
532 }
533 }
534 }
535
536 pub async fn list_catalog_entity_with_http_info(
538 &self,
539 params: ListCatalogEntityOptionalParams,
540 ) -> Result<
541 datadog::ResponseContent<crate::datadogV2::model::ListEntityCatalogResponse>,
542 datadog::Error<ListCatalogEntityError>,
543 > {
544 let local_configuration = &self.config;
545 let operation_id = "v2.list_catalog_entity";
546
547 let page_offset = params.page_offset;
549 let page_limit = params.page_limit;
550 let filter_id = params.filter_id;
551 let filter_ref = params.filter_ref;
552 let filter_name = params.filter_name;
553 let filter_kind = params.filter_kind;
554 let filter_owner = params.filter_owner;
555 let filter_relation_type = params.filter_relation_type;
556 let filter_exclude_snapshot = params.filter_exclude_snapshot;
557 let include = params.include;
558
559 let local_client = &self.client;
560
561 let local_uri_str = format!(
562 "{}/api/v2/catalog/entity",
563 local_configuration.get_operation_host(operation_id)
564 );
565 let mut local_req_builder =
566 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
567
568 if let Some(ref local_query_param) = page_offset {
569 local_req_builder =
570 local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
571 };
572 if let Some(ref local_query_param) = page_limit {
573 local_req_builder =
574 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
575 };
576 if let Some(ref local_query_param) = filter_id {
577 local_req_builder =
578 local_req_builder.query(&[("filter[id]", &local_query_param.to_string())]);
579 };
580 if let Some(ref local_query_param) = filter_ref {
581 local_req_builder =
582 local_req_builder.query(&[("filter[ref]", &local_query_param.to_string())]);
583 };
584 if let Some(ref local_query_param) = filter_name {
585 local_req_builder =
586 local_req_builder.query(&[("filter[name]", &local_query_param.to_string())]);
587 };
588 if let Some(ref local_query_param) = filter_kind {
589 local_req_builder =
590 local_req_builder.query(&[("filter[kind]", &local_query_param.to_string())]);
591 };
592 if let Some(ref local_query_param) = filter_owner {
593 local_req_builder =
594 local_req_builder.query(&[("filter[owner]", &local_query_param.to_string())]);
595 };
596 if let Some(ref local_query_param) = filter_relation_type {
597 local_req_builder = local_req_builder
598 .query(&[("filter[relation][type]", &local_query_param.to_string())]);
599 };
600 if let Some(ref local_query_param) = filter_exclude_snapshot {
601 local_req_builder = local_req_builder
602 .query(&[("filter[exclude_snapshot]", &local_query_param.to_string())]);
603 };
604 if let Some(ref local_query_param) = include {
605 local_req_builder =
606 local_req_builder.query(&[("include", &local_query_param.to_string())]);
607 };
608
609 let mut headers = HeaderMap::new();
611 headers.insert("Accept", HeaderValue::from_static("application/json"));
612
613 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
615 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
616 Err(e) => {
617 log::warn!("Failed to parse user agent header: {e}, falling back to default");
618 headers.insert(
619 reqwest::header::USER_AGENT,
620 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
621 )
622 }
623 };
624
625 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
627 headers.insert(
628 "DD-API-KEY",
629 HeaderValue::from_str(local_key.key.as_str())
630 .expect("failed to parse DD-API-KEY header"),
631 );
632 };
633 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
634 headers.insert(
635 "DD-APPLICATION-KEY",
636 HeaderValue::from_str(local_key.key.as_str())
637 .expect("failed to parse DD-APPLICATION-KEY header"),
638 );
639 };
640
641 local_req_builder = local_req_builder.headers(headers);
642 let local_req = local_req_builder.build()?;
643 log::debug!("request content: {:?}", local_req.body());
644 let local_resp = local_client.execute(local_req).await?;
645
646 let local_status = local_resp.status();
647 let local_content = local_resp.text().await?;
648 log::debug!("response content: {}", local_content);
649
650 if !local_status.is_client_error() && !local_status.is_server_error() {
651 match serde_json::from_str::<crate::datadogV2::model::ListEntityCatalogResponse>(
652 &local_content,
653 ) {
654 Ok(e) => {
655 return Ok(datadog::ResponseContent {
656 status: local_status,
657 content: local_content,
658 entity: Some(e),
659 })
660 }
661 Err(e) => return Err(datadog::Error::Serde(e)),
662 };
663 } else {
664 let local_entity: Option<ListCatalogEntityError> =
665 serde_json::from_str(&local_content).ok();
666 let local_error = datadog::ResponseContent {
667 status: local_status,
668 content: local_content,
669 entity: local_entity,
670 };
671 Err(datadog::Error::ResponseError(local_error))
672 }
673 }
674
675 pub async fn list_catalog_kind(
677 &self,
678 params: ListCatalogKindOptionalParams,
679 ) -> Result<
680 crate::datadogV2::model::ListKindCatalogResponse,
681 datadog::Error<ListCatalogKindError>,
682 > {
683 match self.list_catalog_kind_with_http_info(params).await {
684 Ok(response_content) => {
685 if let Some(e) = response_content.entity {
686 Ok(e)
687 } else {
688 Err(datadog::Error::Serde(serde::de::Error::custom(
689 "response content was None",
690 )))
691 }
692 }
693 Err(err) => Err(err),
694 }
695 }
696
697 pub fn list_catalog_kind_with_pagination(
698 &self,
699 mut params: ListCatalogKindOptionalParams,
700 ) -> impl Stream<
701 Item = Result<crate::datadogV2::model::KindData, datadog::Error<ListCatalogKindError>>,
702 > + '_ {
703 try_stream! {
704 let mut page_size: i64 = 100;
705 if params.page_limit.is_none() {
706 params.page_limit = Some(page_size);
707 } else {
708 page_size = params.page_limit.unwrap().clone();
709 }
710 loop {
711 let resp = self.list_catalog_kind(params.clone()).await?;
712 let Some(data) = resp.data else { break };
713
714 let r = data;
715 let count = r.len();
716 for team in r {
717 yield team;
718 }
719
720 if count < page_size as usize {
721 break;
722 }
723 if params.page_offset.is_none() {
724 params.page_offset = Some(page_size.clone());
725 } else {
726 params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
727 }
728 }
729 }
730 }
731
732 pub async fn list_catalog_kind_with_http_info(
734 &self,
735 params: ListCatalogKindOptionalParams,
736 ) -> Result<
737 datadog::ResponseContent<crate::datadogV2::model::ListKindCatalogResponse>,
738 datadog::Error<ListCatalogKindError>,
739 > {
740 let local_configuration = &self.config;
741 let operation_id = "v2.list_catalog_kind";
742
743 let page_offset = params.page_offset;
745 let page_limit = params.page_limit;
746 let filter_id = params.filter_id;
747 let filter_name = params.filter_name;
748
749 let local_client = &self.client;
750
751 let local_uri_str = format!(
752 "{}/api/v2/catalog/kind",
753 local_configuration.get_operation_host(operation_id)
754 );
755 let mut local_req_builder =
756 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
757
758 if let Some(ref local_query_param) = page_offset {
759 local_req_builder =
760 local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
761 };
762 if let Some(ref local_query_param) = page_limit {
763 local_req_builder =
764 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
765 };
766 if let Some(ref local_query_param) = filter_id {
767 local_req_builder =
768 local_req_builder.query(&[("filter[id]", &local_query_param.to_string())]);
769 };
770 if let Some(ref local_query_param) = filter_name {
771 local_req_builder =
772 local_req_builder.query(&[("filter[name]", &local_query_param.to_string())]);
773 };
774
775 let mut headers = HeaderMap::new();
777 headers.insert("Accept", HeaderValue::from_static("application/json"));
778
779 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
781 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
782 Err(e) => {
783 log::warn!("Failed to parse user agent header: {e}, falling back to default");
784 headers.insert(
785 reqwest::header::USER_AGENT,
786 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
787 )
788 }
789 };
790
791 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
793 headers.insert(
794 "DD-API-KEY",
795 HeaderValue::from_str(local_key.key.as_str())
796 .expect("failed to parse DD-API-KEY header"),
797 );
798 };
799 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
800 headers.insert(
801 "DD-APPLICATION-KEY",
802 HeaderValue::from_str(local_key.key.as_str())
803 .expect("failed to parse DD-APPLICATION-KEY header"),
804 );
805 };
806
807 local_req_builder = local_req_builder.headers(headers);
808 let local_req = local_req_builder.build()?;
809 log::debug!("request content: {:?}", local_req.body());
810 let local_resp = local_client.execute(local_req).await?;
811
812 let local_status = local_resp.status();
813 let local_content = local_resp.text().await?;
814 log::debug!("response content: {}", local_content);
815
816 if !local_status.is_client_error() && !local_status.is_server_error() {
817 match serde_json::from_str::<crate::datadogV2::model::ListKindCatalogResponse>(
818 &local_content,
819 ) {
820 Ok(e) => {
821 return Ok(datadog::ResponseContent {
822 status: local_status,
823 content: local_content,
824 entity: Some(e),
825 })
826 }
827 Err(e) => return Err(datadog::Error::Serde(e)),
828 };
829 } else {
830 let local_entity: Option<ListCatalogKindError> =
831 serde_json::from_str(&local_content).ok();
832 let local_error = datadog::ResponseContent {
833 status: local_status,
834 content: local_content,
835 entity: local_entity,
836 };
837 Err(datadog::Error::ResponseError(local_error))
838 }
839 }
840
841 pub async fn list_catalog_relation(
843 &self,
844 params: ListCatalogRelationOptionalParams,
845 ) -> Result<
846 crate::datadogV2::model::ListRelationCatalogResponse,
847 datadog::Error<ListCatalogRelationError>,
848 > {
849 match self.list_catalog_relation_with_http_info(params).await {
850 Ok(response_content) => {
851 if let Some(e) = response_content.entity {
852 Ok(e)
853 } else {
854 Err(datadog::Error::Serde(serde::de::Error::custom(
855 "response content was None",
856 )))
857 }
858 }
859 Err(err) => Err(err),
860 }
861 }
862
863 pub fn list_catalog_relation_with_pagination(
864 &self,
865 mut params: ListCatalogRelationOptionalParams,
866 ) -> impl Stream<
867 Item = Result<
868 crate::datadogV2::model::RelationResponse,
869 datadog::Error<ListCatalogRelationError>,
870 >,
871 > + '_ {
872 try_stream! {
873 let mut page_size: i64 = 100;
874 if params.page_limit.is_none() {
875 params.page_limit = Some(page_size);
876 } else {
877 page_size = params.page_limit.unwrap().clone();
878 }
879 loop {
880 let resp = self.list_catalog_relation(params.clone()).await?;
881 let Some(data) = resp.data else { break };
882
883 let r = data;
884 let count = r.len();
885 for team in r {
886 yield team;
887 }
888
889 if count < page_size as usize {
890 break;
891 }
892 if params.page_offset.is_none() {
893 params.page_offset = Some(page_size.clone());
894 } else {
895 params.page_offset = Some(params.page_offset.unwrap() + page_size.clone());
896 }
897 }
898 }
899 }
900
901 pub async fn list_catalog_relation_with_http_info(
903 &self,
904 params: ListCatalogRelationOptionalParams,
905 ) -> Result<
906 datadog::ResponseContent<crate::datadogV2::model::ListRelationCatalogResponse>,
907 datadog::Error<ListCatalogRelationError>,
908 > {
909 let local_configuration = &self.config;
910 let operation_id = "v2.list_catalog_relation";
911
912 let page_offset = params.page_offset;
914 let page_limit = params.page_limit;
915 let filter_type = params.filter_type;
916 let filter_from_ref = params.filter_from_ref;
917 let filter_to_ref = params.filter_to_ref;
918 let include = params.include;
919
920 let local_client = &self.client;
921
922 let local_uri_str = format!(
923 "{}/api/v2/catalog/relation",
924 local_configuration.get_operation_host(operation_id)
925 );
926 let mut local_req_builder =
927 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
928
929 if let Some(ref local_query_param) = page_offset {
930 local_req_builder =
931 local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
932 };
933 if let Some(ref local_query_param) = page_limit {
934 local_req_builder =
935 local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
936 };
937 if let Some(ref local_query_param) = filter_type {
938 local_req_builder =
939 local_req_builder.query(&[("filter[type]", &local_query_param.to_string())]);
940 };
941 if let Some(ref local_query_param) = filter_from_ref {
942 local_req_builder =
943 local_req_builder.query(&[("filter[from_ref]", &local_query_param.to_string())]);
944 };
945 if let Some(ref local_query_param) = filter_to_ref {
946 local_req_builder =
947 local_req_builder.query(&[("filter[to_ref]", &local_query_param.to_string())]);
948 };
949 if let Some(ref local_query_param) = include {
950 local_req_builder =
951 local_req_builder.query(&[("include", &local_query_param.to_string())]);
952 };
953
954 let mut headers = HeaderMap::new();
956 headers.insert("Accept", HeaderValue::from_static("application/json"));
957
958 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
960 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
961 Err(e) => {
962 log::warn!("Failed to parse user agent header: {e}, falling back to default");
963 headers.insert(
964 reqwest::header::USER_AGENT,
965 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
966 )
967 }
968 };
969
970 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
972 headers.insert(
973 "DD-API-KEY",
974 HeaderValue::from_str(local_key.key.as_str())
975 .expect("failed to parse DD-API-KEY header"),
976 );
977 };
978 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
979 headers.insert(
980 "DD-APPLICATION-KEY",
981 HeaderValue::from_str(local_key.key.as_str())
982 .expect("failed to parse DD-APPLICATION-KEY header"),
983 );
984 };
985
986 local_req_builder = local_req_builder.headers(headers);
987 let local_req = local_req_builder.build()?;
988 log::debug!("request content: {:?}", local_req.body());
989 let local_resp = local_client.execute(local_req).await?;
990
991 let local_status = local_resp.status();
992 let local_content = local_resp.text().await?;
993 log::debug!("response content: {}", local_content);
994
995 if !local_status.is_client_error() && !local_status.is_server_error() {
996 match serde_json::from_str::<crate::datadogV2::model::ListRelationCatalogResponse>(
997 &local_content,
998 ) {
999 Ok(e) => {
1000 return Ok(datadog::ResponseContent {
1001 status: local_status,
1002 content: local_content,
1003 entity: Some(e),
1004 })
1005 }
1006 Err(e) => return Err(datadog::Error::Serde(e)),
1007 };
1008 } else {
1009 let local_entity: Option<ListCatalogRelationError> =
1010 serde_json::from_str(&local_content).ok();
1011 let local_error = datadog::ResponseContent {
1012 status: local_status,
1013 content: local_content,
1014 entity: local_entity,
1015 };
1016 Err(datadog::Error::ResponseError(local_error))
1017 }
1018 }
1019
1020 pub async fn upsert_catalog_entity(
1022 &self,
1023 body: crate::datadogV2::model::UpsertCatalogEntityRequest,
1024 ) -> Result<
1025 crate::datadogV2::model::UpsertCatalogEntityResponse,
1026 datadog::Error<UpsertCatalogEntityError>,
1027 > {
1028 match self.upsert_catalog_entity_with_http_info(body).await {
1029 Ok(response_content) => {
1030 if let Some(e) = response_content.entity {
1031 Ok(e)
1032 } else {
1033 Err(datadog::Error::Serde(serde::de::Error::custom(
1034 "response content was None",
1035 )))
1036 }
1037 }
1038 Err(err) => Err(err),
1039 }
1040 }
1041
1042 pub async fn upsert_catalog_entity_with_http_info(
1044 &self,
1045 body: crate::datadogV2::model::UpsertCatalogEntityRequest,
1046 ) -> Result<
1047 datadog::ResponseContent<crate::datadogV2::model::UpsertCatalogEntityResponse>,
1048 datadog::Error<UpsertCatalogEntityError>,
1049 > {
1050 let local_configuration = &self.config;
1051 let operation_id = "v2.upsert_catalog_entity";
1052
1053 let local_client = &self.client;
1054
1055 let local_uri_str = format!(
1056 "{}/api/v2/catalog/entity",
1057 local_configuration.get_operation_host(operation_id)
1058 );
1059 let mut local_req_builder =
1060 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1061
1062 let mut headers = HeaderMap::new();
1064 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1065 headers.insert("Accept", HeaderValue::from_static("application/json"));
1066
1067 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1069 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1070 Err(e) => {
1071 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1072 headers.insert(
1073 reqwest::header::USER_AGENT,
1074 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1075 )
1076 }
1077 };
1078
1079 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1081 headers.insert(
1082 "DD-API-KEY",
1083 HeaderValue::from_str(local_key.key.as_str())
1084 .expect("failed to parse DD-API-KEY header"),
1085 );
1086 };
1087 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1088 headers.insert(
1089 "DD-APPLICATION-KEY",
1090 HeaderValue::from_str(local_key.key.as_str())
1091 .expect("failed to parse DD-APPLICATION-KEY header"),
1092 );
1093 };
1094
1095 let output = Vec::new();
1097 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1098 if body.serialize(&mut ser).is_ok() {
1099 if let Some(content_encoding) = headers.get("Content-Encoding") {
1100 match content_encoding.to_str().unwrap_or_default() {
1101 "gzip" => {
1102 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1103 let _ = enc.write_all(ser.into_inner().as_slice());
1104 match enc.finish() {
1105 Ok(buf) => {
1106 local_req_builder = local_req_builder.body(buf);
1107 }
1108 Err(e) => return Err(datadog::Error::Io(e)),
1109 }
1110 }
1111 "deflate" => {
1112 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1113 let _ = enc.write_all(ser.into_inner().as_slice());
1114 match enc.finish() {
1115 Ok(buf) => {
1116 local_req_builder = local_req_builder.body(buf);
1117 }
1118 Err(e) => return Err(datadog::Error::Io(e)),
1119 }
1120 }
1121 "zstd1" => {
1122 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1123 let _ = enc.write_all(ser.into_inner().as_slice());
1124 match enc.finish() {
1125 Ok(buf) => {
1126 local_req_builder = local_req_builder.body(buf);
1127 }
1128 Err(e) => return Err(datadog::Error::Io(e)),
1129 }
1130 }
1131 _ => {
1132 local_req_builder = local_req_builder.body(ser.into_inner());
1133 }
1134 }
1135 } else {
1136 local_req_builder = local_req_builder.body(ser.into_inner());
1137 }
1138 }
1139
1140 local_req_builder = local_req_builder.headers(headers);
1141 let local_req = local_req_builder.build()?;
1142 log::debug!("request content: {:?}", local_req.body());
1143 let local_resp = local_client.execute(local_req).await?;
1144
1145 let local_status = local_resp.status();
1146 let local_content = local_resp.text().await?;
1147 log::debug!("response content: {}", local_content);
1148
1149 if !local_status.is_client_error() && !local_status.is_server_error() {
1150 match serde_json::from_str::<crate::datadogV2::model::UpsertCatalogEntityResponse>(
1151 &local_content,
1152 ) {
1153 Ok(e) => {
1154 return Ok(datadog::ResponseContent {
1155 status: local_status,
1156 content: local_content,
1157 entity: Some(e),
1158 })
1159 }
1160 Err(e) => return Err(datadog::Error::Serde(e)),
1161 };
1162 } else {
1163 let local_entity: Option<UpsertCatalogEntityError> =
1164 serde_json::from_str(&local_content).ok();
1165 let local_error = datadog::ResponseContent {
1166 status: local_status,
1167 content: local_content,
1168 entity: local_entity,
1169 };
1170 Err(datadog::Error::ResponseError(local_error))
1171 }
1172 }
1173
1174 pub async fn upsert_catalog_kind(
1176 &self,
1177 body: crate::datadogV2::model::UpsertCatalogKindRequest,
1178 ) -> Result<
1179 crate::datadogV2::model::UpsertCatalogKindResponse,
1180 datadog::Error<UpsertCatalogKindError>,
1181 > {
1182 match self.upsert_catalog_kind_with_http_info(body).await {
1183 Ok(response_content) => {
1184 if let Some(e) = response_content.entity {
1185 Ok(e)
1186 } else {
1187 Err(datadog::Error::Serde(serde::de::Error::custom(
1188 "response content was None",
1189 )))
1190 }
1191 }
1192 Err(err) => Err(err),
1193 }
1194 }
1195
1196 pub async fn upsert_catalog_kind_with_http_info(
1198 &self,
1199 body: crate::datadogV2::model::UpsertCatalogKindRequest,
1200 ) -> Result<
1201 datadog::ResponseContent<crate::datadogV2::model::UpsertCatalogKindResponse>,
1202 datadog::Error<UpsertCatalogKindError>,
1203 > {
1204 let local_configuration = &self.config;
1205 let operation_id = "v2.upsert_catalog_kind";
1206
1207 let local_client = &self.client;
1208
1209 let local_uri_str = format!(
1210 "{}/api/v2/catalog/kind",
1211 local_configuration.get_operation_host(operation_id)
1212 );
1213 let mut local_req_builder =
1214 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1215
1216 let mut headers = HeaderMap::new();
1218 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1219 headers.insert("Accept", HeaderValue::from_static("application/json"));
1220
1221 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1223 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1224 Err(e) => {
1225 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1226 headers.insert(
1227 reqwest::header::USER_AGENT,
1228 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1229 )
1230 }
1231 };
1232
1233 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1235 headers.insert(
1236 "DD-API-KEY",
1237 HeaderValue::from_str(local_key.key.as_str())
1238 .expect("failed to parse DD-API-KEY header"),
1239 );
1240 };
1241 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1242 headers.insert(
1243 "DD-APPLICATION-KEY",
1244 HeaderValue::from_str(local_key.key.as_str())
1245 .expect("failed to parse DD-APPLICATION-KEY header"),
1246 );
1247 };
1248
1249 let output = Vec::new();
1251 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1252 if body.serialize(&mut ser).is_ok() {
1253 if let Some(content_encoding) = headers.get("Content-Encoding") {
1254 match content_encoding.to_str().unwrap_or_default() {
1255 "gzip" => {
1256 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1257 let _ = enc.write_all(ser.into_inner().as_slice());
1258 match enc.finish() {
1259 Ok(buf) => {
1260 local_req_builder = local_req_builder.body(buf);
1261 }
1262 Err(e) => return Err(datadog::Error::Io(e)),
1263 }
1264 }
1265 "deflate" => {
1266 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1267 let _ = enc.write_all(ser.into_inner().as_slice());
1268 match enc.finish() {
1269 Ok(buf) => {
1270 local_req_builder = local_req_builder.body(buf);
1271 }
1272 Err(e) => return Err(datadog::Error::Io(e)),
1273 }
1274 }
1275 "zstd1" => {
1276 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1277 let _ = enc.write_all(ser.into_inner().as_slice());
1278 match enc.finish() {
1279 Ok(buf) => {
1280 local_req_builder = local_req_builder.body(buf);
1281 }
1282 Err(e) => return Err(datadog::Error::Io(e)),
1283 }
1284 }
1285 _ => {
1286 local_req_builder = local_req_builder.body(ser.into_inner());
1287 }
1288 }
1289 } else {
1290 local_req_builder = local_req_builder.body(ser.into_inner());
1291 }
1292 }
1293
1294 local_req_builder = local_req_builder.headers(headers);
1295 let local_req = local_req_builder.build()?;
1296 log::debug!("request content: {:?}", local_req.body());
1297 let local_resp = local_client.execute(local_req).await?;
1298
1299 let local_status = local_resp.status();
1300 let local_content = local_resp.text().await?;
1301 log::debug!("response content: {}", local_content);
1302
1303 if !local_status.is_client_error() && !local_status.is_server_error() {
1304 match serde_json::from_str::<crate::datadogV2::model::UpsertCatalogKindResponse>(
1305 &local_content,
1306 ) {
1307 Ok(e) => {
1308 return Ok(datadog::ResponseContent {
1309 status: local_status,
1310 content: local_content,
1311 entity: Some(e),
1312 })
1313 }
1314 Err(e) => return Err(datadog::Error::Serde(e)),
1315 };
1316 } else {
1317 let local_entity: Option<UpsertCatalogKindError> =
1318 serde_json::from_str(&local_content).ok();
1319 let local_error = datadog::ResponseContent {
1320 status: local_status,
1321 content: local_content,
1322 entity: local_entity,
1323 };
1324 Err(datadog::Error::ResponseError(local_error))
1325 }
1326 }
1327}