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#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct MakeGCPSTSDelegateOptionalParams {
17 pub body: Option<std::collections::BTreeMap<String, serde_json::Value>>,
19}
20
21impl MakeGCPSTSDelegateOptionalParams {
22 pub fn body(mut self, value: std::collections::BTreeMap<String, serde_json::Value>) -> Self {
24 self.body = Some(value);
25 self
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateGCPSTSAccountError {
33 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteGCPSTSAccountError {
41 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetGCPSTSDelegateError {
49 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListGCPSTSAccountsError {
57 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum MakeGCPSTSDelegateError {
65 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum UpdateGCPSTSAccountError {
73 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone)]
80pub struct GCPIntegrationAPI {
81 config: datadog::Configuration,
82 client: reqwest_middleware::ClientWithMiddleware,
83}
84
85impl Default for GCPIntegrationAPI {
86 fn default() -> Self {
87 Self::with_config(datadog::Configuration::default())
88 }
89}
90
91impl GCPIntegrationAPI {
92 pub fn new() -> Self {
93 Self::default()
94 }
95 pub fn with_config(config: datadog::Configuration) -> Self {
96 let mut reqwest_client_builder = reqwest::Client::builder();
97
98 if let Some(proxy_url) = &config.proxy_url {
99 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
100 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
101 }
102
103 let mut middleware_client_builder =
104 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
105
106 if config.enable_retry {
107 struct RetryableStatus;
108 impl reqwest_retry::RetryableStrategy for RetryableStatus {
109 fn handle(
110 &self,
111 res: &Result<reqwest::Response, reqwest_middleware::Error>,
112 ) -> Option<reqwest_retry::Retryable> {
113 match res {
114 Ok(success) => reqwest_retry::default_on_request_success(success),
115 Err(_) => None,
116 }
117 }
118 }
119 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
120 .build_with_max_retries(config.max_retries);
121
122 let retry_middleware =
123 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
124 backoff_policy,
125 RetryableStatus,
126 );
127
128 middleware_client_builder = middleware_client_builder.with(retry_middleware);
129 }
130
131 let client = middleware_client_builder.build();
132
133 Self { config, client }
134 }
135
136 pub fn with_client_and_config(
137 config: datadog::Configuration,
138 client: reqwest_middleware::ClientWithMiddleware,
139 ) -> Self {
140 Self { config, client }
141 }
142
143 pub async fn create_gcpsts_account(
145 &self,
146 body: crate::datadogV2::model::GCPSTSServiceAccountCreateRequest,
147 ) -> Result<
148 crate::datadogV2::model::GCPSTSServiceAccountResponse,
149 datadog::Error<CreateGCPSTSAccountError>,
150 > {
151 match self.create_gcpsts_account_with_http_info(body).await {
152 Ok(response_content) => {
153 if let Some(e) = response_content.entity {
154 Ok(e)
155 } else {
156 Err(datadog::Error::Serde(serde::de::Error::custom(
157 "response content was None",
158 )))
159 }
160 }
161 Err(err) => Err(err),
162 }
163 }
164
165 pub async fn create_gcpsts_account_with_http_info(
167 &self,
168 body: crate::datadogV2::model::GCPSTSServiceAccountCreateRequest,
169 ) -> Result<
170 datadog::ResponseContent<crate::datadogV2::model::GCPSTSServiceAccountResponse>,
171 datadog::Error<CreateGCPSTSAccountError>,
172 > {
173 let local_configuration = &self.config;
174 let operation_id = "v2.create_gcpsts_account";
175
176 let local_client = &self.client;
177
178 let local_uri_str = format!(
179 "{}/api/v2/integration/gcp/accounts",
180 local_configuration.get_operation_host(operation_id)
181 );
182 let mut local_req_builder =
183 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
184
185 let mut headers = HeaderMap::new();
187 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
188 headers.insert("Accept", HeaderValue::from_static("application/json"));
189
190 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
192 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
193 Err(e) => {
194 log::warn!("Failed to parse user agent header: {e}, falling back to default");
195 headers.insert(
196 reqwest::header::USER_AGENT,
197 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
198 )
199 }
200 };
201
202 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
204 headers.insert(
205 "DD-API-KEY",
206 HeaderValue::from_str(local_key.key.as_str())
207 .expect("failed to parse DD-API-KEY header"),
208 );
209 };
210 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
211 headers.insert(
212 "DD-APPLICATION-KEY",
213 HeaderValue::from_str(local_key.key.as_str())
214 .expect("failed to parse DD-APPLICATION-KEY header"),
215 );
216 };
217
218 let output = Vec::new();
220 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
221 if body.serialize(&mut ser).is_ok() {
222 if let Some(content_encoding) = headers.get("Content-Encoding") {
223 match content_encoding.to_str().unwrap_or_default() {
224 "gzip" => {
225 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
226 let _ = enc.write_all(ser.into_inner().as_slice());
227 match enc.finish() {
228 Ok(buf) => {
229 local_req_builder = local_req_builder.body(buf);
230 }
231 Err(e) => return Err(datadog::Error::Io(e)),
232 }
233 }
234 "deflate" => {
235 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
236 let _ = enc.write_all(ser.into_inner().as_slice());
237 match enc.finish() {
238 Ok(buf) => {
239 local_req_builder = local_req_builder.body(buf);
240 }
241 Err(e) => return Err(datadog::Error::Io(e)),
242 }
243 }
244 "zstd1" => {
245 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
246 let _ = enc.write_all(ser.into_inner().as_slice());
247 match enc.finish() {
248 Ok(buf) => {
249 local_req_builder = local_req_builder.body(buf);
250 }
251 Err(e) => return Err(datadog::Error::Io(e)),
252 }
253 }
254 _ => {
255 local_req_builder = local_req_builder.body(ser.into_inner());
256 }
257 }
258 } else {
259 local_req_builder = local_req_builder.body(ser.into_inner());
260 }
261 }
262
263 local_req_builder = local_req_builder.headers(headers);
264 let local_req = local_req_builder.build()?;
265 log::debug!("request content: {:?}", local_req.body());
266 let local_resp = local_client.execute(local_req).await?;
267
268 let local_status = local_resp.status();
269 let local_content = local_resp.text().await?;
270 log::debug!("response content: {}", local_content);
271
272 if !local_status.is_client_error() && !local_status.is_server_error() {
273 match serde_json::from_str::<crate::datadogV2::model::GCPSTSServiceAccountResponse>(
274 &local_content,
275 ) {
276 Ok(e) => {
277 return Ok(datadog::ResponseContent {
278 status: local_status,
279 content: local_content,
280 entity: Some(e),
281 })
282 }
283 Err(e) => return Err(datadog::Error::Serde(e)),
284 };
285 } else {
286 let local_entity: Option<CreateGCPSTSAccountError> =
287 serde_json::from_str(&local_content).ok();
288 let local_error = datadog::ResponseContent {
289 status: local_status,
290 content: local_content,
291 entity: local_entity,
292 };
293 Err(datadog::Error::ResponseError(local_error))
294 }
295 }
296
297 pub async fn delete_gcpsts_account(
299 &self,
300 account_id: String,
301 ) -> Result<(), datadog::Error<DeleteGCPSTSAccountError>> {
302 match self.delete_gcpsts_account_with_http_info(account_id).await {
303 Ok(_) => Ok(()),
304 Err(err) => Err(err),
305 }
306 }
307
308 pub async fn delete_gcpsts_account_with_http_info(
310 &self,
311 account_id: String,
312 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteGCPSTSAccountError>> {
313 let local_configuration = &self.config;
314 let operation_id = "v2.delete_gcpsts_account";
315
316 let local_client = &self.client;
317
318 let local_uri_str = format!(
319 "{}/api/v2/integration/gcp/accounts/{account_id}",
320 local_configuration.get_operation_host(operation_id),
321 account_id = datadog::urlencode(account_id)
322 );
323 let mut local_req_builder =
324 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
325
326 let mut headers = HeaderMap::new();
328 headers.insert("Accept", HeaderValue::from_static("*/*"));
329
330 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
332 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
333 Err(e) => {
334 log::warn!("Failed to parse user agent header: {e}, falling back to default");
335 headers.insert(
336 reqwest::header::USER_AGENT,
337 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
338 )
339 }
340 };
341
342 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
344 headers.insert(
345 "DD-API-KEY",
346 HeaderValue::from_str(local_key.key.as_str())
347 .expect("failed to parse DD-API-KEY header"),
348 );
349 };
350 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
351 headers.insert(
352 "DD-APPLICATION-KEY",
353 HeaderValue::from_str(local_key.key.as_str())
354 .expect("failed to parse DD-APPLICATION-KEY header"),
355 );
356 };
357
358 local_req_builder = local_req_builder.headers(headers);
359 let local_req = local_req_builder.build()?;
360 log::debug!("request content: {:?}", local_req.body());
361 let local_resp = local_client.execute(local_req).await?;
362
363 let local_status = local_resp.status();
364 let local_content = local_resp.text().await?;
365 log::debug!("response content: {}", local_content);
366
367 if !local_status.is_client_error() && !local_status.is_server_error() {
368 Ok(datadog::ResponseContent {
369 status: local_status,
370 content: local_content,
371 entity: None,
372 })
373 } else {
374 let local_entity: Option<DeleteGCPSTSAccountError> =
375 serde_json::from_str(&local_content).ok();
376 let local_error = datadog::ResponseContent {
377 status: local_status,
378 content: local_content,
379 entity: local_entity,
380 };
381 Err(datadog::Error::ResponseError(local_error))
382 }
383 }
384
385 pub async fn get_gcpsts_delegate(
387 &self,
388 ) -> Result<
389 crate::datadogV2::model::GCPSTSDelegateAccountResponse,
390 datadog::Error<GetGCPSTSDelegateError>,
391 > {
392 match self.get_gcpsts_delegate_with_http_info().await {
393 Ok(response_content) => {
394 if let Some(e) = response_content.entity {
395 Ok(e)
396 } else {
397 Err(datadog::Error::Serde(serde::de::Error::custom(
398 "response content was None",
399 )))
400 }
401 }
402 Err(err) => Err(err),
403 }
404 }
405
406 pub async fn get_gcpsts_delegate_with_http_info(
408 &self,
409 ) -> Result<
410 datadog::ResponseContent<crate::datadogV2::model::GCPSTSDelegateAccountResponse>,
411 datadog::Error<GetGCPSTSDelegateError>,
412 > {
413 let local_configuration = &self.config;
414 let operation_id = "v2.get_gcpsts_delegate";
415
416 let local_client = &self.client;
417
418 let local_uri_str = format!(
419 "{}/api/v2/integration/gcp/sts_delegate",
420 local_configuration.get_operation_host(operation_id)
421 );
422 let mut local_req_builder =
423 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
424
425 let mut headers = HeaderMap::new();
427 headers.insert("Accept", HeaderValue::from_static("application/json"));
428
429 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
431 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
432 Err(e) => {
433 log::warn!("Failed to parse user agent header: {e}, falling back to default");
434 headers.insert(
435 reqwest::header::USER_AGENT,
436 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
437 )
438 }
439 };
440
441 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
443 headers.insert(
444 "DD-API-KEY",
445 HeaderValue::from_str(local_key.key.as_str())
446 .expect("failed to parse DD-API-KEY header"),
447 );
448 };
449 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
450 headers.insert(
451 "DD-APPLICATION-KEY",
452 HeaderValue::from_str(local_key.key.as_str())
453 .expect("failed to parse DD-APPLICATION-KEY header"),
454 );
455 };
456
457 local_req_builder = local_req_builder.headers(headers);
458 let local_req = local_req_builder.build()?;
459 log::debug!("request content: {:?}", local_req.body());
460 let local_resp = local_client.execute(local_req).await?;
461
462 let local_status = local_resp.status();
463 let local_content = local_resp.text().await?;
464 log::debug!("response content: {}", local_content);
465
466 if !local_status.is_client_error() && !local_status.is_server_error() {
467 match serde_json::from_str::<crate::datadogV2::model::GCPSTSDelegateAccountResponse>(
468 &local_content,
469 ) {
470 Ok(e) => {
471 return Ok(datadog::ResponseContent {
472 status: local_status,
473 content: local_content,
474 entity: Some(e),
475 })
476 }
477 Err(e) => return Err(datadog::Error::Serde(e)),
478 };
479 } else {
480 let local_entity: Option<GetGCPSTSDelegateError> =
481 serde_json::from_str(&local_content).ok();
482 let local_error = datadog::ResponseContent {
483 status: local_status,
484 content: local_content,
485 entity: local_entity,
486 };
487 Err(datadog::Error::ResponseError(local_error))
488 }
489 }
490
491 pub async fn list_gcpsts_accounts(
493 &self,
494 ) -> Result<
495 crate::datadogV2::model::GCPSTSServiceAccountsResponse,
496 datadog::Error<ListGCPSTSAccountsError>,
497 > {
498 match self.list_gcpsts_accounts_with_http_info().await {
499 Ok(response_content) => {
500 if let Some(e) = response_content.entity {
501 Ok(e)
502 } else {
503 Err(datadog::Error::Serde(serde::de::Error::custom(
504 "response content was None",
505 )))
506 }
507 }
508 Err(err) => Err(err),
509 }
510 }
511
512 pub async fn list_gcpsts_accounts_with_http_info(
514 &self,
515 ) -> Result<
516 datadog::ResponseContent<crate::datadogV2::model::GCPSTSServiceAccountsResponse>,
517 datadog::Error<ListGCPSTSAccountsError>,
518 > {
519 let local_configuration = &self.config;
520 let operation_id = "v2.list_gcpsts_accounts";
521
522 let local_client = &self.client;
523
524 let local_uri_str = format!(
525 "{}/api/v2/integration/gcp/accounts",
526 local_configuration.get_operation_host(operation_id)
527 );
528 let mut local_req_builder =
529 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
530
531 let mut headers = HeaderMap::new();
533 headers.insert("Accept", HeaderValue::from_static("application/json"));
534
535 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
537 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
538 Err(e) => {
539 log::warn!("Failed to parse user agent header: {e}, falling back to default");
540 headers.insert(
541 reqwest::header::USER_AGENT,
542 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
543 )
544 }
545 };
546
547 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
549 headers.insert(
550 "DD-API-KEY",
551 HeaderValue::from_str(local_key.key.as_str())
552 .expect("failed to parse DD-API-KEY header"),
553 );
554 };
555 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
556 headers.insert(
557 "DD-APPLICATION-KEY",
558 HeaderValue::from_str(local_key.key.as_str())
559 .expect("failed to parse DD-APPLICATION-KEY header"),
560 );
561 };
562
563 local_req_builder = local_req_builder.headers(headers);
564 let local_req = local_req_builder.build()?;
565 log::debug!("request content: {:?}", local_req.body());
566 let local_resp = local_client.execute(local_req).await?;
567
568 let local_status = local_resp.status();
569 let local_content = local_resp.text().await?;
570 log::debug!("response content: {}", local_content);
571
572 if !local_status.is_client_error() && !local_status.is_server_error() {
573 match serde_json::from_str::<crate::datadogV2::model::GCPSTSServiceAccountsResponse>(
574 &local_content,
575 ) {
576 Ok(e) => {
577 return Ok(datadog::ResponseContent {
578 status: local_status,
579 content: local_content,
580 entity: Some(e),
581 })
582 }
583 Err(e) => return Err(datadog::Error::Serde(e)),
584 };
585 } else {
586 let local_entity: Option<ListGCPSTSAccountsError> =
587 serde_json::from_str(&local_content).ok();
588 let local_error = datadog::ResponseContent {
589 status: local_status,
590 content: local_content,
591 entity: local_entity,
592 };
593 Err(datadog::Error::ResponseError(local_error))
594 }
595 }
596
597 pub async fn make_gcpsts_delegate(
599 &self,
600 params: MakeGCPSTSDelegateOptionalParams,
601 ) -> Result<
602 crate::datadogV2::model::GCPSTSDelegateAccountResponse,
603 datadog::Error<MakeGCPSTSDelegateError>,
604 > {
605 match self.make_gcpsts_delegate_with_http_info(params).await {
606 Ok(response_content) => {
607 if let Some(e) = response_content.entity {
608 Ok(e)
609 } else {
610 Err(datadog::Error::Serde(serde::de::Error::custom(
611 "response content was None",
612 )))
613 }
614 }
615 Err(err) => Err(err),
616 }
617 }
618
619 pub async fn make_gcpsts_delegate_with_http_info(
621 &self,
622 params: MakeGCPSTSDelegateOptionalParams,
623 ) -> Result<
624 datadog::ResponseContent<crate::datadogV2::model::GCPSTSDelegateAccountResponse>,
625 datadog::Error<MakeGCPSTSDelegateError>,
626 > {
627 let local_configuration = &self.config;
628 let operation_id = "v2.make_gcpsts_delegate";
629
630 let body = params.body;
632
633 let local_client = &self.client;
634
635 let local_uri_str = format!(
636 "{}/api/v2/integration/gcp/sts_delegate",
637 local_configuration.get_operation_host(operation_id)
638 );
639 let mut local_req_builder =
640 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
641
642 let mut headers = HeaderMap::new();
644 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
645 headers.insert("Accept", HeaderValue::from_static("application/json"));
646
647 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
649 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
650 Err(e) => {
651 log::warn!("Failed to parse user agent header: {e}, falling back to default");
652 headers.insert(
653 reqwest::header::USER_AGENT,
654 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
655 )
656 }
657 };
658
659 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
661 headers.insert(
662 "DD-API-KEY",
663 HeaderValue::from_str(local_key.key.as_str())
664 .expect("failed to parse DD-API-KEY header"),
665 );
666 };
667 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
668 headers.insert(
669 "DD-APPLICATION-KEY",
670 HeaderValue::from_str(local_key.key.as_str())
671 .expect("failed to parse DD-APPLICATION-KEY header"),
672 );
673 };
674
675 let output = Vec::new();
677 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
678 if body.serialize(&mut ser).is_ok() {
679 if let Some(content_encoding) = headers.get("Content-Encoding") {
680 match content_encoding.to_str().unwrap_or_default() {
681 "gzip" => {
682 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
683 let _ = enc.write_all(ser.into_inner().as_slice());
684 match enc.finish() {
685 Ok(buf) => {
686 local_req_builder = local_req_builder.body(buf);
687 }
688 Err(e) => return Err(datadog::Error::Io(e)),
689 }
690 }
691 "deflate" => {
692 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
693 let _ = enc.write_all(ser.into_inner().as_slice());
694 match enc.finish() {
695 Ok(buf) => {
696 local_req_builder = local_req_builder.body(buf);
697 }
698 Err(e) => return Err(datadog::Error::Io(e)),
699 }
700 }
701 "zstd1" => {
702 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
703 let _ = enc.write_all(ser.into_inner().as_slice());
704 match enc.finish() {
705 Ok(buf) => {
706 local_req_builder = local_req_builder.body(buf);
707 }
708 Err(e) => return Err(datadog::Error::Io(e)),
709 }
710 }
711 _ => {
712 local_req_builder = local_req_builder.body(ser.into_inner());
713 }
714 }
715 } else {
716 local_req_builder = local_req_builder.body(ser.into_inner());
717 }
718 }
719
720 local_req_builder = local_req_builder.headers(headers);
721 let local_req = local_req_builder.build()?;
722 log::debug!("request content: {:?}", local_req.body());
723 let local_resp = local_client.execute(local_req).await?;
724
725 let local_status = local_resp.status();
726 let local_content = local_resp.text().await?;
727 log::debug!("response content: {}", local_content);
728
729 if !local_status.is_client_error() && !local_status.is_server_error() {
730 match serde_json::from_str::<crate::datadogV2::model::GCPSTSDelegateAccountResponse>(
731 &local_content,
732 ) {
733 Ok(e) => {
734 return Ok(datadog::ResponseContent {
735 status: local_status,
736 content: local_content,
737 entity: Some(e),
738 })
739 }
740 Err(e) => return Err(datadog::Error::Serde(e)),
741 };
742 } else {
743 let local_entity: Option<MakeGCPSTSDelegateError> =
744 serde_json::from_str(&local_content).ok();
745 let local_error = datadog::ResponseContent {
746 status: local_status,
747 content: local_content,
748 entity: local_entity,
749 };
750 Err(datadog::Error::ResponseError(local_error))
751 }
752 }
753
754 pub async fn update_gcpsts_account(
756 &self,
757 account_id: String,
758 body: crate::datadogV2::model::GCPSTSServiceAccountUpdateRequest,
759 ) -> Result<
760 crate::datadogV2::model::GCPSTSServiceAccountResponse,
761 datadog::Error<UpdateGCPSTSAccountError>,
762 > {
763 match self
764 .update_gcpsts_account_with_http_info(account_id, body)
765 .await
766 {
767 Ok(response_content) => {
768 if let Some(e) = response_content.entity {
769 Ok(e)
770 } else {
771 Err(datadog::Error::Serde(serde::de::Error::custom(
772 "response content was None",
773 )))
774 }
775 }
776 Err(err) => Err(err),
777 }
778 }
779
780 pub async fn update_gcpsts_account_with_http_info(
782 &self,
783 account_id: String,
784 body: crate::datadogV2::model::GCPSTSServiceAccountUpdateRequest,
785 ) -> Result<
786 datadog::ResponseContent<crate::datadogV2::model::GCPSTSServiceAccountResponse>,
787 datadog::Error<UpdateGCPSTSAccountError>,
788 > {
789 let local_configuration = &self.config;
790 let operation_id = "v2.update_gcpsts_account";
791
792 let local_client = &self.client;
793
794 let local_uri_str = format!(
795 "{}/api/v2/integration/gcp/accounts/{account_id}",
796 local_configuration.get_operation_host(operation_id),
797 account_id = datadog::urlencode(account_id)
798 );
799 let mut local_req_builder =
800 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
801
802 let mut headers = HeaderMap::new();
804 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
805 headers.insert("Accept", HeaderValue::from_static("application/json"));
806
807 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
809 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
810 Err(e) => {
811 log::warn!("Failed to parse user agent header: {e}, falling back to default");
812 headers.insert(
813 reqwest::header::USER_AGENT,
814 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
815 )
816 }
817 };
818
819 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
821 headers.insert(
822 "DD-API-KEY",
823 HeaderValue::from_str(local_key.key.as_str())
824 .expect("failed to parse DD-API-KEY header"),
825 );
826 };
827 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
828 headers.insert(
829 "DD-APPLICATION-KEY",
830 HeaderValue::from_str(local_key.key.as_str())
831 .expect("failed to parse DD-APPLICATION-KEY header"),
832 );
833 };
834
835 let output = Vec::new();
837 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
838 if body.serialize(&mut ser).is_ok() {
839 if let Some(content_encoding) = headers.get("Content-Encoding") {
840 match content_encoding.to_str().unwrap_or_default() {
841 "gzip" => {
842 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
843 let _ = enc.write_all(ser.into_inner().as_slice());
844 match enc.finish() {
845 Ok(buf) => {
846 local_req_builder = local_req_builder.body(buf);
847 }
848 Err(e) => return Err(datadog::Error::Io(e)),
849 }
850 }
851 "deflate" => {
852 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
853 let _ = enc.write_all(ser.into_inner().as_slice());
854 match enc.finish() {
855 Ok(buf) => {
856 local_req_builder = local_req_builder.body(buf);
857 }
858 Err(e) => return Err(datadog::Error::Io(e)),
859 }
860 }
861 "zstd1" => {
862 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
863 let _ = enc.write_all(ser.into_inner().as_slice());
864 match enc.finish() {
865 Ok(buf) => {
866 local_req_builder = local_req_builder.body(buf);
867 }
868 Err(e) => return Err(datadog::Error::Io(e)),
869 }
870 }
871 _ => {
872 local_req_builder = local_req_builder.body(ser.into_inner());
873 }
874 }
875 } else {
876 local_req_builder = local_req_builder.body(ser.into_inner());
877 }
878 }
879
880 local_req_builder = local_req_builder.headers(headers);
881 let local_req = local_req_builder.build()?;
882 log::debug!("request content: {:?}", local_req.body());
883 let local_resp = local_client.execute(local_req).await?;
884
885 let local_status = local_resp.status();
886 let local_content = local_resp.text().await?;
887 log::debug!("response content: {}", local_content);
888
889 if !local_status.is_client_error() && !local_status.is_server_error() {
890 match serde_json::from_str::<crate::datadogV2::model::GCPSTSServiceAccountResponse>(
891 &local_content,
892 ) {
893 Ok(e) => {
894 return Ok(datadog::ResponseContent {
895 status: local_status,
896 content: local_content,
897 entity: Some(e),
898 })
899 }
900 Err(e) => return Err(datadog::Error::Serde(e)),
901 };
902 } else {
903 let local_entity: Option<UpdateGCPSTSAccountError> =
904 serde_json::from_str(&local_content).ok();
905 let local_error = datadog::ResponseContent {
906 status: local_status,
907 content: local_content,
908 entity: local_entity,
909 };
910 Err(datadog::Error::ResponseError(local_error))
911 }
912 }
913}