datadog_api_client/datadogV1/api/
api_gcp_integration.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use 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/// CreateGCPIntegrationError is a struct for typed errors of method [`GCPIntegrationAPI::create_gcp_integration`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateGCPIntegrationError {
17    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// DeleteGCPIntegrationError is a struct for typed errors of method [`GCPIntegrationAPI::delete_gcp_integration`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum DeleteGCPIntegrationError {
25    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// ListGCPIntegrationError is a struct for typed errors of method [`GCPIntegrationAPI::list_gcp_integration`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum ListGCPIntegrationError {
33    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// UpdateGCPIntegrationError is a struct for typed errors of method [`GCPIntegrationAPI::update_gcp_integration`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UpdateGCPIntegrationError {
41    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// Configure your Datadog-Google Cloud Platform (GCP) integration directly
46/// through the Datadog API. Read more about the [Datadog-Google Cloud Platform integration](<https://docs.datadoghq.com/integrations/google_cloud_platform>).
47#[derive(Debug, Clone)]
48pub struct GCPIntegrationAPI {
49    config: datadog::Configuration,
50    client: reqwest_middleware::ClientWithMiddleware,
51}
52
53impl Default for GCPIntegrationAPI {
54    fn default() -> Self {
55        Self::with_config(datadog::Configuration::default())
56    }
57}
58
59impl GCPIntegrationAPI {
60    pub fn new() -> Self {
61        Self::default()
62    }
63    pub fn with_config(config: datadog::Configuration) -> Self {
64        let mut reqwest_client_builder = reqwest::Client::builder();
65
66        if let Some(proxy_url) = &config.proxy_url {
67            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
68            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
69        }
70
71        let mut middleware_client_builder =
72            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
73
74        if config.enable_retry {
75            struct RetryableStatus;
76            impl reqwest_retry::RetryableStrategy for RetryableStatus {
77                fn handle(
78                    &self,
79                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
80                ) -> Option<reqwest_retry::Retryable> {
81                    match res {
82                        Ok(success) => reqwest_retry::default_on_request_success(success),
83                        Err(_) => None,
84                    }
85                }
86            }
87            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
88                .build_with_max_retries(config.max_retries);
89
90            let retry_middleware =
91                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
92                    backoff_policy,
93                    RetryableStatus,
94                );
95
96            middleware_client_builder = middleware_client_builder.with(retry_middleware);
97        }
98
99        let client = middleware_client_builder.build();
100
101        Self { config, client }
102    }
103
104    pub fn with_client_and_config(
105        config: datadog::Configuration,
106        client: reqwest_middleware::ClientWithMiddleware,
107    ) -> Self {
108        Self { config, client }
109    }
110
111    /// This endpoint is deprecated – use the V2 endpoints instead. Create a Datadog-GCP integration.
112    pub async fn create_gcp_integration(
113        &self,
114        body: crate::datadogV1::model::GCPAccount,
115    ) -> Result<
116        std::collections::BTreeMap<String, serde_json::Value>,
117        datadog::Error<CreateGCPIntegrationError>,
118    > {
119        match self.create_gcp_integration_with_http_info(body).await {
120            Ok(response_content) => {
121                if let Some(e) = response_content.entity {
122                    Ok(e)
123                } else {
124                    Err(datadog::Error::Serde(serde::de::Error::custom(
125                        "response content was None",
126                    )))
127                }
128            }
129            Err(err) => Err(err),
130        }
131    }
132
133    /// This endpoint is deprecated – use the V2 endpoints instead. Create a Datadog-GCP integration.
134    pub async fn create_gcp_integration_with_http_info(
135        &self,
136        body: crate::datadogV1::model::GCPAccount,
137    ) -> Result<
138        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
139        datadog::Error<CreateGCPIntegrationError>,
140    > {
141        let local_configuration = &self.config;
142        let operation_id = "v1.create_gcp_integration";
143
144        let local_client = &self.client;
145
146        let local_uri_str = format!(
147            "{}/api/v1/integration/gcp",
148            local_configuration.get_operation_host(operation_id)
149        );
150        let mut local_req_builder =
151            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
152
153        // build headers
154        let mut headers = HeaderMap::new();
155        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
156        headers.insert("Accept", HeaderValue::from_static("application/json"));
157
158        // build user agent
159        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
160            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
161            Err(e) => {
162                log::warn!("Failed to parse user agent header: {e}, falling back to default");
163                headers.insert(
164                    reqwest::header::USER_AGENT,
165                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
166                )
167            }
168        };
169
170        // build auth
171        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
172            headers.insert(
173                "DD-API-KEY",
174                HeaderValue::from_str(local_key.key.as_str())
175                    .expect("failed to parse DD-API-KEY header"),
176            );
177        };
178        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
179            headers.insert(
180                "DD-APPLICATION-KEY",
181                HeaderValue::from_str(local_key.key.as_str())
182                    .expect("failed to parse DD-APPLICATION-KEY header"),
183            );
184        };
185
186        // build body parameters
187        let output = Vec::new();
188        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
189        if body.serialize(&mut ser).is_ok() {
190            if let Some(content_encoding) = headers.get("Content-Encoding") {
191                match content_encoding.to_str().unwrap_or_default() {
192                    "gzip" => {
193                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
194                        let _ = enc.write_all(ser.into_inner().as_slice());
195                        match enc.finish() {
196                            Ok(buf) => {
197                                local_req_builder = local_req_builder.body(buf);
198                            }
199                            Err(e) => return Err(datadog::Error::Io(e)),
200                        }
201                    }
202                    "deflate" => {
203                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
204                        let _ = enc.write_all(ser.into_inner().as_slice());
205                        match enc.finish() {
206                            Ok(buf) => {
207                                local_req_builder = local_req_builder.body(buf);
208                            }
209                            Err(e) => return Err(datadog::Error::Io(e)),
210                        }
211                    }
212                    "zstd1" => {
213                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
214                        let _ = enc.write_all(ser.into_inner().as_slice());
215                        match enc.finish() {
216                            Ok(buf) => {
217                                local_req_builder = local_req_builder.body(buf);
218                            }
219                            Err(e) => return Err(datadog::Error::Io(e)),
220                        }
221                    }
222                    _ => {
223                        local_req_builder = local_req_builder.body(ser.into_inner());
224                    }
225                }
226            } else {
227                local_req_builder = local_req_builder.body(ser.into_inner());
228            }
229        }
230
231        local_req_builder = local_req_builder.headers(headers);
232        let local_req = local_req_builder.build()?;
233        log::debug!("request content: {:?}", local_req.body());
234        let local_resp = local_client.execute(local_req).await?;
235
236        let local_status = local_resp.status();
237        let local_content = local_resp.text().await?;
238        log::debug!("response content: {}", local_content);
239
240        if !local_status.is_client_error() && !local_status.is_server_error() {
241            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
242                &local_content,
243            ) {
244                Ok(e) => {
245                    return Ok(datadog::ResponseContent {
246                        status: local_status,
247                        content: local_content,
248                        entity: Some(e),
249                    })
250                }
251                Err(e) => return Err(datadog::Error::Serde(e)),
252            };
253        } else {
254            let local_entity: Option<CreateGCPIntegrationError> =
255                serde_json::from_str(&local_content).ok();
256            let local_error = datadog::ResponseContent {
257                status: local_status,
258                content: local_content,
259                entity: local_entity,
260            };
261            Err(datadog::Error::ResponseError(local_error))
262        }
263    }
264
265    /// This endpoint is deprecated – use the V2 endpoints instead. Delete a given Datadog-GCP integration.
266    pub async fn delete_gcp_integration(
267        &self,
268        body: crate::datadogV1::model::GCPAccount,
269    ) -> Result<
270        std::collections::BTreeMap<String, serde_json::Value>,
271        datadog::Error<DeleteGCPIntegrationError>,
272    > {
273        match self.delete_gcp_integration_with_http_info(body).await {
274            Ok(response_content) => {
275                if let Some(e) = response_content.entity {
276                    Ok(e)
277                } else {
278                    Err(datadog::Error::Serde(serde::de::Error::custom(
279                        "response content was None",
280                    )))
281                }
282            }
283            Err(err) => Err(err),
284        }
285    }
286
287    /// This endpoint is deprecated – use the V2 endpoints instead. Delete a given Datadog-GCP integration.
288    pub async fn delete_gcp_integration_with_http_info(
289        &self,
290        body: crate::datadogV1::model::GCPAccount,
291    ) -> Result<
292        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
293        datadog::Error<DeleteGCPIntegrationError>,
294    > {
295        let local_configuration = &self.config;
296        let operation_id = "v1.delete_gcp_integration";
297
298        let local_client = &self.client;
299
300        let local_uri_str = format!(
301            "{}/api/v1/integration/gcp",
302            local_configuration.get_operation_host(operation_id)
303        );
304        let mut local_req_builder =
305            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
306
307        // build headers
308        let mut headers = HeaderMap::new();
309        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
310        headers.insert("Accept", HeaderValue::from_static("application/json"));
311
312        // build user agent
313        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
314            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
315            Err(e) => {
316                log::warn!("Failed to parse user agent header: {e}, falling back to default");
317                headers.insert(
318                    reqwest::header::USER_AGENT,
319                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
320                )
321            }
322        };
323
324        // build auth
325        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
326            headers.insert(
327                "DD-API-KEY",
328                HeaderValue::from_str(local_key.key.as_str())
329                    .expect("failed to parse DD-API-KEY header"),
330            );
331        };
332        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
333            headers.insert(
334                "DD-APPLICATION-KEY",
335                HeaderValue::from_str(local_key.key.as_str())
336                    .expect("failed to parse DD-APPLICATION-KEY header"),
337            );
338        };
339
340        // build body parameters
341        let output = Vec::new();
342        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
343        if body.serialize(&mut ser).is_ok() {
344            if let Some(content_encoding) = headers.get("Content-Encoding") {
345                match content_encoding.to_str().unwrap_or_default() {
346                    "gzip" => {
347                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
348                        let _ = enc.write_all(ser.into_inner().as_slice());
349                        match enc.finish() {
350                            Ok(buf) => {
351                                local_req_builder = local_req_builder.body(buf);
352                            }
353                            Err(e) => return Err(datadog::Error::Io(e)),
354                        }
355                    }
356                    "deflate" => {
357                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
358                        let _ = enc.write_all(ser.into_inner().as_slice());
359                        match enc.finish() {
360                            Ok(buf) => {
361                                local_req_builder = local_req_builder.body(buf);
362                            }
363                            Err(e) => return Err(datadog::Error::Io(e)),
364                        }
365                    }
366                    "zstd1" => {
367                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
368                        let _ = enc.write_all(ser.into_inner().as_slice());
369                        match enc.finish() {
370                            Ok(buf) => {
371                                local_req_builder = local_req_builder.body(buf);
372                            }
373                            Err(e) => return Err(datadog::Error::Io(e)),
374                        }
375                    }
376                    _ => {
377                        local_req_builder = local_req_builder.body(ser.into_inner());
378                    }
379                }
380            } else {
381                local_req_builder = local_req_builder.body(ser.into_inner());
382            }
383        }
384
385        local_req_builder = local_req_builder.headers(headers);
386        let local_req = local_req_builder.build()?;
387        log::debug!("request content: {:?}", local_req.body());
388        let local_resp = local_client.execute(local_req).await?;
389
390        let local_status = local_resp.status();
391        let local_content = local_resp.text().await?;
392        log::debug!("response content: {}", local_content);
393
394        if !local_status.is_client_error() && !local_status.is_server_error() {
395            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
396                &local_content,
397            ) {
398                Ok(e) => {
399                    return Ok(datadog::ResponseContent {
400                        status: local_status,
401                        content: local_content,
402                        entity: Some(e),
403                    })
404                }
405                Err(e) => return Err(datadog::Error::Serde(e)),
406            };
407        } else {
408            let local_entity: Option<DeleteGCPIntegrationError> =
409                serde_json::from_str(&local_content).ok();
410            let local_error = datadog::ResponseContent {
411                status: local_status,
412                content: local_content,
413                entity: local_entity,
414            };
415            Err(datadog::Error::ResponseError(local_error))
416        }
417    }
418
419    /// This endpoint is deprecated – use the V2 endpoints instead. List all Datadog-GCP integrations configured in your Datadog account.
420    pub async fn list_gcp_integration(
421        &self,
422    ) -> Result<Vec<crate::datadogV1::model::GCPAccount>, datadog::Error<ListGCPIntegrationError>>
423    {
424        match self.list_gcp_integration_with_http_info().await {
425            Ok(response_content) => {
426                if let Some(e) = response_content.entity {
427                    Ok(e)
428                } else {
429                    Err(datadog::Error::Serde(serde::de::Error::custom(
430                        "response content was None",
431                    )))
432                }
433            }
434            Err(err) => Err(err),
435        }
436    }
437
438    /// This endpoint is deprecated – use the V2 endpoints instead. List all Datadog-GCP integrations configured in your Datadog account.
439    pub async fn list_gcp_integration_with_http_info(
440        &self,
441    ) -> Result<
442        datadog::ResponseContent<Vec<crate::datadogV1::model::GCPAccount>>,
443        datadog::Error<ListGCPIntegrationError>,
444    > {
445        let local_configuration = &self.config;
446        let operation_id = "v1.list_gcp_integration";
447
448        let local_client = &self.client;
449
450        let local_uri_str = format!(
451            "{}/api/v1/integration/gcp",
452            local_configuration.get_operation_host(operation_id)
453        );
454        let mut local_req_builder =
455            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
456
457        // build headers
458        let mut headers = HeaderMap::new();
459        headers.insert("Accept", HeaderValue::from_static("application/json"));
460
461        // build user agent
462        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
463            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
464            Err(e) => {
465                log::warn!("Failed to parse user agent header: {e}, falling back to default");
466                headers.insert(
467                    reqwest::header::USER_AGENT,
468                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
469                )
470            }
471        };
472
473        // build auth
474        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
475            headers.insert(
476                "DD-API-KEY",
477                HeaderValue::from_str(local_key.key.as_str())
478                    .expect("failed to parse DD-API-KEY header"),
479            );
480        };
481        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
482            headers.insert(
483                "DD-APPLICATION-KEY",
484                HeaderValue::from_str(local_key.key.as_str())
485                    .expect("failed to parse DD-APPLICATION-KEY header"),
486            );
487        };
488
489        local_req_builder = local_req_builder.headers(headers);
490        let local_req = local_req_builder.build()?;
491        log::debug!("request content: {:?}", local_req.body());
492        let local_resp = local_client.execute(local_req).await?;
493
494        let local_status = local_resp.status();
495        let local_content = local_resp.text().await?;
496        log::debug!("response content: {}", local_content);
497
498        if !local_status.is_client_error() && !local_status.is_server_error() {
499            match serde_json::from_str::<Vec<crate::datadogV1::model::GCPAccount>>(&local_content) {
500                Ok(e) => {
501                    return Ok(datadog::ResponseContent {
502                        status: local_status,
503                        content: local_content,
504                        entity: Some(e),
505                    })
506                }
507                Err(e) => return Err(datadog::Error::Serde(e)),
508            };
509        } else {
510            let local_entity: Option<ListGCPIntegrationError> =
511                serde_json::from_str(&local_content).ok();
512            let local_error = datadog::ResponseContent {
513                status: local_status,
514                content: local_content,
515                entity: local_entity,
516            };
517            Err(datadog::Error::ResponseError(local_error))
518        }
519    }
520
521    /// This endpoint is deprecated – use the V2 endpoints instead. Update a Datadog-GCP integrations host_filters and/or auto-mute.
522    /// Requires a `project_id` and `client_email`, however these fields cannot be updated.
523    /// If you need to update these fields, delete and use the create (`POST`) endpoint.
524    /// The unspecified fields will keep their original values.
525    pub async fn update_gcp_integration(
526        &self,
527        body: crate::datadogV1::model::GCPAccount,
528    ) -> Result<
529        std::collections::BTreeMap<String, serde_json::Value>,
530        datadog::Error<UpdateGCPIntegrationError>,
531    > {
532        match self.update_gcp_integration_with_http_info(body).await {
533            Ok(response_content) => {
534                if let Some(e) = response_content.entity {
535                    Ok(e)
536                } else {
537                    Err(datadog::Error::Serde(serde::de::Error::custom(
538                        "response content was None",
539                    )))
540                }
541            }
542            Err(err) => Err(err),
543        }
544    }
545
546    /// This endpoint is deprecated – use the V2 endpoints instead. Update a Datadog-GCP integrations host_filters and/or auto-mute.
547    /// Requires a `project_id` and `client_email`, however these fields cannot be updated.
548    /// If you need to update these fields, delete and use the create (`POST`) endpoint.
549    /// The unspecified fields will keep their original values.
550    pub async fn update_gcp_integration_with_http_info(
551        &self,
552        body: crate::datadogV1::model::GCPAccount,
553    ) -> Result<
554        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
555        datadog::Error<UpdateGCPIntegrationError>,
556    > {
557        let local_configuration = &self.config;
558        let operation_id = "v1.update_gcp_integration";
559
560        let local_client = &self.client;
561
562        let local_uri_str = format!(
563            "{}/api/v1/integration/gcp",
564            local_configuration.get_operation_host(operation_id)
565        );
566        let mut local_req_builder =
567            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
568
569        // build headers
570        let mut headers = HeaderMap::new();
571        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
572        headers.insert("Accept", HeaderValue::from_static("application/json"));
573
574        // build user agent
575        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
576            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
577            Err(e) => {
578                log::warn!("Failed to parse user agent header: {e}, falling back to default");
579                headers.insert(
580                    reqwest::header::USER_AGENT,
581                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
582                )
583            }
584        };
585
586        // build auth
587        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
588            headers.insert(
589                "DD-API-KEY",
590                HeaderValue::from_str(local_key.key.as_str())
591                    .expect("failed to parse DD-API-KEY header"),
592            );
593        };
594        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
595            headers.insert(
596                "DD-APPLICATION-KEY",
597                HeaderValue::from_str(local_key.key.as_str())
598                    .expect("failed to parse DD-APPLICATION-KEY header"),
599            );
600        };
601
602        // build body parameters
603        let output = Vec::new();
604        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
605        if body.serialize(&mut ser).is_ok() {
606            if let Some(content_encoding) = headers.get("Content-Encoding") {
607                match content_encoding.to_str().unwrap_or_default() {
608                    "gzip" => {
609                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
610                        let _ = enc.write_all(ser.into_inner().as_slice());
611                        match enc.finish() {
612                            Ok(buf) => {
613                                local_req_builder = local_req_builder.body(buf);
614                            }
615                            Err(e) => return Err(datadog::Error::Io(e)),
616                        }
617                    }
618                    "deflate" => {
619                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
620                        let _ = enc.write_all(ser.into_inner().as_slice());
621                        match enc.finish() {
622                            Ok(buf) => {
623                                local_req_builder = local_req_builder.body(buf);
624                            }
625                            Err(e) => return Err(datadog::Error::Io(e)),
626                        }
627                    }
628                    "zstd1" => {
629                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
630                        let _ = enc.write_all(ser.into_inner().as_slice());
631                        match enc.finish() {
632                            Ok(buf) => {
633                                local_req_builder = local_req_builder.body(buf);
634                            }
635                            Err(e) => return Err(datadog::Error::Io(e)),
636                        }
637                    }
638                    _ => {
639                        local_req_builder = local_req_builder.body(ser.into_inner());
640                    }
641                }
642            } else {
643                local_req_builder = local_req_builder.body(ser.into_inner());
644            }
645        }
646
647        local_req_builder = local_req_builder.headers(headers);
648        let local_req = local_req_builder.build()?;
649        log::debug!("request content: {:?}", local_req.body());
650        let local_resp = local_client.execute(local_req).await?;
651
652        let local_status = local_resp.status();
653        let local_content = local_resp.text().await?;
654        log::debug!("response content: {}", local_content);
655
656        if !local_status.is_client_error() && !local_status.is_server_error() {
657            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
658                &local_content,
659            ) {
660                Ok(e) => {
661                    return Ok(datadog::ResponseContent {
662                        status: local_status,
663                        content: local_content,
664                        entity: Some(e),
665                    })
666                }
667                Err(e) => return Err(datadog::Error::Serde(e)),
668            };
669        } else {
670            let local_entity: Option<UpdateGCPIntegrationError> =
671                serde_json::from_str(&local_content).ok();
672            let local_error = datadog::ResponseContent {
673                status: local_status,
674                content: local_content,
675                entity: local_entity,
676            };
677            Err(datadog::Error::ResponseError(local_error))
678        }
679    }
680}