aboutsummaryrefslogtreecommitdiff
path: root/src/dyndns_service/gandi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dyndns_service/gandi.rs')
-rw-r--r--src/dyndns_service/gandi.rs55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/dyndns_service/gandi.rs b/src/dyndns_service/gandi.rs
index 72c95ad..03ecf6f 100644
--- a/src/dyndns_service/gandi.rs
+++ b/src/dyndns_service/gandi.rs
@@ -4,54 +4,67 @@
// --header 'content-type: application/json' \
// --data "{ \"rrset_ttl\": 300, \"rrset_values\": [\"1.2.3.4\"] }"
+use crate::dyndns_service::DynDnsServiceConfiguration;
+use http::Method;
+use serde::{Deserialize, Serialize};
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;
+use crate::config::DnsRecordType;
// 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,
+#[derive(Debug, Deserialize, PartialEq, Serialize)]
+pub struct Gandi {
+ api_key: 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,
+ record_type: DnsRecordType,
}
impl Gandi {
+ pub fn new(api_key: String) -> Self {
+ Self {
+ api_key,
+ method: Self::default_method(),
+ record_type: Self::default_record_type(),
+ }
+ }
- fn default_method() -> Method { Method::PUT }
- fn default_record_type() -> RecordType { RecordType::A }
-
+ fn default_method() -> Method {
+ Method::PUT
+ }
+ fn default_record_type() -> DnsRecordType {
+ DnsRecordType::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)
+ format!(
+ "https://api.gandi.net/api/v5/domains/{domain}/records/{subdomain}/{record_type}",
+ domain = 'a',
+ subdomain = 'b',
+ record_type = self.record_type
+ )
}
}
#[cfg(test)]
mod tests {
-
+ use serde_json::json;
use super::*;
#[test]
fn check_defaults() {
- let gandi = serde_json::from_str::<Gandi>("{ \"domain\":\"mydomain.com\", \"subdomain\":\"dyn\" }").unwrap();
+ let input = json!({
+ "api_key": "SOME-API-KEY",
+ });
+
+ let gandi = serde_json::from_value::<Gandi>(input).unwrap();
- assert_eq!(gandi.record_type, RecordType::A);
+ assert_eq!(gandi.record_type, DnsRecordType::A);
assert_eq!(gandi.method, Method::PUT);
}
}