@@ -192,16 +192,42 @@ impl RuntimeConfig {
192
192
let mut components_map: HashMap < String , HashMap < Authority , ParsedClientTlsOpts > > =
193
193
HashMap :: new ( ) ;
194
194
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
+
195
213
for opt_layer in self . opts_layers ( ) {
196
214
for opts in & opt_layer. client_tls_opts {
197
215
let parsed = parse_client_tls_opts ( opts) . context ( "parsing client tls options" ) ?;
198
216
for component_id in & opts. component_ids {
217
+ let existing_opts_for_component = components_map. get ( & component_id. to_string ( ) ) ;
199
218
#[ allow( clippy:: mutable_key_type) ]
200
219
let hostmap = parsed
201
220
. hosts
202
221
. clone ( )
203
222
. 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
+ } )
205
231
. collect :: < HashMap < Authority , ParsedClientTlsOpts > > ( ) ;
206
232
components_map. insert ( component_id. to_string ( ) . to_owned ( ) , hostmap) ;
207
233
}
@@ -728,7 +754,7 @@ ca_roots_file = "{}"
728
754
. unwrap ( ) ;
729
755
730
756
// 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 ( ) ) ;
732
758
}
733
759
734
760
fn merge_config_toml ( config : & mut RuntimeConfig , value : toml:: Value ) {
0 commit comments