Compare commits

..

No commits in common. "05a3fb6c8931b5cc95f0d37036febb375444d4bf" and "ffa22a6f8d0f8de1c1633f5a47c4682272305954" have entirely different histories.

6 changed files with 24 additions and 50 deletions

26
Cargo.lock generated
View file

@ -63,9 +63,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.1.18"
version = "3.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
dependencies = [
"atty",
"bitflags",
@ -82,9 +82,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "3.1.18"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
dependencies = [
"heck",
"proc-macro-error",
@ -95,9 +95,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.2.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
dependencies = [
"os_str_bytes",
]
@ -270,7 +270,7 @@ dependencies = [
[[package]]
name = "gandi-live-dns"
version = "1.2.1"
version = "1.1.0"
dependencies = [
"anyhow",
"clap",
@ -858,18 +858,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.137"
version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.137"
version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
dependencies = [
"proc-macro2",
"quote",
@ -1019,9 +1019,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.19.0"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f392c8f16bda3456c0b00c6de39cb100449b98de55ac41c6cdd2bfcf53a1245"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"bytes",
"libc",

View file

@ -1,6 +1,6 @@
[package]
name = "gandi-live-dns"
version = "1.2.1"
version = "1.1.0"
edition = "2021"
authors = ["Kaan Barmore-Genç <kaan@bgenc.net>"]
@ -16,7 +16,7 @@ json = "0.12"
serde = { version = "1.0", features = ["derive"] }
directories = "4.0"
clap = { version = "3.1", features = ["derive", "cargo", "unicode", "wrap_help"]}
tokio = { version = "1.19", features = ["full"] }
tokio = { version = "1.17", features = ["full"] }
futures = "0.3"
anyhow = "1.0"
governor = "0.4"

View file

@ -9,12 +9,6 @@ fqdn = "example.com"
# otherwise do things that will cause you to be charged money.
api_key = "xxxxxxxxxxxxxxxxxxxxxxxx"
# The Time To Live value to be used by entries. This can be an integer between
# 300 and 2592000. It is 300 by default. This is roughly how quickly DNS changes
# will propagate when updated, you should keep this the minimum so changes to
# your IP address propagate quickly.
ttl = 300
# For every domain or subdomain you want to update, create an entry below.
[[entry]]
@ -30,5 +24,3 @@ types = ["A", "AAAA"]
# Updates A for some.example.net
name = "some"
fqdn = "example.net" # Overrides top level setting
# Individual entries can override the global TTL
ttl = 600

View file

@ -10,37 +10,28 @@ pub struct Entry {
pub name: String,
types: Option<Vec<String>>,
fqdn: Option<String>,
ttl: Option<u32>,
}
fn default_ttl() -> u32 { return 300; }
#[derive(Deserialize, Debug)]
pub struct Config {
fqdn: String,
pub api_key: String,
pub entry: Vec<Entry>,
#[serde(default = "default_ttl")]
pub ttl: u32,
}
const DEFAULT_TYPES: &'static [&'static str] = &["A"];
impl Config {
pub fn fqdn<'c>(entry: &'c Entry, config: &'c Config) -> &'c str {
entry.fqdn.as_ref().unwrap_or(&config.fqdn).as_str()
}
pub fn ttl(entry: &Entry, config: &Config) -> u32 {
entry.ttl.unwrap_or(config.ttl)
return entry.fqdn.as_ref().unwrap_or(&config.fqdn).as_str();
}
pub fn types<'e>(entry: &'e Entry) -> Vec<&'e str> {
entry
return entry
.types
.as_ref()
.and_then(|ts| Some(ts.iter().map(|t| t.as_str()).collect()))
.unwrap_or_else(|| DEFAULT_TYPES.to_vec())
.unwrap_or_else(|| DEFAULT_TYPES.to_vec());
}
}

View file

@ -3,8 +3,7 @@ use anyhow;
use clap::Parser;
use futures;
use reqwest::{header, Client, ClientBuilder, StatusCode};
use serde::Serialize;
use std::{num::NonZeroU32, sync::Arc, time::Duration};
use std::{collections::HashMap, num::NonZeroU32, sync::Arc, time::Duration};
use tokio::{self, task::JoinHandle};
mod config;
mod opts;
@ -44,13 +43,7 @@ async fn get_ip(api_url: &str) -> anyhow::Result<String> {
Ok(text)
}
#[derive(Serialize)]
pub struct APIPayload {
pub rrset_values: Vec<String>,
pub rrset_ttl: u32,
}
#[tokio::main(flavor = "current_thread")]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opts = opts::Opts::parse();
let conf = config::load_config(&opts)
@ -90,11 +83,9 @@ async fn main() -> anyhow::Result<()> {
"AAAA" => ipv6.die_with(|error| format!("Needed IPv6 for {}: {}", fqdn, error)),
bad_entry_type => die!("Unexpected type in config: {}", bad_entry_type),
};
let payload = APIPayload {
rrset_values: vec![ip.to_string()],
rrset_ttl: Config::ttl(&entry, &conf),
};
let req = client.put(url).json(&payload);
let mut map = HashMap::new();
map.insert("rrset_values", vec![ip]);
let req = client.put(url).json(&map);
let task_governor = governor.clone();
let task = tokio::task::spawn(async move {
task_governor.until_ready_with_jitter(retry_jitter).await;

View file

@ -1,4 +1,4 @@
use clap::Parser;
use clap::{Parser, ArgEnum};
/// A tool to automatically update DNS entries on Gandi, using it as a dynamic DNS system.
#[derive(Parser, Debug)]