Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1m18s
115 lines
2.7 KiB
Rust
115 lines
2.7 KiB
Rust
use serde::{Serialize, Deserialize};
|
|
use chrono::{DateTime, Utc};
|
|
use crate::client::RecordType;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct TxtVerification {
|
|
pub name: String,
|
|
pub token: String
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Pagination {
|
|
pub page: u32,
|
|
pub per_page: u32,
|
|
pub last_page: u32,
|
|
pub total_entries: u32
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Meta {
|
|
pub pagination: Pagination
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Zone {
|
|
pub id: String,
|
|
#[serde(with = "hetzner_date")]
|
|
pub created: DateTime<Utc>,
|
|
#[serde(with = "hetzner_date")]
|
|
pub modified: DateTime<Utc>,
|
|
pub legacy_dns_host: String,
|
|
pub legacy_dns: Option<Vec<String>>,
|
|
pub ns: Vec<String>,
|
|
pub owner: String,
|
|
pub paused: bool,
|
|
pub permission: String,
|
|
pub project: String,
|
|
pub registrar: String,
|
|
pub status: String,
|
|
pub ttl: Option<u64>,
|
|
//#[serde(with = "hetzner_date")] // verified strings are empty, so its useless anyway
|
|
//pub verified: Option<DateTime<Utc>>,
|
|
pub records_count: u32,
|
|
pub is_secondary_dns: bool,
|
|
pub txt_verification: TxtVerification
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct ZoneResult {
|
|
pub zones: Vec<Zone>,
|
|
pub meta: Meta
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct RecordPayload {
|
|
zone_id: String,
|
|
r#type: RecordType,
|
|
name: String,
|
|
value: String,
|
|
ttl: u64
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct Record {
|
|
id: String,
|
|
#[serde(with = "hetzner_date")]
|
|
created: DateTime<Utc>,
|
|
#[serde(with = "hetzner_date")]
|
|
modified: DateTime<Utc>,
|
|
zone_id: String,
|
|
r#type: String,
|
|
name: String,
|
|
value: String,
|
|
ttl: Option<u64>
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct RecordResult {
|
|
pub record: Record
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct RecordsResult {
|
|
pub records: Vec<Record>
|
|
}
|
|
|
|
mod hetzner_date {
|
|
use chrono::{DateTime, Utc, NaiveDateTime};
|
|
use serde::{self, Deserialize, Serializer, Deserializer};
|
|
|
|
// 2025-01-06 02:18:34.674 +0000 UTC
|
|
const FORMAT: &str = "%F %T.%-f";
|
|
|
|
pub fn serialize<S>(
|
|
date: &DateTime<Utc>,
|
|
serializer: S,
|
|
) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
let s = format!("{}", date.format(FORMAT));
|
|
serializer.serialize_str(&s)
|
|
}
|
|
|
|
pub fn deserialize<'de, D>(
|
|
deserializer: D,
|
|
) -> Result<DateTime<Utc>, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let s = String::deserialize(deserializer)?;
|
|
let dt = NaiveDateTime::parse_from_str(&s.split(" +").next().unwrap(), FORMAT).map_err(serde::de::Error::custom)?;
|
|
Ok(DateTime::<Utc>::from_naive_utc_and_offset(dt, Utc))
|
|
}
|
|
}
|