datadog_api_client/datadogV2/model/
model_github_webhook_trigger_wrapper.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/// Schema for a GitHub webhook-based trigger.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct GithubWebhookTriggerWrapper {
14    /// Trigger a workflow from a GitHub webhook. To trigger a workflow from GitHub, you must set a `webhookSecret`. In your GitHub Webhook Settings, set the Payload URL to "base_url"/api/v2/workflows/"workflow_id"/webhook?orgId="org_id", select application/json for the content type, and be highly recommend enabling SSL verification for security. The workflow must be published.
15    #[serde(rename = "githubWebhookTrigger")]
16    pub github_webhook_trigger: crate::datadogV2::model::GithubWebhookTrigger,
17    /// A list of steps that run first after a trigger fires.
18    #[serde(rename = "startStepNames")]
19    pub start_step_names: Option<Vec<String>>,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl GithubWebhookTriggerWrapper {
28    pub fn new(
29        github_webhook_trigger: crate::datadogV2::model::GithubWebhookTrigger,
30    ) -> GithubWebhookTriggerWrapper {
31        GithubWebhookTriggerWrapper {
32            github_webhook_trigger,
33            start_step_names: None,
34            additional_properties: std::collections::BTreeMap::new(),
35            _unparsed: false,
36        }
37    }
38
39    pub fn start_step_names(mut self, value: Vec<String>) -> Self {
40        self.start_step_names = Some(value);
41        self
42    }
43
44    pub fn additional_properties(
45        mut self,
46        value: std::collections::BTreeMap<String, serde_json::Value>,
47    ) -> Self {
48        self.additional_properties = value;
49        self
50    }
51}
52
53impl<'de> Deserialize<'de> for GithubWebhookTriggerWrapper {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55    where
56        D: Deserializer<'de>,
57    {
58        struct GithubWebhookTriggerWrapperVisitor;
59        impl<'a> Visitor<'a> for GithubWebhookTriggerWrapperVisitor {
60            type Value = GithubWebhookTriggerWrapper;
61
62            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
63                f.write_str("a mapping")
64            }
65
66            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
67            where
68                M: MapAccess<'a>,
69            {
70                let mut github_webhook_trigger: Option<
71                    crate::datadogV2::model::GithubWebhookTrigger,
72                > = None;
73                let mut start_step_names: Option<Vec<String>> = None;
74                let mut additional_properties: std::collections::BTreeMap<
75                    String,
76                    serde_json::Value,
77                > = std::collections::BTreeMap::new();
78                let mut _unparsed = false;
79
80                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
81                    match k.as_str() {
82                        "githubWebhookTrigger" => {
83                            github_webhook_trigger =
84                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85                        }
86                        "startStepNames" => {
87                            if v.is_null() {
88                                continue;
89                            }
90                            start_step_names =
91                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
92                        }
93                        &_ => {
94                            if let Ok(value) = serde_json::from_value(v.clone()) {
95                                additional_properties.insert(k, value);
96                            }
97                        }
98                    }
99                }
100                let github_webhook_trigger = github_webhook_trigger
101                    .ok_or_else(|| M::Error::missing_field("github_webhook_trigger"))?;
102
103                let content = GithubWebhookTriggerWrapper {
104                    github_webhook_trigger,
105                    start_step_names,
106                    additional_properties,
107                    _unparsed,
108                };
109
110                Ok(content)
111            }
112        }
113
114        deserializer.deserialize_any(GithubWebhookTriggerWrapperVisitor)
115    }
116}