datadog_api_client/datadogV2/model/
model_trigger_source.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.
4
5use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum TriggerSource {
10    SECURITY_FINDINGS,
11    SECURITY_SIGNALS,
12    UnparsedObject(crate::datadog::UnparsedObject),
13}
14
15impl ToString for TriggerSource {
16    fn to_string(&self) -> String {
17        match self {
18            Self::SECURITY_FINDINGS => String::from("security_findings"),
19            Self::SECURITY_SIGNALS => String::from("security_signals"),
20            Self::UnparsedObject(v) => v.value.to_string(),
21        }
22    }
23}
24
25impl Serialize for TriggerSource {
26    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
27    where
28        S: Serializer,
29    {
30        match self {
31            Self::UnparsedObject(v) => v.serialize(serializer),
32            _ => serializer.serialize_str(self.to_string().as_str()),
33        }
34    }
35}
36
37impl<'de> Deserialize<'de> for TriggerSource {
38    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
39    where
40        D: Deserializer<'de>,
41    {
42        let s: String = String::deserialize(deserializer)?;
43        Ok(match s.as_str() {
44            "security_findings" => Self::SECURITY_FINDINGS,
45            "security_signals" => Self::SECURITY_SIGNALS,
46            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
47                value: serde_json::Value::String(s.into()),
48            }),
49        })
50    }
51}