Skip to content

Commit

Permalink
Fix parsing proxy config from environment (#1413)
Browse files Browse the repository at this point in the history
## Motivation

Looks like figment's env parser doesn't really support nested
structures.

## Solution

Use `#[serde(flatten)]`, like for other bits of the config.
  • Loading branch information
svix-jplatte authored Sep 2, 2024
2 parents a799b8b + f266c04 commit 66930b8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/svix-server/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub struct ConfigurationInner {
pub dangerous_disable_tls_verification: bool,

/// Optional configuration for sending webhooks through a proxy.
#[serde(rename = "proxy")]
#[serde(flatten)]
pub proxy_config: Option<ProxyConfig>,

#[serde(flatten)]
Expand All @@ -202,6 +202,7 @@ pub struct ProxyConfig {
/// SOCKS5 proxy address.
///
/// More proxy types may be supported in the future.
#[serde(rename = "proxy_addr")]
pub addr: ProxyAddr,
}

Expand Down Expand Up @@ -514,6 +515,20 @@ mod tests {
});
}

#[test]
fn test_proxy_addr_from_env_parsing() {
figment::Jail::expect_with(|jail| {
jail.set_env("SVIX_QUEUE_TYPE", "memory");
jail.set_env("SVIX_JWT_SECRET", "x");
jail.set_env("SVIX_PROXY_ADDR", "x");

let cfg = load().unwrap();
assert!(cfg.proxy_config.is_some());

Ok(())
});
}

#[test]
fn test_cache_or_queue_dsn_priority() {
// NOTE: Does not use `figment::Jail` like the above because set env vars will leak into
Expand Down

0 comments on commit 66930b8

Please sign in to comment.