aboutsummaryrefslogtreecommitdiff
path: root/src/proxy_config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/proxy_config.rs')
-rw-r--r--src/proxy_config.rs35
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(),