cloudflare/endpoints/
dns.rs1use surf::http::Method;
2
3use crate::framework::{endpoint::Endpoint, ApiResultTraits};
4use crate::framework::{OrderDirection, SearchMatch};
6use chrono::offset::Utc;
7use chrono::DateTime;
8use std::net::{Ipv4Addr, Ipv6Addr};
9
10#[derive(Debug)]
13pub struct ListDnsRecords<'a> {
14 pub zone_identifier: &'a str,
15 pub params: ListDnsRecordsParams,
16}
17impl<'a> Endpoint<Vec<DnsRecord>, ListDnsRecordsParams> for ListDnsRecords<'a> {
18 fn method(&self) -> Method {
19 Method::Get
20 }
21 fn path(&self) -> String {
22 format!("zones/{}/dns_records", self.zone_identifier)
23 }
24 fn query(&self) -> Option<ListDnsRecordsParams> {
25 Some(self.params.clone())
26 }
27}
28
29#[derive(Debug)]
32pub struct CreateDnsRecord<'a> {
33 pub zone_identifier: &'a str,
34 pub params: CreateDnsRecordParams<'a>,
35}
36
37impl<'a> Endpoint<DnsRecord, (), CreateDnsRecordParams<'a>> for CreateDnsRecord<'a> {
38 fn method(&self) -> Method {
39 Method::Post
40 }
41 fn path(&self) -> String {
42 format!("zones/{}/dns_records", self.zone_identifier)
43 }
44 fn body(&self) -> Option<CreateDnsRecordParams<'a>> {
45 Some(self.params.clone())
46 }
47}
48
49#[serde_with::skip_serializing_none]
50#[derive(Serialize, Clone, Debug)]
51pub struct CreateDnsRecordParams<'a> {
52 pub ttl: Option<u32>,
54 pub priority: Option<u16>,
57 pub proxied: Option<bool>,
59 pub name: &'a str,
61 #[serde(flatten)]
63 pub content: DnsContent,
64}
65
66#[derive(Debug)]
69pub struct DeleteDnsRecord<'a> {
70 pub zone_identifier: &'a str,
71 pub identifier: &'a str,
72}
73impl<'a> Endpoint<DeleteDnsRecordResponse> for DeleteDnsRecord<'a> {
74 fn method(&self) -> Method {
75 Method::Delete
76 }
77 fn path(&self) -> String {
78 format!(
79 "zones/{}/dns_records/{}",
80 self.zone_identifier, self.identifier
81 )
82 }
83}
84
85#[derive(Debug)]
88pub struct UpdateDnsRecord<'a> {
89 pub zone_identifier: &'a str,
90 pub identifier: &'a str,
91 pub params: UpdateDnsRecordParams<'a>,
92}
93
94impl<'a> Endpoint<DnsRecord, (), UpdateDnsRecordParams<'a>> for UpdateDnsRecord<'a> {
95 fn method(&self) -> Method {
96 Method::Put
97 }
98 fn path(&self) -> String {
99 format!(
100 "zones/{}/dns_records/{}",
101 self.zone_identifier, self.identifier
102 )
103 }
104 fn body(&self) -> Option<UpdateDnsRecordParams<'a>> {
105 Some(self.params.clone())
106 }
107}
108
109#[serde_with::skip_serializing_none]
110#[derive(Serialize, Clone, Debug)]
111pub struct UpdateDnsRecordParams<'a> {
112 pub ttl: Option<u32>,
114 pub proxied: Option<bool>,
116 pub name: &'a str,
118 #[serde(flatten)]
120 pub content: DnsContent,
121}
122
123#[derive(Serialize, Clone, Debug)]
124#[serde(rename_all = "lowercase")]
125pub enum ListDnsRecordsOrder {
126 Type,
127 Name,
128 Content,
129 Ttl,
130 Proxied,
131}
132
133#[serde_with::skip_serializing_none]
134#[derive(Serialize, Clone, Debug, Default)]
135pub struct ListDnsRecordsParams {
136 #[serde(flatten)]
137 pub record_type: Option<DnsContent>,
138 pub name: Option<String>,
139 pub page: Option<u32>,
140 pub per_page: Option<u32>,
141 pub order: Option<ListDnsRecordsOrder>,
142 pub direction: Option<OrderDirection>,
143 #[serde(rename = "match")]
144 pub search_match: Option<SearchMatch>,
145}
146
147#[derive(Deserialize, Debug)]
149pub struct Meta {
150 pub auto_added: bool,
152}
153
154#[derive(Deserialize, Serialize, Clone, Debug)]
158#[serde(tag = "type")]
159pub enum DnsContent {
160 A { content: Ipv4Addr },
161 AAAA { content: Ipv6Addr },
162 CNAME { content: String },
163 NS { content: String },
164 MX { content: String, priority: u16 },
165 TXT { content: String },
166 SRV { content: String },
167}
168
169#[derive(Deserialize, Debug)]
170pub struct DeleteDnsRecordResponse {
171 pub id: String,
173}
174
175#[derive(Deserialize, Debug)]
176pub struct DnsRecord {
177 pub meta: Meta,
179 pub locked: bool,
181 pub name: String,
183 pub ttl: u32,
185 pub zone_id: String,
187 pub modified_on: DateTime<Utc>,
189 pub created_on: DateTime<Utc>,
191 pub proxiable: bool,
193 #[serde(flatten)]
195 pub content: DnsContent,
196 pub id: String,
198 pub proxied: bool,
200 pub zone_name: String,
202}
203
204impl ApiResultTraits for DnsRecord {}
205impl ApiResultTraits for Vec<DnsRecord> {}
206impl ApiResultTraits for DeleteDnsRecordResponse {}