cloudflare/endpoints/
dns.rs1use crate::framework::{
2 endpoint::{Endpoint, Method},
3 response::ApiResult,
4};
5use crate::framework::{OrderDirection, SearchMatch};
7use chrono::offset::Utc;
8use chrono::DateTime;
9use std::net::{Ipv4Addr, Ipv6Addr};
10
11pub 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
29pub struct CreateDnsRecord<'a> {
32 pub zone_identifier: &'a str,
33 pub params: CreateDnsRecordParams<'a>,
34}
35
36impl<'a> Endpoint<DnsRecord, (), CreateDnsRecordParams<'a>> for CreateDnsRecord<'a> {
37 fn method(&self) -> Method {
38 Method::Post
39 }
40 fn path(&self) -> String {
41 format!("zones/{}/dns_records", self.zone_identifier)
42 }
43 fn body(&self) -> Option<CreateDnsRecordParams<'a>> {
44 Some(self.params.clone())
45 }
46}
47
48#[serde_with::skip_serializing_none]
49#[derive(Serialize, Clone, Debug)]
50pub struct CreateDnsRecordParams<'a> {
51 pub ttl: Option<u32>,
53 pub priority: Option<u16>,
56 pub proxied: Option<bool>,
58 pub name: &'a str,
60 #[serde(flatten)]
62 pub content: DnsContent,
63}
64
65pub struct DeleteDnsRecord<'a> {
68 pub zone_identifier: &'a str,
69 pub identifier: &'a str,
70}
71impl<'a> Endpoint<DeleteDnsRecordResponse> for DeleteDnsRecord<'a> {
72 fn method(&self) -> Method {
73 Method::Delete
74 }
75 fn path(&self) -> String {
76 format!(
77 "zones/{}/dns_records/{}",
78 self.zone_identifier, self.identifier
79 )
80 }
81}
82
83#[derive(Serialize, Clone, Debug)]
84#[serde(rename_all = "lowercase")]
85pub enum ListDnsRecordsOrder {
86 Type,
87 Name,
88 Content,
89 Ttl,
90 Proxied,
91}
92
93#[serde_with::skip_serializing_none]
94#[derive(Serialize, Clone, Debug, Default)]
95pub struct ListDnsRecordsParams {
96 pub record_type: Option<DnsContent>,
97 pub name: Option<String>,
98 pub page: Option<u32>,
99 pub per_page: Option<u32>,
100 pub order: Option<ListDnsRecordsOrder>,
101 pub direction: Option<OrderDirection>,
102 #[serde(rename = "match")]
103 pub search_match: Option<SearchMatch>,
104}
105
106#[derive(Deserialize, Debug)]
108pub struct Meta {
109 pub auto_added: bool,
111}
112
113#[derive(Deserialize, Serialize, Clone, Debug)]
117#[serde(tag = "type")]
118pub enum DnsContent {
119 A { content: Ipv4Addr },
120 AAAA { content: Ipv6Addr },
121 CNAME { content: String },
122 NS { content: String },
123 MX { content: String, priority: u16 },
124 TXT { content: String },
125}
126
127#[derive(Deserialize, Debug)]
128pub struct DeleteDnsRecordResponse {
129 pub id: String,
131}
132
133#[derive(Deserialize, Debug)]
134pub struct DnsRecord {
135 pub meta: Meta,
137 pub locked: bool,
139 pub name: String,
141 pub ttl: u32,
143 pub zone_id: String,
145 pub modified_on: DateTime<Utc>,
147 pub created_on: DateTime<Utc>,
149 pub proxiable: bool,
151 #[serde(flatten)]
153 pub content: DnsContent,
154 pub id: String,
156 pub proxied: bool,
158 pub zone_name: String,
160}
161
162impl ApiResult for DnsRecord {}
163impl ApiResult for Vec<DnsRecord> {}
164impl ApiResult for DeleteDnsRecordResponse {}