aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2021-03-18 21:26:34 +0100
committerAlex <alex@adnab.me>2021-03-18 21:26:34 +0100
commite19e267b7ea9a6c8e69e288dc49d66c2877a2cc6 (patch)
treedbcc52170e5340d3be5e4c52781c950dd9d6eb5e
parent6edbc658472a552da3b26f32773a8fa97b51aff8 (diff)
parentf17cb6c969121d12937409f9ec0d204cad4a841c (diff)
downloadgarage-e19e267b7ea9a6c8e69e288dc49d66c2877a2cc6.tar.gz
garage-e19e267b7ea9a6c8e69e288dc49d66c2877a2cc6.zip
Merge pull request 'add support for using domain name in configuration' (#46) from trinity-1686a/garage:bind-domain into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/46
-rw-r--r--src/util/config.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/util/config.rs b/src/util/config.rs
index cd65e009..9ff67711 100644
--- a/src/util/config.rs
+++ b/src/util/config.rs
@@ -2,7 +2,7 @@ use std::io::Read;
use std::net::SocketAddr;
use std::path::PathBuf;
-use serde::Deserialize;
+use serde::{de, Deserialize};
use crate::error::Error;
@@ -13,6 +13,7 @@ pub struct Config {
pub rpc_bind_addr: SocketAddr,
+ #[serde(deserialize_with = "deserialize_vec_addr")]
pub bootstrap_peers: Vec<SocketAddr>,
pub consul_host: Option<String>,
pub consul_service_name: Option<String>,
@@ -82,3 +83,28 @@ pub fn read_config(config_file: PathBuf) -> Result<Config, Error> {
Ok(toml::from_str(&config)?)
}
+
+fn deserialize_vec_addr<'de, D>(deserializer: D) -> Result<Vec<SocketAddr>, D::Error>
+where
+ D: de::Deserializer<'de>,
+{
+ use std::net::ToSocketAddrs;
+
+ Ok(<Vec<&str>>::deserialize(deserializer)?
+ .iter()
+ .filter_map(|&name| {
+ name.to_socket_addrs()
+ .map(|iter| (name, iter))
+ .map_err(|_| warn!("Error resolving \"{}\"", name))
+ .ok()
+ })
+ .map(|(name, iter)| {
+ let v = iter.collect::<Vec<_>>();
+ if v.is_empty() {
+ warn!("Error resolving \"{}\"", name)
+ }
+ v
+ })
+ .flatten()
+ .collect())
+}