Skip to content

Commit 8f66682

Browse files
committed
change tls opts logic to ensure first entry wins
Signed-off-by: Rajat Jindal <[email protected]>
1 parent cd2c096 commit 8f66682

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

crates/trigger/src/runtime_config.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,42 @@ impl RuntimeConfig {
192192
let mut components_map: HashMap<String, HashMap<Authority, ParsedClientTlsOpts>> =
193193
HashMap::new();
194194

195+
// if available, use the existing client tls opts value for a given component-id and host-authority
196+
// to ensure first-one wins incase of duplicate options
197+
fn use_existing_if_available(
198+
existing_opts: Option<&HashMap<Authority, ParsedClientTlsOpts>>,
199+
host: Authority,
200+
newopts: ParsedClientTlsOpts,
201+
) -> Option<(Authority, ParsedClientTlsOpts)> {
202+
match existing_opts {
203+
None => Some((host, newopts.clone())),
204+
Some(opts) => match opts.get(&host) {
205+
Some(existing_opts_for_component_and_host) => {
206+
Some((host, existing_opts_for_component_and_host.to_owned()))
207+
}
208+
None => Some((host, newopts.clone())),
209+
},
210+
}
211+
}
212+
195213
for opt_layer in self.opts_layers() {
196214
for opts in &opt_layer.client_tls_opts {
197215
let parsed = parse_client_tls_opts(opts).context("parsing client tls options")?;
198216
for component_id in &opts.component_ids {
217+
let existing_opts_for_component = components_map.get(&component_id.to_string());
199218
#[allow(clippy::mutable_key_type)]
200219
let hostmap = parsed
201220
.hosts
202221
.clone()
203222
.into_iter()
204-
.map(|host| (host, parsed.clone()))
223+
.into_iter()
224+
.filter_map(|host| {
225+
use_existing_if_available(
226+
existing_opts_for_component,
227+
host,
228+
parsed.clone(),
229+
)
230+
})
205231
.collect::<HashMap<Authority, ParsedClientTlsOpts>>();
206232
components_map.insert(component_id.to_string().to_owned(), hostmap);
207233
}
@@ -728,7 +754,7 @@ ca_roots_file = "{}"
728754
.unwrap();
729755

730756
// verify that the last client_tls block wins for same component-id and host combination
731-
assert!(component_no1_host_client_tls_opts.custom_root_ca.is_some());
757+
assert!(component_no1_host_client_tls_opts.custom_root_ca.is_none());
732758
}
733759

734760
fn merge_config_toml(config: &mut RuntimeConfig, value: toml::Value) {

0 commit comments

Comments
 (0)