cloudflare/endpoints/
zone.rs

1use surf::http::Method;
2
3use crate::endpoints::{account::AccountDetails, plan::Plan};
4use crate::framework::{endpoint::Endpoint, ApiResultTraits};
5use crate::framework::{OrderDirection, SearchMatch};
6use chrono::offset::Utc;
7use chrono::DateTime;
8
9/// List Zones
10/// List, search, sort, and filter your zones
11/// https://api.cloudflare.com/#zone-list-zones
12#[derive(Debug)]
13pub struct ListZones {
14    pub params: ListZonesParams,
15}
16
17impl Endpoint<Vec<Zone>, ListZonesParams> for ListZones {
18    fn method(&self) -> Method {
19        Method::Get
20    }
21    fn path(&self) -> String {
22        "zones".to_string()
23    }
24    fn query(&self) -> Option<ListZonesParams> {
25        Some(self.params.clone())
26    }
27}
28
29/// Zone Details
30/// https://api.cloudflare.com/#zone-zone-details
31#[derive(Debug)]
32pub struct ZoneDetails<'a> {
33    pub identifier: &'a str,
34}
35impl<'a> Endpoint<Zone> for ZoneDetails<'a> {
36    fn method(&self) -> Method {
37        Method::Get
38    }
39    fn path(&self) -> String {
40        format!("zones/{}", self.identifier)
41    }
42}
43
44/// Add Zone
45/// https://api.cloudflare.com/#zone-create-zone
46pub struct CreateZone<'a> {
47    pub params: CreateZoneParams<'a>,
48}
49impl<'a> Endpoint<(), (), CreateZoneParams<'a>> for CreateZone<'a> {
50    fn method(&self) -> Method {
51        Method::Post
52    }
53
54    fn path(&self) -> String {
55        "zones".to_string()
56    }
57
58    fn body(&self) -> Option<CreateZoneParams<'a>> {
59        Some(self.params.clone())
60    }
61}
62
63#[derive(Serialize, Clone, Debug, Default)]
64pub struct CreateZoneParams<'a> {
65    pub name: &'a str,
66    pub account: &'a str,
67    pub jump_start: Option<bool>,
68    #[serde(rename = "type")]
69    pub zone_type: Option<Type>,
70}
71
72#[derive(Serialize, Clone, Debug, Default)]
73pub struct ListZonesParams {
74    pub name: Option<String>,
75    pub status: Option<Status>,
76    pub page: Option<u32>,
77    pub per_page: Option<u32>,
78    pub order: Option<ListZonesOrder>,
79    pub direction: Option<OrderDirection>,
80    #[serde(rename = "match")]
81    pub search_match: Option<SearchMatch>,
82}
83
84#[derive(Serialize, Clone, Debug)]
85#[serde(rename_all = "lowercase")]
86pub enum ListZonesOrder {
87    Name,
88    Status,
89    Email,
90}
91
92#[derive(Clone, Debug, Deserialize, Serialize)]
93#[serde(rename = "status", rename_all = "lowercase")]
94pub enum Status {
95    Active,
96    Pending,
97    Initializing,
98    Moved,
99    Deleted,
100    Deactivated,
101}
102
103#[derive(Deserialize, Debug)]
104#[serde(rename_all = "lowercase", tag = "type")]
105pub enum Owner {
106    User { id: String, email: String },
107    Organization { id: String, name: String },
108}
109
110#[derive(Serialize, Deserialize, Debug, Clone)]
111#[serde(rename_all = "lowercase")]
112pub enum Type {
113    Full,
114    Partial,
115}
116
117#[derive(Deserialize, Debug)]
118pub struct HostingPartner {
119    /// Host company name
120    pub name: String,
121    /// The host's website URL
122    pub website: String,
123}
124
125#[derive(Deserialize, Debug)]
126pub struct Meta {
127    /// Maximum custom certificates that can be uploaded/used.
128    pub custom_certificate_quota: u32,
129    /// Maximum page rules that can be created.
130    pub page_rule_quota: u32,
131    /// Indicates whether wildcard DNS records can receive Cloudflare security and performance
132    /// features
133    pub wildcard_proxiable: bool,
134    /// Indicates if URLs on the zone have been identified as hosting phishing content.
135    pub phishing_detected: bool,
136    /// Indicates whether the zone is allowed to be connected to multiple Railguns at once
137    pub multiple_railguns_allowed: bool,
138}
139
140/// A Zone is a domain name along with its subdomains and other identities
141/// https://api.cloudflare.com/#zone-properties
142#[derive(Deserialize, Debug)]
143pub struct Zone {
144    /// Zone identifier tag
145    pub id: String,
146    /// The domain name
147    pub name: String,
148    /// Information about the account the zone belongs to
149    pub account: AccountDetails,
150    /// A list of beta features in which the zone is participating
151    pub betas: Option<Vec<String>>,
152    /// When the zone was created
153    pub created_on: DateTime<Utc>,
154    /// Exists only with a deactivated status and indicates the reason the zone is not resolving on
155    /// the Cloudflare network.
156    pub deactivation_reason: Option<String>,
157    /// The interval (in seconds) from when development mode expires (positive integer) or last
158    /// expired (negative integer) for the domain. If development mode has never been enabled, this
159    /// value is 0.
160    pub development_mode: i32,
161    /// Hosting partner information, if the zone signed up via a Cloudflare hosting partner
162    pub host: Option<HostingPartner>,
163    /// Metadata about the domain.
164    pub meta: Meta,
165    /// When the zone was last modified
166    pub modified_on: DateTime<Utc>,
167    /// Cloudflare-assigned name servers. This is only populated for zones that use Cloudflare DNS
168    pub name_servers: Vec<String>,
169    /// DNS host at the time of switching to Cloudflare
170    pub original_dnshost: Option<String>,
171    /// Original name servers before moving to Cloudflare
172    pub original_name_servers: Option<Vec<String>>,
173    /// Registrar for the domain at the time of switching to Cloudflare
174    pub original_registrar: Option<String>,
175    /// Information about the owner of the zone
176    pub owner: Owner,
177    /// Indicates if the zone is only using Cloudflare DNS services. A true value means the zone
178    /// will not receive security or performance benefits.
179    pub paused: bool,
180    /// Available permissions on the zone for the current user requesting the item
181    pub permissions: Vec<String>,
182    /// A zone plan
183    pub plan: Option<Plan>,
184    /// A zone plan
185    pub plan_pending: Option<Plan>,
186    /// Status of the zone
187    pub status: Status,
188    /// An array of domains used for custom name servers. This is only available for Business and
189    /// Enterprise plans.
190    pub vanity_name_servers: Option<Vec<String>>,
191    /// A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a
192    /// partner-hosted zone or a CNAME setup.
193    #[serde(rename = "type")]
194    pub zone_type: Type,
195}
196
197// TODO: This should probably be a derive macro
198impl ApiResultTraits for Zone {}
199impl ApiResultTraits for Vec<Zone> {}