1use crate::{
2 Error,
3 client::endpoint::Endpoint,
4 types::{CertificateId, DomainName, Region, RequestId},
5};
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
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: RequestId,
19}
20
21#[derive(Debug, Clone, Serialize)]
22#[serde(rename_all = "PascalCase")]
23pub struct CertInfo {
24 pub cert_id: CertificateId,
25}
26
27#[derive(Debug, Clone, Serialize)]
28#[serde(rename_all = "PascalCase")]
29pub struct HttpsInfo {
30 pub switch: String,
31 pub cert_info: CertInfo,
32}
33
34#[derive(Debug, Clone, Serialize)]
35#[serde(rename_all = "PascalCase")]
36pub struct UpdateDomainConfigRequest {
37 pub domain: DomainName,
38 pub https: HttpsInfo,
39}
40
41impl UpdateDomainConfigRequest {
42 pub fn new(domain: impl Into<DomainName>, cert_id: impl Into<CertificateId>) -> Self {
43 Self {
44 domain: domain.into(),
45 https: HttpsInfo {
46 switch: "on".to_string(),
47 cert_info: CertInfo {
48 cert_id: cert_id.into(),
49 },
50 },
51 }
52 }
53}
54
55impl Endpoint for UpdateDomainConfigRequest {
56 type Output = UpdateDomainConfigResponse;
57
58 fn service(&self) -> &'static str {
59 "cdn"
60 }
61
62 fn action(&self) -> &'static str {
63 "UpdateDomainConfig"
64 }
65
66 fn version(&self) -> &'static str {
67 "2018-06-06"
68 }
69
70 fn region(&self) -> Option<&Region> {
71 None
72 }
73
74 fn payload(&self) -> Result<Option<Value>, Error> {
75 let value = serde_json::to_value(self).map_err(|source| {
76 Error::invalid_request_with_source(
77 "failed to serialize UpdateDomainConfig request payload",
78 Box::new(source),
79 )
80 })?;
81 Ok(Some(value))
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use super::*;
88 use serde_json::json;
89
90 #[test]
91 fn update_domain_config_payload() {
92 let request = UpdateDomainConfigRequest::new("example.com", "cert_001");
93 let payload = request.payload().unwrap().unwrap();
94
95 let expected_payload = json!({
96 "Domain": "example.com",
97 "Https": {
98 "Switch":"on",
99 "CertInfo": {
100 "CertId": "cert_001"
101 }
102 }
103 });
104
105 assert_eq!(payload, expected_payload);
106 }
107}