Compare commits

...

6 commits

Author SHA1 Message Date
Kaan Barmore-Genç 05a3fb6c89
Fix spawn local panic about local set 2022-06-09 22:11:42 -04:00
Kaan Barmore-Genç a9629ad4a3
Bump version for release 2022-06-09 21:57:44 -04:00
dependabot[bot] c05b0a8494
Bump tokio from 1.17.0 to 1.19.0 (#19)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.17.0 to 1.19.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.17.0...tokio-1.19.0)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-09 21:29:21 -04:00
Kaan Barmore-Genç 661dfc55fd
Use a single threaded setup & allow configurable TTL (#21)
* use a single threaded executor

* add configurable TTL support
2022-06-09 21:29:02 -04:00
dependabot[bot] e4938a3f95
Bump serde from 1.0.136 to 1.0.137 (#14)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.136 to 1.0.137.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.136...v1.0.137)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-09 20:39:25 -04:00
dependabot[bot] df672c0f48
Bump clap from 3.1.12 to 3.1.18 (#17)
Bumps [clap](https://github.com/clap-rs/clap) from 3.1.12 to 3.1.18.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v3.1.12...v3.1.18)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-09 20:39:16 -04:00
6 changed files with 50 additions and 24 deletions

26
Cargo.lock generated
View file

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

View file

@ -1,6 +1,6 @@
[package]
name = "gandi-live-dns"
version = "1.1.0"
version = "1.2.1"
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.17", features = ["full"] }
tokio = { version = "1.19", features = ["full"] }
futures = "0.3"
anyhow = "1.0"
governor = "0.4"

View file

@ -9,6 +9,12 @@ 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]]
@ -24,3 +30,5 @@ 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,28 +10,37 @@ 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 {
return entry.fqdn.as_ref().unwrap_or(&config.fqdn).as_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)
}
pub fn types<'e>(entry: &'e Entry) -> Vec<&'e str> {
return entry
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,7 +3,8 @@ use anyhow;
use clap::Parser;
use futures;
use reqwest::{header, Client, ClientBuilder, StatusCode};
use std::{collections::HashMap, num::NonZeroU32, sync::Arc, time::Duration};
use serde::Serialize;
use std::{num::NonZeroU32, sync::Arc, time::Duration};
use tokio::{self, task::JoinHandle};
mod config;
mod opts;
@ -43,7 +44,13 @@ async fn get_ip(api_url: &str) -> anyhow::Result<String> {
Ok(text)
}
#[tokio::main]
#[derive(Serialize)]
pub struct APIPayload {
pub rrset_values: Vec<String>,
pub rrset_ttl: u32,
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let opts = opts::Opts::parse();
let conf = config::load_config(&opts)
@ -83,9 +90,11 @@ 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 mut map = HashMap::new();
map.insert("rrset_values", vec![ip]);
let req = client.put(url).json(&map);
let payload = APIPayload {
rrset_values: vec![ip.to_string()],
rrset_ttl: Config::ttl(&entry, &conf),
};
let req = client.put(url).json(&payload);
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, ArgEnum};
use clap::Parser;
/// A tool to automatically update DNS entries on Gandi, using it as a dynamic DNS system.
#[derive(Parser, Debug)]