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 CreateConfluentAccountError {
17 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18 UnknownValue(serde_json::Value),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateConfluentResourceError {
25 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteConfluentAccountError {
33 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteConfluentResourceError {
41 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetConfluentAccountError {
49 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetConfluentResourceError {
57 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListConfluentAccountError {
65 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListConfluentResourceError {
73 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum UpdateConfluentAccountError {
81 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateConfluentResourceError {
89 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90 UnknownValue(serde_json::Value),
91}
92
93#[derive(Debug, Clone)]
95pub struct ConfluentCloudAPI {
96 config: datadog::Configuration,
97 client: reqwest_middleware::ClientWithMiddleware,
98}
99
100impl Default for ConfluentCloudAPI {
101 fn default() -> Self {
102 Self::with_config(datadog::Configuration::default())
103 }
104}
105
106impl ConfluentCloudAPI {
107 pub fn new() -> Self {
108 Self::default()
109 }
110 pub fn with_config(config: datadog::Configuration) -> Self {
111 let mut reqwest_client_builder = reqwest::Client::builder();
112
113 if let Some(proxy_url) = &config.proxy_url {
114 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
115 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
116 }
117
118 let mut middleware_client_builder =
119 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
120
121 if config.enable_retry {
122 struct RetryableStatus;
123 impl reqwest_retry::RetryableStrategy for RetryableStatus {
124 fn handle(
125 &self,
126 res: &Result<reqwest::Response, reqwest_middleware::Error>,
127 ) -> Option<reqwest_retry::Retryable> {
128 match res {
129 Ok(success) => reqwest_retry::default_on_request_success(success),
130 Err(_) => None,
131 }
132 }
133 }
134 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
135 .build_with_max_retries(config.max_retries);
136
137 let retry_middleware =
138 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
139 backoff_policy,
140 RetryableStatus,
141 );
142
143 middleware_client_builder = middleware_client_builder.with(retry_middleware);
144 }
145
146 let client = middleware_client_builder.build();
147
148 Self { config, client }
149 }
150
151 pub fn with_client_and_config(
152 config: datadog::Configuration,
153 client: reqwest_middleware::ClientWithMiddleware,
154 ) -> Self {
155 Self { config, client }
156 }
157
158 pub async fn create_confluent_account(
160 &self,
161 body: crate::datadogV2::model::ConfluentAccountCreateRequest,
162 ) -> Result<
163 crate::datadogV2::model::ConfluentAccountResponse,
164 datadog::Error<CreateConfluentAccountError>,
165 > {
166 match self.create_confluent_account_with_http_info(body).await {
167 Ok(response_content) => {
168 if let Some(e) = response_content.entity {
169 Ok(e)
170 } else {
171 Err(datadog::Error::Serde(serde::de::Error::custom(
172 "response content was None",
173 )))
174 }
175 }
176 Err(err) => Err(err),
177 }
178 }
179
180 pub async fn create_confluent_account_with_http_info(
182 &self,
183 body: crate::datadogV2::model::ConfluentAccountCreateRequest,
184 ) -> Result<
185 datadog::ResponseContent<crate::datadogV2::model::ConfluentAccountResponse>,
186 datadog::Error<CreateConfluentAccountError>,
187 > {
188 let local_configuration = &self.config;
189 let operation_id = "v2.create_confluent_account";
190
191 let local_client = &self.client;
192
193 let local_uri_str = format!(
194 "{}/api/v2/integrations/confluent-cloud/accounts",
195 local_configuration.get_operation_host(operation_id)
196 );
197 let mut local_req_builder =
198 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
199
200 let mut headers = HeaderMap::new();
202 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
203 headers.insert("Accept", HeaderValue::from_static("application/json"));
204
205 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
207 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
208 Err(e) => {
209 log::warn!("Failed to parse user agent header: {e}, falling back to default");
210 headers.insert(
211 reqwest::header::USER_AGENT,
212 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
213 )
214 }
215 };
216
217 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
219 headers.insert(
220 "DD-API-KEY",
221 HeaderValue::from_str(local_key.key.as_str())
222 .expect("failed to parse DD-API-KEY header"),
223 );
224 };
225 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
226 headers.insert(
227 "DD-APPLICATION-KEY",
228 HeaderValue::from_str(local_key.key.as_str())
229 .expect("failed to parse DD-APPLICATION-KEY header"),
230 );
231 };
232
233 let output = Vec::new();
235 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
236 if body.serialize(&mut ser).is_ok() {
237 if let Some(content_encoding) = headers.get("Content-Encoding") {
238 match content_encoding.to_str().unwrap_or_default() {
239 "gzip" => {
240 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
241 let _ = enc.write_all(ser.into_inner().as_slice());
242 match enc.finish() {
243 Ok(buf) => {
244 local_req_builder = local_req_builder.body(buf);
245 }
246 Err(e) => return Err(datadog::Error::Io(e)),
247 }
248 }
249 "deflate" => {
250 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
251 let _ = enc.write_all(ser.into_inner().as_slice());
252 match enc.finish() {
253 Ok(buf) => {
254 local_req_builder = local_req_builder.body(buf);
255 }
256 Err(e) => return Err(datadog::Error::Io(e)),
257 }
258 }
259 "zstd1" => {
260 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
261 let _ = enc.write_all(ser.into_inner().as_slice());
262 match enc.finish() {
263 Ok(buf) => {
264 local_req_builder = local_req_builder.body(buf);
265 }
266 Err(e) => return Err(datadog::Error::Io(e)),
267 }
268 }
269 _ => {
270 local_req_builder = local_req_builder.body(ser.into_inner());
271 }
272 }
273 } else {
274 local_req_builder = local_req_builder.body(ser.into_inner());
275 }
276 }
277
278 local_req_builder = local_req_builder.headers(headers);
279 let local_req = local_req_builder.build()?;
280 log::debug!("request content: {:?}", local_req.body());
281 let local_resp = local_client.execute(local_req).await?;
282
283 let local_status = local_resp.status();
284 let local_content = local_resp.text().await?;
285 log::debug!("response content: {}", local_content);
286
287 if !local_status.is_client_error() && !local_status.is_server_error() {
288 match serde_json::from_str::<crate::datadogV2::model::ConfluentAccountResponse>(
289 &local_content,
290 ) {
291 Ok(e) => {
292 return Ok(datadog::ResponseContent {
293 status: local_status,
294 content: local_content,
295 entity: Some(e),
296 })
297 }
298 Err(e) => return Err(datadog::Error::Serde(e)),
299 };
300 } else {
301 let local_entity: Option<CreateConfluentAccountError> =
302 serde_json::from_str(&local_content).ok();
303 let local_error = datadog::ResponseContent {
304 status: local_status,
305 content: local_content,
306 entity: local_entity,
307 };
308 Err(datadog::Error::ResponseError(local_error))
309 }
310 }
311
312 pub async fn create_confluent_resource(
314 &self,
315 account_id: String,
316 body: crate::datadogV2::model::ConfluentResourceRequest,
317 ) -> Result<
318 crate::datadogV2::model::ConfluentResourceResponse,
319 datadog::Error<CreateConfluentResourceError>,
320 > {
321 match self
322 .create_confluent_resource_with_http_info(account_id, body)
323 .await
324 {
325 Ok(response_content) => {
326 if let Some(e) = response_content.entity {
327 Ok(e)
328 } else {
329 Err(datadog::Error::Serde(serde::de::Error::custom(
330 "response content was None",
331 )))
332 }
333 }
334 Err(err) => Err(err),
335 }
336 }
337
338 pub async fn create_confluent_resource_with_http_info(
340 &self,
341 account_id: String,
342 body: crate::datadogV2::model::ConfluentResourceRequest,
343 ) -> Result<
344 datadog::ResponseContent<crate::datadogV2::model::ConfluentResourceResponse>,
345 datadog::Error<CreateConfluentResourceError>,
346 > {
347 let local_configuration = &self.config;
348 let operation_id = "v2.create_confluent_resource";
349
350 let local_client = &self.client;
351
352 let local_uri_str = format!(
353 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}/resources",
354 local_configuration.get_operation_host(operation_id),
355 account_id = datadog::urlencode(account_id)
356 );
357 let mut local_req_builder =
358 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
359
360 let mut headers = HeaderMap::new();
362 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
363 headers.insert("Accept", HeaderValue::from_static("application/json"));
364
365 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
367 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
368 Err(e) => {
369 log::warn!("Failed to parse user agent header: {e}, falling back to default");
370 headers.insert(
371 reqwest::header::USER_AGENT,
372 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
373 )
374 }
375 };
376
377 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
379 headers.insert(
380 "DD-API-KEY",
381 HeaderValue::from_str(local_key.key.as_str())
382 .expect("failed to parse DD-API-KEY header"),
383 );
384 };
385 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
386 headers.insert(
387 "DD-APPLICATION-KEY",
388 HeaderValue::from_str(local_key.key.as_str())
389 .expect("failed to parse DD-APPLICATION-KEY header"),
390 );
391 };
392
393 let output = Vec::new();
395 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
396 if body.serialize(&mut ser).is_ok() {
397 if let Some(content_encoding) = headers.get("Content-Encoding") {
398 match content_encoding.to_str().unwrap_or_default() {
399 "gzip" => {
400 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
401 let _ = enc.write_all(ser.into_inner().as_slice());
402 match enc.finish() {
403 Ok(buf) => {
404 local_req_builder = local_req_builder.body(buf);
405 }
406 Err(e) => return Err(datadog::Error::Io(e)),
407 }
408 }
409 "deflate" => {
410 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
411 let _ = enc.write_all(ser.into_inner().as_slice());
412 match enc.finish() {
413 Ok(buf) => {
414 local_req_builder = local_req_builder.body(buf);
415 }
416 Err(e) => return Err(datadog::Error::Io(e)),
417 }
418 }
419 "zstd1" => {
420 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
421 let _ = enc.write_all(ser.into_inner().as_slice());
422 match enc.finish() {
423 Ok(buf) => {
424 local_req_builder = local_req_builder.body(buf);
425 }
426 Err(e) => return Err(datadog::Error::Io(e)),
427 }
428 }
429 _ => {
430 local_req_builder = local_req_builder.body(ser.into_inner());
431 }
432 }
433 } else {
434 local_req_builder = local_req_builder.body(ser.into_inner());
435 }
436 }
437
438 local_req_builder = local_req_builder.headers(headers);
439 let local_req = local_req_builder.build()?;
440 log::debug!("request content: {:?}", local_req.body());
441 let local_resp = local_client.execute(local_req).await?;
442
443 let local_status = local_resp.status();
444 let local_content = local_resp.text().await?;
445 log::debug!("response content: {}", local_content);
446
447 if !local_status.is_client_error() && !local_status.is_server_error() {
448 match serde_json::from_str::<crate::datadogV2::model::ConfluentResourceResponse>(
449 &local_content,
450 ) {
451 Ok(e) => {
452 return Ok(datadog::ResponseContent {
453 status: local_status,
454 content: local_content,
455 entity: Some(e),
456 })
457 }
458 Err(e) => return Err(datadog::Error::Serde(e)),
459 };
460 } else {
461 let local_entity: Option<CreateConfluentResourceError> =
462 serde_json::from_str(&local_content).ok();
463 let local_error = datadog::ResponseContent {
464 status: local_status,
465 content: local_content,
466 entity: local_entity,
467 };
468 Err(datadog::Error::ResponseError(local_error))
469 }
470 }
471
472 pub async fn delete_confluent_account(
474 &self,
475 account_id: String,
476 ) -> Result<(), datadog::Error<DeleteConfluentAccountError>> {
477 match self
478 .delete_confluent_account_with_http_info(account_id)
479 .await
480 {
481 Ok(_) => Ok(()),
482 Err(err) => Err(err),
483 }
484 }
485
486 pub async fn delete_confluent_account_with_http_info(
488 &self,
489 account_id: String,
490 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteConfluentAccountError>> {
491 let local_configuration = &self.config;
492 let operation_id = "v2.delete_confluent_account";
493
494 let local_client = &self.client;
495
496 let local_uri_str = format!(
497 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}",
498 local_configuration.get_operation_host(operation_id),
499 account_id = datadog::urlencode(account_id)
500 );
501 let mut local_req_builder =
502 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
503
504 let mut headers = HeaderMap::new();
506 headers.insert("Accept", HeaderValue::from_static("*/*"));
507
508 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
510 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
511 Err(e) => {
512 log::warn!("Failed to parse user agent header: {e}, falling back to default");
513 headers.insert(
514 reqwest::header::USER_AGENT,
515 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
516 )
517 }
518 };
519
520 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
522 headers.insert(
523 "DD-API-KEY",
524 HeaderValue::from_str(local_key.key.as_str())
525 .expect("failed to parse DD-API-KEY header"),
526 );
527 };
528 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
529 headers.insert(
530 "DD-APPLICATION-KEY",
531 HeaderValue::from_str(local_key.key.as_str())
532 .expect("failed to parse DD-APPLICATION-KEY header"),
533 );
534 };
535
536 local_req_builder = local_req_builder.headers(headers);
537 let local_req = local_req_builder.build()?;
538 log::debug!("request content: {:?}", local_req.body());
539 let local_resp = local_client.execute(local_req).await?;
540
541 let local_status = local_resp.status();
542 let local_content = local_resp.text().await?;
543 log::debug!("response content: {}", local_content);
544
545 if !local_status.is_client_error() && !local_status.is_server_error() {
546 Ok(datadog::ResponseContent {
547 status: local_status,
548 content: local_content,
549 entity: None,
550 })
551 } else {
552 let local_entity: Option<DeleteConfluentAccountError> =
553 serde_json::from_str(&local_content).ok();
554 let local_error = datadog::ResponseContent {
555 status: local_status,
556 content: local_content,
557 entity: local_entity,
558 };
559 Err(datadog::Error::ResponseError(local_error))
560 }
561 }
562
563 pub async fn delete_confluent_resource(
565 &self,
566 account_id: String,
567 resource_id: String,
568 ) -> Result<(), datadog::Error<DeleteConfluentResourceError>> {
569 match self
570 .delete_confluent_resource_with_http_info(account_id, resource_id)
571 .await
572 {
573 Ok(_) => Ok(()),
574 Err(err) => Err(err),
575 }
576 }
577
578 pub async fn delete_confluent_resource_with_http_info(
580 &self,
581 account_id: String,
582 resource_id: String,
583 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteConfluentResourceError>> {
584 let local_configuration = &self.config;
585 let operation_id = "v2.delete_confluent_resource";
586
587 let local_client = &self.client;
588
589 let local_uri_str = format!(
590 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}/resources/{resource_id}",
591 local_configuration.get_operation_host(operation_id),
592 account_id = datadog::urlencode(account_id),
593 resource_id = datadog::urlencode(resource_id)
594 );
595 let mut local_req_builder =
596 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
597
598 let mut headers = HeaderMap::new();
600 headers.insert("Accept", HeaderValue::from_static("*/*"));
601
602 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
604 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
605 Err(e) => {
606 log::warn!("Failed to parse user agent header: {e}, falling back to default");
607 headers.insert(
608 reqwest::header::USER_AGENT,
609 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
610 )
611 }
612 };
613
614 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
616 headers.insert(
617 "DD-API-KEY",
618 HeaderValue::from_str(local_key.key.as_str())
619 .expect("failed to parse DD-API-KEY header"),
620 );
621 };
622 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
623 headers.insert(
624 "DD-APPLICATION-KEY",
625 HeaderValue::from_str(local_key.key.as_str())
626 .expect("failed to parse DD-APPLICATION-KEY header"),
627 );
628 };
629
630 local_req_builder = local_req_builder.headers(headers);
631 let local_req = local_req_builder.build()?;
632 log::debug!("request content: {:?}", local_req.body());
633 let local_resp = local_client.execute(local_req).await?;
634
635 let local_status = local_resp.status();
636 let local_content = local_resp.text().await?;
637 log::debug!("response content: {}", local_content);
638
639 if !local_status.is_client_error() && !local_status.is_server_error() {
640 Ok(datadog::ResponseContent {
641 status: local_status,
642 content: local_content,
643 entity: None,
644 })
645 } else {
646 let local_entity: Option<DeleteConfluentResourceError> =
647 serde_json::from_str(&local_content).ok();
648 let local_error = datadog::ResponseContent {
649 status: local_status,
650 content: local_content,
651 entity: local_entity,
652 };
653 Err(datadog::Error::ResponseError(local_error))
654 }
655 }
656
657 pub async fn get_confluent_account(
659 &self,
660 account_id: String,
661 ) -> Result<
662 crate::datadogV2::model::ConfluentAccountResponse,
663 datadog::Error<GetConfluentAccountError>,
664 > {
665 match self.get_confluent_account_with_http_info(account_id).await {
666 Ok(response_content) => {
667 if let Some(e) = response_content.entity {
668 Ok(e)
669 } else {
670 Err(datadog::Error::Serde(serde::de::Error::custom(
671 "response content was None",
672 )))
673 }
674 }
675 Err(err) => Err(err),
676 }
677 }
678
679 pub async fn get_confluent_account_with_http_info(
681 &self,
682 account_id: String,
683 ) -> Result<
684 datadog::ResponseContent<crate::datadogV2::model::ConfluentAccountResponse>,
685 datadog::Error<GetConfluentAccountError>,
686 > {
687 let local_configuration = &self.config;
688 let operation_id = "v2.get_confluent_account";
689
690 let local_client = &self.client;
691
692 let local_uri_str = format!(
693 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}",
694 local_configuration.get_operation_host(operation_id),
695 account_id = datadog::urlencode(account_id)
696 );
697 let mut local_req_builder =
698 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
699
700 let mut headers = HeaderMap::new();
702 headers.insert("Accept", HeaderValue::from_static("application/json"));
703
704 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
706 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
707 Err(e) => {
708 log::warn!("Failed to parse user agent header: {e}, falling back to default");
709 headers.insert(
710 reqwest::header::USER_AGENT,
711 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
712 )
713 }
714 };
715
716 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
718 headers.insert(
719 "DD-API-KEY",
720 HeaderValue::from_str(local_key.key.as_str())
721 .expect("failed to parse DD-API-KEY header"),
722 );
723 };
724 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
725 headers.insert(
726 "DD-APPLICATION-KEY",
727 HeaderValue::from_str(local_key.key.as_str())
728 .expect("failed to parse DD-APPLICATION-KEY header"),
729 );
730 };
731
732 local_req_builder = local_req_builder.headers(headers);
733 let local_req = local_req_builder.build()?;
734 log::debug!("request content: {:?}", local_req.body());
735 let local_resp = local_client.execute(local_req).await?;
736
737 let local_status = local_resp.status();
738 let local_content = local_resp.text().await?;
739 log::debug!("response content: {}", local_content);
740
741 if !local_status.is_client_error() && !local_status.is_server_error() {
742 match serde_json::from_str::<crate::datadogV2::model::ConfluentAccountResponse>(
743 &local_content,
744 ) {
745 Ok(e) => {
746 return Ok(datadog::ResponseContent {
747 status: local_status,
748 content: local_content,
749 entity: Some(e),
750 })
751 }
752 Err(e) => return Err(datadog::Error::Serde(e)),
753 };
754 } else {
755 let local_entity: Option<GetConfluentAccountError> =
756 serde_json::from_str(&local_content).ok();
757 let local_error = datadog::ResponseContent {
758 status: local_status,
759 content: local_content,
760 entity: local_entity,
761 };
762 Err(datadog::Error::ResponseError(local_error))
763 }
764 }
765
766 pub async fn get_confluent_resource(
768 &self,
769 account_id: String,
770 resource_id: String,
771 ) -> Result<
772 crate::datadogV2::model::ConfluentResourceResponse,
773 datadog::Error<GetConfluentResourceError>,
774 > {
775 match self
776 .get_confluent_resource_with_http_info(account_id, resource_id)
777 .await
778 {
779 Ok(response_content) => {
780 if let Some(e) = response_content.entity {
781 Ok(e)
782 } else {
783 Err(datadog::Error::Serde(serde::de::Error::custom(
784 "response content was None",
785 )))
786 }
787 }
788 Err(err) => Err(err),
789 }
790 }
791
792 pub async fn get_confluent_resource_with_http_info(
794 &self,
795 account_id: String,
796 resource_id: String,
797 ) -> Result<
798 datadog::ResponseContent<crate::datadogV2::model::ConfluentResourceResponse>,
799 datadog::Error<GetConfluentResourceError>,
800 > {
801 let local_configuration = &self.config;
802 let operation_id = "v2.get_confluent_resource";
803
804 let local_client = &self.client;
805
806 let local_uri_str = format!(
807 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}/resources/{resource_id}",
808 local_configuration.get_operation_host(operation_id),
809 account_id = datadog::urlencode(account_id),
810 resource_id = datadog::urlencode(resource_id)
811 );
812 let mut local_req_builder =
813 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
814
815 let mut headers = HeaderMap::new();
817 headers.insert("Accept", HeaderValue::from_static("application/json"));
818
819 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
821 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
822 Err(e) => {
823 log::warn!("Failed to parse user agent header: {e}, falling back to default");
824 headers.insert(
825 reqwest::header::USER_AGENT,
826 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
827 )
828 }
829 };
830
831 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
833 headers.insert(
834 "DD-API-KEY",
835 HeaderValue::from_str(local_key.key.as_str())
836 .expect("failed to parse DD-API-KEY header"),
837 );
838 };
839 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
840 headers.insert(
841 "DD-APPLICATION-KEY",
842 HeaderValue::from_str(local_key.key.as_str())
843 .expect("failed to parse DD-APPLICATION-KEY header"),
844 );
845 };
846
847 local_req_builder = local_req_builder.headers(headers);
848 let local_req = local_req_builder.build()?;
849 log::debug!("request content: {:?}", local_req.body());
850 let local_resp = local_client.execute(local_req).await?;
851
852 let local_status = local_resp.status();
853 let local_content = local_resp.text().await?;
854 log::debug!("response content: {}", local_content);
855
856 if !local_status.is_client_error() && !local_status.is_server_error() {
857 match serde_json::from_str::<crate::datadogV2::model::ConfluentResourceResponse>(
858 &local_content,
859 ) {
860 Ok(e) => {
861 return Ok(datadog::ResponseContent {
862 status: local_status,
863 content: local_content,
864 entity: Some(e),
865 })
866 }
867 Err(e) => return Err(datadog::Error::Serde(e)),
868 };
869 } else {
870 let local_entity: Option<GetConfluentResourceError> =
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 list_confluent_account(
883 &self,
884 ) -> Result<
885 crate::datadogV2::model::ConfluentAccountsResponse,
886 datadog::Error<ListConfluentAccountError>,
887 > {
888 match self.list_confluent_account_with_http_info().await {
889 Ok(response_content) => {
890 if let Some(e) = response_content.entity {
891 Ok(e)
892 } else {
893 Err(datadog::Error::Serde(serde::de::Error::custom(
894 "response content was None",
895 )))
896 }
897 }
898 Err(err) => Err(err),
899 }
900 }
901
902 pub async fn list_confluent_account_with_http_info(
904 &self,
905 ) -> Result<
906 datadog::ResponseContent<crate::datadogV2::model::ConfluentAccountsResponse>,
907 datadog::Error<ListConfluentAccountError>,
908 > {
909 let local_configuration = &self.config;
910 let operation_id = "v2.list_confluent_account";
911
912 let local_client = &self.client;
913
914 let local_uri_str = format!(
915 "{}/api/v2/integrations/confluent-cloud/accounts",
916 local_configuration.get_operation_host(operation_id)
917 );
918 let mut local_req_builder =
919 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
920
921 let mut headers = HeaderMap::new();
923 headers.insert("Accept", HeaderValue::from_static("application/json"));
924
925 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
927 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
928 Err(e) => {
929 log::warn!("Failed to parse user agent header: {e}, falling back to default");
930 headers.insert(
931 reqwest::header::USER_AGENT,
932 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
933 )
934 }
935 };
936
937 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
939 headers.insert(
940 "DD-API-KEY",
941 HeaderValue::from_str(local_key.key.as_str())
942 .expect("failed to parse DD-API-KEY header"),
943 );
944 };
945 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
946 headers.insert(
947 "DD-APPLICATION-KEY",
948 HeaderValue::from_str(local_key.key.as_str())
949 .expect("failed to parse DD-APPLICATION-KEY header"),
950 );
951 };
952
953 local_req_builder = local_req_builder.headers(headers);
954 let local_req = local_req_builder.build()?;
955 log::debug!("request content: {:?}", local_req.body());
956 let local_resp = local_client.execute(local_req).await?;
957
958 let local_status = local_resp.status();
959 let local_content = local_resp.text().await?;
960 log::debug!("response content: {}", local_content);
961
962 if !local_status.is_client_error() && !local_status.is_server_error() {
963 match serde_json::from_str::<crate::datadogV2::model::ConfluentAccountsResponse>(
964 &local_content,
965 ) {
966 Ok(e) => {
967 return Ok(datadog::ResponseContent {
968 status: local_status,
969 content: local_content,
970 entity: Some(e),
971 })
972 }
973 Err(e) => return Err(datadog::Error::Serde(e)),
974 };
975 } else {
976 let local_entity: Option<ListConfluentAccountError> =
977 serde_json::from_str(&local_content).ok();
978 let local_error = datadog::ResponseContent {
979 status: local_status,
980 content: local_content,
981 entity: local_entity,
982 };
983 Err(datadog::Error::ResponseError(local_error))
984 }
985 }
986
987 pub async fn list_confluent_resource(
989 &self,
990 account_id: String,
991 ) -> Result<
992 crate::datadogV2::model::ConfluentResourcesResponse,
993 datadog::Error<ListConfluentResourceError>,
994 > {
995 match self
996 .list_confluent_resource_with_http_info(account_id)
997 .await
998 {
999 Ok(response_content) => {
1000 if let Some(e) = response_content.entity {
1001 Ok(e)
1002 } else {
1003 Err(datadog::Error::Serde(serde::de::Error::custom(
1004 "response content was None",
1005 )))
1006 }
1007 }
1008 Err(err) => Err(err),
1009 }
1010 }
1011
1012 pub async fn list_confluent_resource_with_http_info(
1014 &self,
1015 account_id: String,
1016 ) -> Result<
1017 datadog::ResponseContent<crate::datadogV2::model::ConfluentResourcesResponse>,
1018 datadog::Error<ListConfluentResourceError>,
1019 > {
1020 let local_configuration = &self.config;
1021 let operation_id = "v2.list_confluent_resource";
1022
1023 let local_client = &self.client;
1024
1025 let local_uri_str = format!(
1026 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}/resources",
1027 local_configuration.get_operation_host(operation_id),
1028 account_id = datadog::urlencode(account_id)
1029 );
1030 let mut local_req_builder =
1031 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1032
1033 let mut headers = HeaderMap::new();
1035 headers.insert("Accept", HeaderValue::from_static("application/json"));
1036
1037 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1039 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1040 Err(e) => {
1041 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1042 headers.insert(
1043 reqwest::header::USER_AGENT,
1044 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1045 )
1046 }
1047 };
1048
1049 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1051 headers.insert(
1052 "DD-API-KEY",
1053 HeaderValue::from_str(local_key.key.as_str())
1054 .expect("failed to parse DD-API-KEY header"),
1055 );
1056 };
1057 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1058 headers.insert(
1059 "DD-APPLICATION-KEY",
1060 HeaderValue::from_str(local_key.key.as_str())
1061 .expect("failed to parse DD-APPLICATION-KEY header"),
1062 );
1063 };
1064
1065 local_req_builder = local_req_builder.headers(headers);
1066 let local_req = local_req_builder.build()?;
1067 log::debug!("request content: {:?}", local_req.body());
1068 let local_resp = local_client.execute(local_req).await?;
1069
1070 let local_status = local_resp.status();
1071 let local_content = local_resp.text().await?;
1072 log::debug!("response content: {}", local_content);
1073
1074 if !local_status.is_client_error() && !local_status.is_server_error() {
1075 match serde_json::from_str::<crate::datadogV2::model::ConfluentResourcesResponse>(
1076 &local_content,
1077 ) {
1078 Ok(e) => {
1079 return Ok(datadog::ResponseContent {
1080 status: local_status,
1081 content: local_content,
1082 entity: Some(e),
1083 })
1084 }
1085 Err(e) => return Err(datadog::Error::Serde(e)),
1086 };
1087 } else {
1088 let local_entity: Option<ListConfluentResourceError> =
1089 serde_json::from_str(&local_content).ok();
1090 let local_error = datadog::ResponseContent {
1091 status: local_status,
1092 content: local_content,
1093 entity: local_entity,
1094 };
1095 Err(datadog::Error::ResponseError(local_error))
1096 }
1097 }
1098
1099 pub async fn update_confluent_account(
1101 &self,
1102 account_id: String,
1103 body: crate::datadogV2::model::ConfluentAccountUpdateRequest,
1104 ) -> Result<
1105 crate::datadogV2::model::ConfluentAccountResponse,
1106 datadog::Error<UpdateConfluentAccountError>,
1107 > {
1108 match self
1109 .update_confluent_account_with_http_info(account_id, body)
1110 .await
1111 {
1112 Ok(response_content) => {
1113 if let Some(e) = response_content.entity {
1114 Ok(e)
1115 } else {
1116 Err(datadog::Error::Serde(serde::de::Error::custom(
1117 "response content was None",
1118 )))
1119 }
1120 }
1121 Err(err) => Err(err),
1122 }
1123 }
1124
1125 pub async fn update_confluent_account_with_http_info(
1127 &self,
1128 account_id: String,
1129 body: crate::datadogV2::model::ConfluentAccountUpdateRequest,
1130 ) -> Result<
1131 datadog::ResponseContent<crate::datadogV2::model::ConfluentAccountResponse>,
1132 datadog::Error<UpdateConfluentAccountError>,
1133 > {
1134 let local_configuration = &self.config;
1135 let operation_id = "v2.update_confluent_account";
1136
1137 let local_client = &self.client;
1138
1139 let local_uri_str = format!(
1140 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}",
1141 local_configuration.get_operation_host(operation_id),
1142 account_id = datadog::urlencode(account_id)
1143 );
1144 let mut local_req_builder =
1145 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1146
1147 let mut headers = HeaderMap::new();
1149 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1150 headers.insert("Accept", HeaderValue::from_static("application/json"));
1151
1152 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1154 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1155 Err(e) => {
1156 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1157 headers.insert(
1158 reqwest::header::USER_AGENT,
1159 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1160 )
1161 }
1162 };
1163
1164 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1166 headers.insert(
1167 "DD-API-KEY",
1168 HeaderValue::from_str(local_key.key.as_str())
1169 .expect("failed to parse DD-API-KEY header"),
1170 );
1171 };
1172 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1173 headers.insert(
1174 "DD-APPLICATION-KEY",
1175 HeaderValue::from_str(local_key.key.as_str())
1176 .expect("failed to parse DD-APPLICATION-KEY header"),
1177 );
1178 };
1179
1180 let output = Vec::new();
1182 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1183 if body.serialize(&mut ser).is_ok() {
1184 if let Some(content_encoding) = headers.get("Content-Encoding") {
1185 match content_encoding.to_str().unwrap_or_default() {
1186 "gzip" => {
1187 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1188 let _ = enc.write_all(ser.into_inner().as_slice());
1189 match enc.finish() {
1190 Ok(buf) => {
1191 local_req_builder = local_req_builder.body(buf);
1192 }
1193 Err(e) => return Err(datadog::Error::Io(e)),
1194 }
1195 }
1196 "deflate" => {
1197 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1198 let _ = enc.write_all(ser.into_inner().as_slice());
1199 match enc.finish() {
1200 Ok(buf) => {
1201 local_req_builder = local_req_builder.body(buf);
1202 }
1203 Err(e) => return Err(datadog::Error::Io(e)),
1204 }
1205 }
1206 "zstd1" => {
1207 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1208 let _ = enc.write_all(ser.into_inner().as_slice());
1209 match enc.finish() {
1210 Ok(buf) => {
1211 local_req_builder = local_req_builder.body(buf);
1212 }
1213 Err(e) => return Err(datadog::Error::Io(e)),
1214 }
1215 }
1216 _ => {
1217 local_req_builder = local_req_builder.body(ser.into_inner());
1218 }
1219 }
1220 } else {
1221 local_req_builder = local_req_builder.body(ser.into_inner());
1222 }
1223 }
1224
1225 local_req_builder = local_req_builder.headers(headers);
1226 let local_req = local_req_builder.build()?;
1227 log::debug!("request content: {:?}", local_req.body());
1228 let local_resp = local_client.execute(local_req).await?;
1229
1230 let local_status = local_resp.status();
1231 let local_content = local_resp.text().await?;
1232 log::debug!("response content: {}", local_content);
1233
1234 if !local_status.is_client_error() && !local_status.is_server_error() {
1235 match serde_json::from_str::<crate::datadogV2::model::ConfluentAccountResponse>(
1236 &local_content,
1237 ) {
1238 Ok(e) => {
1239 return Ok(datadog::ResponseContent {
1240 status: local_status,
1241 content: local_content,
1242 entity: Some(e),
1243 })
1244 }
1245 Err(e) => return Err(datadog::Error::Serde(e)),
1246 };
1247 } else {
1248 let local_entity: Option<UpdateConfluentAccountError> =
1249 serde_json::from_str(&local_content).ok();
1250 let local_error = datadog::ResponseContent {
1251 status: local_status,
1252 content: local_content,
1253 entity: local_entity,
1254 };
1255 Err(datadog::Error::ResponseError(local_error))
1256 }
1257 }
1258
1259 pub async fn update_confluent_resource(
1261 &self,
1262 account_id: String,
1263 resource_id: String,
1264 body: crate::datadogV2::model::ConfluentResourceRequest,
1265 ) -> Result<
1266 crate::datadogV2::model::ConfluentResourceResponse,
1267 datadog::Error<UpdateConfluentResourceError>,
1268 > {
1269 match self
1270 .update_confluent_resource_with_http_info(account_id, resource_id, body)
1271 .await
1272 {
1273 Ok(response_content) => {
1274 if let Some(e) = response_content.entity {
1275 Ok(e)
1276 } else {
1277 Err(datadog::Error::Serde(serde::de::Error::custom(
1278 "response content was None",
1279 )))
1280 }
1281 }
1282 Err(err) => Err(err),
1283 }
1284 }
1285
1286 pub async fn update_confluent_resource_with_http_info(
1288 &self,
1289 account_id: String,
1290 resource_id: String,
1291 body: crate::datadogV2::model::ConfluentResourceRequest,
1292 ) -> Result<
1293 datadog::ResponseContent<crate::datadogV2::model::ConfluentResourceResponse>,
1294 datadog::Error<UpdateConfluentResourceError>,
1295 > {
1296 let local_configuration = &self.config;
1297 let operation_id = "v2.update_confluent_resource";
1298
1299 let local_client = &self.client;
1300
1301 let local_uri_str = format!(
1302 "{}/api/v2/integrations/confluent-cloud/accounts/{account_id}/resources/{resource_id}",
1303 local_configuration.get_operation_host(operation_id),
1304 account_id = datadog::urlencode(account_id),
1305 resource_id = datadog::urlencode(resource_id)
1306 );
1307 let mut local_req_builder =
1308 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1309
1310 let mut headers = HeaderMap::new();
1312 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1313 headers.insert("Accept", HeaderValue::from_static("application/json"));
1314
1315 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1317 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1318 Err(e) => {
1319 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1320 headers.insert(
1321 reqwest::header::USER_AGENT,
1322 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1323 )
1324 }
1325 };
1326
1327 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1329 headers.insert(
1330 "DD-API-KEY",
1331 HeaderValue::from_str(local_key.key.as_str())
1332 .expect("failed to parse DD-API-KEY header"),
1333 );
1334 };
1335 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1336 headers.insert(
1337 "DD-APPLICATION-KEY",
1338 HeaderValue::from_str(local_key.key.as_str())
1339 .expect("failed to parse DD-APPLICATION-KEY header"),
1340 );
1341 };
1342
1343 let output = Vec::new();
1345 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1346 if body.serialize(&mut ser).is_ok() {
1347 if let Some(content_encoding) = headers.get("Content-Encoding") {
1348 match content_encoding.to_str().unwrap_or_default() {
1349 "gzip" => {
1350 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1351 let _ = enc.write_all(ser.into_inner().as_slice());
1352 match enc.finish() {
1353 Ok(buf) => {
1354 local_req_builder = local_req_builder.body(buf);
1355 }
1356 Err(e) => return Err(datadog::Error::Io(e)),
1357 }
1358 }
1359 "deflate" => {
1360 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1361 let _ = enc.write_all(ser.into_inner().as_slice());
1362 match enc.finish() {
1363 Ok(buf) => {
1364 local_req_builder = local_req_builder.body(buf);
1365 }
1366 Err(e) => return Err(datadog::Error::Io(e)),
1367 }
1368 }
1369 "zstd1" => {
1370 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1371 let _ = enc.write_all(ser.into_inner().as_slice());
1372 match enc.finish() {
1373 Ok(buf) => {
1374 local_req_builder = local_req_builder.body(buf);
1375 }
1376 Err(e) => return Err(datadog::Error::Io(e)),
1377 }
1378 }
1379 _ => {
1380 local_req_builder = local_req_builder.body(ser.into_inner());
1381 }
1382 }
1383 } else {
1384 local_req_builder = local_req_builder.body(ser.into_inner());
1385 }
1386 }
1387
1388 local_req_builder = local_req_builder.headers(headers);
1389 let local_req = local_req_builder.build()?;
1390 log::debug!("request content: {:?}", local_req.body());
1391 let local_resp = local_client.execute(local_req).await?;
1392
1393 let local_status = local_resp.status();
1394 let local_content = local_resp.text().await?;
1395 log::debug!("response content: {}", local_content);
1396
1397 if !local_status.is_client_error() && !local_status.is_server_error() {
1398 match serde_json::from_str::<crate::datadogV2::model::ConfluentResourceResponse>(
1399 &local_content,
1400 ) {
1401 Ok(e) => {
1402 return Ok(datadog::ResponseContent {
1403 status: local_status,
1404 content: local_content,
1405 entity: Some(e),
1406 })
1407 }
1408 Err(e) => return Err(datadog::Error::Serde(e)),
1409 };
1410 } else {
1411 let local_entity: Option<UpdateConfluentResourceError> =
1412 serde_json::from_str(&local_content).ok();
1413 let local_error = datadog::ResponseContent {
1414 status: local_status,
1415 content: local_content,
1416 entity: local_entity,
1417 };
1418 Err(datadog::Error::ResponseError(local_error))
1419 }
1420 }
1421}