cloudflare/endpoints/
zone.rs

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