diff options
| author | Gus Power <gus@infinitesidequests.com> | 2025-05-12 16:52:10 +0100 |
|---|---|---|
| committer | Gus Power <gus@infinitesidequests.com> | 2025-05-12 16:52:10 +0100 |
| commit | 87c3219c0e6c7f374cf117eb1990dd41e196710a (patch) | |
| tree | c05007b36409b2a2867b4d0d2ec3bd6f2b587bcd /src | |
| parent | 65746b829b8247ab366182ea028dc1eb0d21522a (diff) | |
start on gandi template
Diffstat (limited to 'src')
| -rw-r--r-- | src/dyndns_service.rs | 2 | ||||
| -rw-r--r-- | src/dyndns_service/gandi.rs | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/dyndns_service.rs b/src/dyndns_service.rs index caa163d..7c903e0 100644 --- a/src/dyndns_service.rs +++ b/src/dyndns_service.rs @@ -1,3 +1,5 @@ +mod gandi; + use reqwest::ClientBuilder; use std::error::Error; diff --git a/src/dyndns_service/gandi.rs b/src/dyndns_service/gandi.rs new file mode 100644 index 0000000..72c95ad --- /dev/null +++ b/src/dyndns_service/gandi.rs @@ -0,0 +1,57 @@ +// curl --request PUT \ +// --url https://api.gandi.net/api/v5/domains/example.net/records/mybox/A \ +// --header "authorization: Apikey ${API_KEY}" \ +// --header 'content-type: application/json' \ +// --data "{ \"rrset_ttl\": 300, \"rrset_values\": [\"1.2.3.4\"] }" + +use serde_with::DisplayFromStr; +use serde_with::TryFromInto; +use serde_with::serde_as; +use http::Method; +use trust_dns_client::rr::RecordType; +use serde::Deserialize; +use crate::dyndns_service::DynDnsServiceConfiguration; + +// See https://api.gandi.net/docs/livedns/ for more info + +const API_URL_TEMPLATE: &str = "https://api.gandi.net/api/v5/domains/{domain}/records/{subdomain}/{record_type}"; + +#[serde_as] +#[derive(Debug, Deserialize)] +struct Gandi { + domain: String, + subdomain: String, + #[serde(default = "Gandi::default_method")] + #[serde_as(as = "DisplayFromStr")] + method: Method, + #[serde(default = "Gandi::default_record_type")] + #[serde_as(as = "DisplayFromStr")] + record_type: RecordType, +} + +impl Gandi { + + fn default_method() -> Method { Method::PUT } + fn default_record_type() -> RecordType { RecordType::A } + +} + +impl DynDnsServiceConfiguration for Gandi { + fn get_service_url(&self) -> String { + format!("https://api.gandi.net/api/v5/domains/{domain}/records/{subdomain}/{record_type}", domain = self.domain, subdomain = self.subdomain, record_type = self.record_type) + } +} + +#[cfg(test)] +mod tests { + + use super::*; + + #[test] + fn check_defaults() { + let gandi = serde_json::from_str::<Gandi>("{ \"domain\":\"mydomain.com\", \"subdomain\":\"dyn\" }").unwrap(); + + assert_eq!(gandi.record_type, RecordType::A); + assert_eq!(gandi.method, Method::PUT); + } +} |
