aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-12-11 16:29:06 +0100
committerAlex Auvolat <alex@adnab.me>2022-12-11 16:29:06 +0100
commitb26d4d7bbad7c77f466a00f0bd21e7e4ea09c3b1 (patch)
tree0894d7de36ec28e20f36311c5144959d6f604343 /src/main.rs
parent0d37299b24ec112b752b81334e35bac8c2c36167 (diff)
downloadD53-b26d4d7bbad7c77f466a00f0bd21e7e4ea09c3b1.tar.gz
D53-b26d4d7bbad7c77f466a00f0bd21e7e4ea09c3b1.zip
Change label format to be a single dns path
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 667c058..77c8b16 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,8 +37,8 @@ pub struct Opt {
pub consul_client_key: Option<String>,
/// DNS provider
- #[structopt(long = "provider", env = "D53_PROVIDER")]
- pub provider: String,
+ #[structopt(long = "providers", env = "D53_PROVIDERS")]
+ pub providers: String,
/// Allowed domains
#[structopt(long = "allowed-domains", env = "D53_ALLOWED_DOMAINS")]
@@ -49,6 +49,11 @@ pub struct Opt {
pub gandi_api_key: Option<String>,
}
+pub struct DomainProvider {
+ pub domain: String,
+ pub provider: Box<dyn provider::DnsProvider>,
+}
+
#[tokio::main]
async fn main() {
if std::env::var("RUST_LOG").is_err() {
@@ -81,12 +86,24 @@ async fn main() {
let consul = df_consul::Consul::new(consul_config, "").expect("Cannot build Consul");
- let provider: Box<dyn provider::DnsProvider> = match opt.provider.as_str() {
- "gandi" => Box::new(
- provider::gandi::GandiProvider::new(&opt).expect("Cannot initialize Gandi provier"),
- ),
- p => panic!("Unsupported DNS provider: {}", p),
- };
+ let mut domain_providers = vec![];
+ for pstr in opt.providers.as_str().split(',') {
+ let (domain, provider) = pstr.split_once(':')
+ .expect("Invalid provider syntax, expected: <domain_name>:<provider>[,<domain_name>:<provider>[,...]]");
+ let provider: Box<dyn provider::DnsProvider> = match provider {
+ "gandi" => Box::new(
+ provider::gandi::GandiProvider::new(&opt).expect("Cannot initialize Gandi provier"),
+ ),
+ p => panic!("Unsupported DNS provider: {}", p),
+ };
+ domain_providers.push(DomainProvider {
+ domain: domain.to_string(),
+ provider,
+ });
+ }
+ if domain_providers.is_empty() {
+ panic!("No domain providers were specified.");
+ }
let allowed_domains = opt
.allowed_domains
@@ -98,7 +115,7 @@ async fn main() {
let updater_task = tokio::spawn(dns_updater::dns_updater_task(
rx_dns_config.clone(),
- provider,
+ domain_providers,
allowed_domains,
exit_signal.clone(),
));