datadog_api_client/datadogV2/model/
model_entity_v3_integrations.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 serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// A base schema for defining third-party integrations.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EntityV3Integrations {
14    /// An Opsgenie integration schema.
15    #[serde(rename = "opsgenie")]
16    pub opsgenie: Option<crate::datadogV2::model::EntityV3DatadogIntegrationOpsgenie>,
17    /// A PagerDuty integration schema.
18    #[serde(rename = "pagerduty")]
19    pub pagerduty: Option<crate::datadogV2::model::EntityV3DatadogIntegrationPagerduty>,
20    #[serde(skip)]
21    #[serde(default)]
22    pub(crate) _unparsed: bool,
23}
24
25impl EntityV3Integrations {
26    pub fn new() -> EntityV3Integrations {
27        EntityV3Integrations {
28            opsgenie: None,
29            pagerduty: None,
30            _unparsed: false,
31        }
32    }
33
34    pub fn opsgenie(
35        mut self,
36        value: crate::datadogV2::model::EntityV3DatadogIntegrationOpsgenie,
37    ) -> Self {
38        self.opsgenie = Some(value);
39        self
40    }
41
42    pub fn pagerduty(
43        mut self,
44        value: crate::datadogV2::model::EntityV3DatadogIntegrationPagerduty,
45    ) -> Self {
46        self.pagerduty = Some(value);
47        self
48    }
49}
50
51impl Default for EntityV3Integrations {
52    fn default() -> Self {
53        Self::new()
54    }
55}
56
57impl<'de> Deserialize<'de> for EntityV3Integrations {
58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
59    where
60        D: Deserializer<'de>,
61    {
62        struct EntityV3IntegrationsVisitor;
63        impl<'a> Visitor<'a> for EntityV3IntegrationsVisitor {
64            type Value = EntityV3Integrations;
65
66            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
67                f.write_str("a mapping")
68            }
69
70            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
71            where
72                M: MapAccess<'a>,
73            {
74                let mut opsgenie: Option<
75                    crate::datadogV2::model::EntityV3DatadogIntegrationOpsgenie,
76                > = None;
77                let mut pagerduty: Option<
78                    crate::datadogV2::model::EntityV3DatadogIntegrationPagerduty,
79                > = None;
80                let mut _unparsed = false;
81
82                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83                    match k.as_str() {
84                        "opsgenie" => {
85                            if v.is_null() {
86                                continue;
87                            }
88                            opsgenie = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        "pagerduty" => {
91                            if v.is_null() {
92                                continue;
93                            }
94                            pagerduty = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
95                        }
96                        &_ => {
97                            return Err(serde::de::Error::custom(
98                                "Additional properties not allowed",
99                            ));
100                        }
101                    }
102                }
103
104                let content = EntityV3Integrations {
105                    opsgenie,
106                    pagerduty,
107                    _unparsed,
108                };
109
110                Ok(content)
111            }
112        }
113
114        deserializer.deserialize_any(EntityV3IntegrationsVisitor)
115    }
116}