tencent_sdk/services/cdn/
update_domain_config.rs

1use crate::{
2    client::{TencentCloudAsync, TencentCloudBlocking},
3    core::{Endpoint, TencentCloudResult},
4};
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7use std::borrow::Cow;
8
9#[derive(Debug, Deserialize)]
10pub struct UpdateDomainConfigResponse {
11    #[serde(rename = "Response")]
12    pub response: UpdateDomainConfigResult,
13}
14
15#[derive(Debug, Deserialize)]
16pub struct UpdateDomainConfigResult {
17    #[serde(rename = "RequestId")]
18    pub request_id: String,
19}
20
21#[derive(Serialize)]
22pub struct CertInfo<'a> {
23    #[serde(rename = "CertId")]
24    pub cert_id: &'a str,
25}
26
27#[derive(Serialize)]
28#[serde(rename_all = "PascalCase")]
29pub struct HttpsInfo<'a> {
30    switch: &'a str,
31    cert_info: CertInfo<'a>,
32}
33
34#[derive(Serialize)]
35#[serde(rename_all = "PascalCase")]
36pub struct UpdateDomainConfig<'a> {
37    pub domain: &'a str,
38    pub https: HttpsInfo<'a>,
39}
40
41impl<'a> UpdateDomainConfig<'a> {
42    pub fn new(domain: &'a str, value: &'a str) -> Self {
43        Self {
44            domain,
45            https: HttpsInfo {
46                switch: "on",
47                cert_info: CertInfo { cert_id: value },
48            },
49        }
50    }
51}
52
53impl<'a> Endpoint for UpdateDomainConfig<'a> {
54    type Output = UpdateDomainConfigResponse;
55
56    fn service(&self) -> Cow<'static, str> {
57        Cow::Borrowed("cdn")
58    }
59
60    fn action(&self) -> Cow<'static, str> {
61        Cow::Borrowed("UpdateDomainConfig")
62    }
63
64    fn version(&self) -> Cow<'static, str> {
65        Cow::Borrowed("2018-06-06")
66    }
67
68    fn region(&self) -> Option<Cow<'_, str>> {
69        // CDN UpdateDomainConfig does not require a region parameter
70        None
71    }
72
73    fn payload(&self) -> Value {
74        serde_json::to_value(self).expect("serialize UpdateDomainConfig payload")
75    }
76}
77
78/// Call CDN `UpdateDomainConfig` with the async client.
79pub async fn update_domain_config_async(
80    client: &TencentCloudAsync,
81    request: &UpdateDomainConfig<'_>,
82) -> TencentCloudResult<UpdateDomainConfigResponse> {
83    client.request(request).await
84}
85
86/// Call CDN `UpdateDomainConfig` with the blocking client.
87pub fn update_domain_config_blocking(
88    client: &TencentCloudBlocking,
89    request: &UpdateDomainConfig<'_>,
90) -> TencentCloudResult<UpdateDomainConfigResponse> {
91    client.request(request)
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97    use serde_json::json;
98
99    #[test]
100    fn test_update_domain_config_payload() {
101        let cert_id = "cert_001";
102        let domain_name = "example.com";
103
104        let request = UpdateDomainConfig::new(domain_name, cert_id);
105
106        let payload = request.payload();
107        assert_eq!(payload["Domain"], json!(domain_name));
108        assert!(payload["Https"].is_object());
109
110        let https_value = &payload["Https"];
111        assert!(https_value["CertInfo"].is_object());
112
113        let cert_info_value = &https_value["CertInfo"];
114        assert_eq!(cert_info_value["CertId"], json!(cert_id),);
115
116        let expected_payload = json!({
117            "Domain": "example.com",
118            "Https": {
119                "Switch":"on",
120                "CertInfo": {
121                    "CertId": "cert_001"
122                }
123            }
124        });
125
126        assert_eq!(payload, expected_payload);
127    }
128}