diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-08 11:11:22 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-12-08 11:11:22 +0100 |
commit | 098a6cf2cdb9b0370ab7358b005f731b65e9981c (patch) | |
tree | 80e862f2ba2aeb03a33ab8e4fcb05d4a221dd308 /src/proxy_config.rs | |
parent | 11c6f0b1c29b10893de9390f5be559de49e78410 (diff) | |
download | tricot-098a6cf2cdb9b0370ab7358b005f731b65e9981c.tar.gz tricot-098a6cf2cdb9b0370ab7358b005f731b65e9981c.zip |
Implement glob pattern hostnames
no wildcard certificates: one certificate per matching hostname that
actually recieves requests
Diffstat (limited to 'src/proxy_config.rs')
-rw-r--r-- | src/proxy_config.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/proxy_config.rs b/src/proxy_config.rs index d4fe039..9092b59 100644 --- a/src/proxy_config.rs +++ b/src/proxy_config.rs @@ -16,10 +16,33 @@ use crate::consul::*; // ---- Extract proxy config from Consul catalog ---- #[derive(Debug)] +pub enum HostDescription { + Hostname(String), + Pattern(glob::Pattern), +} + +impl HostDescription { + fn new(desc: &str) -> Result<Self> { + if desc.chars().any(|x| matches!(x, '*' | '?' | '[' | ']')) { + Ok(Self::Pattern(glob::Pattern::new(desc)?)) + } else { + Ok(Self::Hostname(desc.to_string())) + } + } + + pub fn matches(&self, v: &str) -> bool { + match self { + Self::Pattern(p) => p.matches(v), + Self::Hostname(s) => s == v, + } + } +} + +#[derive(Debug)] pub struct ProxyEntry { pub target_addr: SocketAddr, - pub host: String, + pub host: HostDescription, pub path_prefix: Option<String>, pub priority: u32, pub add_headers: Vec<(String, String)>, @@ -65,9 +88,17 @@ fn parse_tricot_tag( _ => 100, }; + let host = match HostDescription::new(host) { + Ok(h) => h, + Err(e) => { + warn!("Invalid hostname pattern {}: {}", host, e); + return None; + } + }; + Some(ProxyEntry { target_addr, - host: host.to_string(), + host, path_prefix, priority, add_headers: add_headers.to_vec(), |