aboutsummaryrefslogtreecommitdiff
path: root/src/proxy_config.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-08-27 15:26:19 +0200
committerAlex Auvolat <alex@adnab.me>2023-08-27 15:26:19 +0200
commitb5e8d1fcd800330edfc4e8deed5229d172ec1248 (patch)
treee1377e66ac3f16cd6c5136aa0933da9433b3e48e /src/proxy_config.rs
parent48a421a3b6c07705b67276853643ed5601a30154 (diff)
downloadtricot-b5e8d1fcd800330edfc4e8deed5229d172ec1248.tar.gz
tricot-b5e8d1fcd800330edfc4e8deed5229d172ec1248.zip
stdout: prettier formatting of proxy config
Diffstat (limited to 'src/proxy_config.rs')
-rw-r--r--src/proxy_config.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/proxy_config.rs b/src/proxy_config.rs
index b4fab90..18f9d53 100644
--- a/src/proxy_config.rs
+++ b/src/proxy_config.rs
@@ -16,7 +16,7 @@ use crate::consul;
// ---- Extract proxy config from Consul catalog ----
-#[derive(Debug)]
+#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum HostDescription {
Hostname(String),
Pattern(glob::Pattern),
@@ -43,7 +43,7 @@ impl std::fmt::Display for HostDescription {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HostDescription::Hostname(h) => write!(f, "{}", h),
- HostDescription::Pattern(p) => write!(f, "Pattern('{}')", p.as_str()),
+ HostDescription::Pattern(p) => write!(f, "[{}]", p.as_str()),
}
}
}
@@ -77,7 +77,21 @@ pub struct ProxyEntry {
pub last_call: atomic::AtomicI64,
}
-#[derive(Debug, Clone, Copy)]
+impl PartialEq for ProxyEntry {
+ fn eq(&self, other: &Self) -> bool {
+ self.host == other.host
+ && self.path_prefix == other.path_prefix
+ && self.priority == other.priority
+ && self.service_name == other.service_name
+ && self.target_addr == other.target_addr
+ && self.https_target == other.https_target
+ && self.flags == other.flags
+ && self.add_headers == other.add_headers
+ }
+}
+impl Eq for ProxyEntry {}
+
+#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct ProxyEntryFlags {
/// Is the target the same node as we are running on?
/// (if yes priorize it over other matching targets)
@@ -122,7 +136,7 @@ impl std::fmt::Display for ProxyEntry {
}
}
-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq)]
pub struct ProxyConfig {
pub entries: Vec<ProxyEntry>,
}
@@ -383,6 +397,9 @@ pub fn spawn_proxy_config_task(
entries.extend(parse_consul_catalog(catalog, same_node, same_site));
}
}
+
+ entries.sort_by_cached_key(|ent| ent.to_string());
+
let config = ProxyConfig { entries };
tx.send(Arc::new(config)).expect("Internal error");