@@ -19,6 +19,7 @@ use crate::{
19
19
client:: metadata_cache:: MetadataCache ,
20
20
} ;
21
21
22
+ pub use self :: transport:: SaslConfig ;
22
23
pub use self :: transport:: TlsConfig ;
23
24
24
25
mod topology;
@@ -45,6 +46,9 @@ pub enum Error {
45
46
46
47
#[ error( "all retries failed: {0}" ) ]
47
48
RetryFailed ( BackoffError ) ,
49
+
50
+ #[ error( "Sasl handshake failed: {0}" ) ]
51
+ SaslFailed ( #[ from] crate :: messenger:: SaslError ) ,
48
52
}
49
53
50
54
pub type Result < T , E = Error > = std:: result:: Result < T , E > ;
@@ -59,6 +63,7 @@ trait ConnectionHandler {
59
63
client_id : Arc < str > ,
60
64
tls_config : TlsConfig ,
61
65
socks5_proxy : Option < String > ,
66
+ sasl_config : Option < SaslConfig > ,
62
67
max_message_size : usize ,
63
68
) -> Result < Arc < Self :: R > > ;
64
69
}
@@ -121,6 +126,7 @@ impl ConnectionHandler for BrokerRepresentation {
121
126
client_id : Arc < str > ,
122
127
tls_config : TlsConfig ,
123
128
socks5_proxy : Option < String > ,
129
+ sasl_config : Option < SaslConfig > ,
124
130
max_message_size : usize ,
125
131
) -> Result < Arc < Self :: R > > {
126
132
let url = self . url ( ) ;
@@ -138,6 +144,11 @@ impl ConnectionHandler for BrokerRepresentation {
138
144
139
145
let mut messenger = Messenger :: new ( BufStream :: new ( transport) , max_message_size, client_id) ;
140
146
messenger. sync_versions ( ) . await ?;
147
+ if let Some ( sasl_config) = sasl_config {
148
+ messenger
149
+ . sasl_handshake ( sasl_config. mechanism ( ) , sasl_config. auth_bytes ( ) )
150
+ . await ?;
151
+ }
141
152
Ok ( Arc :: new ( messenger) )
142
153
}
143
154
}
@@ -177,6 +188,9 @@ pub struct BrokerConnector {
177
188
/// SOCKS5 proxy.
178
189
socks5_proxy : Option < String > ,
179
190
191
+ /// SASL Configuration
192
+ sasl_config : Option < SaslConfig > ,
193
+
180
194
/// Maximum message size for framing protocol.
181
195
max_message_size : usize ,
182
196
}
@@ -187,6 +201,7 @@ impl BrokerConnector {
187
201
client_id : Arc < str > ,
188
202
tls_config : TlsConfig ,
189
203
socks5_proxy : Option < String > ,
204
+ sasl_config : Option < SaslConfig > ,
190
205
max_message_size : usize ,
191
206
backoff_config : Arc < BackoffConfig > ,
192
207
) -> Self {
@@ -199,6 +214,7 @@ impl BrokerConnector {
199
214
backoff_config,
200
215
tls_config,
201
216
socks5_proxy,
217
+ sasl_config,
202
218
max_message_size,
203
219
}
204
220
}
@@ -294,6 +310,7 @@ impl BrokerConnector {
294
310
Arc :: clone ( & self . client_id ) ,
295
311
self . tls_config . clone ( ) ,
296
312
self . socks5_proxy . clone ( ) ,
313
+ self . sasl_config . clone ( ) ,
297
314
self . max_message_size ,
298
315
)
299
316
. await ?;
@@ -405,6 +422,7 @@ impl BrokerCache for &BrokerConnector {
405
422
& self . backoff_config ,
406
423
self . tls_config . clone ( ) ,
407
424
self . socks5_proxy . clone ( ) ,
425
+ self . sasl_config . clone ( ) ,
408
426
self . max_message_size ,
409
427
)
410
428
. await ?;
@@ -440,6 +458,7 @@ async fn connect_to_a_broker_with_retry<B>(
440
458
backoff_config : & BackoffConfig ,
441
459
tls_config : TlsConfig ,
442
460
socks5_proxy : Option < String > ,
461
+ sasl_config : Option < SaslConfig > ,
443
462
max_message_size : usize ,
444
463
) -> Result < Arc < B :: R > >
445
464
where
@@ -457,6 +476,7 @@ where
457
476
Arc :: clone ( & client_id) ,
458
477
tls_config. clone ( ) ,
459
478
socks5_proxy. clone ( ) ,
479
+ sasl_config. clone ( ) ,
460
480
max_message_size,
461
481
)
462
482
. await ;
@@ -773,6 +793,7 @@ mod tests {
773
793
_client_id : Arc < str > ,
774
794
_tls_config : TlsConfig ,
775
795
_socks5_proxy : Option < String > ,
796
+ _sasl_config : Option < SaslConfig > ,
776
797
_max_message_size : usize ,
777
798
) -> Result < Arc < Self :: R > > {
778
799
( self . conn ) ( )
@@ -801,6 +822,7 @@ mod tests {
801
822
Default :: default ( ) ,
802
823
Default :: default ( ) ,
803
824
Default :: default ( ) ,
825
+ Default :: default ( ) ,
804
826
)
805
827
. await
806
828
. unwrap ( ) ;
0 commit comments