diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 35 |
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(), )); |