Skip to content

Commit fdfdc0e

Browse files
Merge pull request #3867 from didier-wenzek/fix/inappropriate-warning
fix: remove inappropriate warning on MQTT connect
2 parents 5bd643f + 67c46f7 commit fdfdc0e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

crates/common/mqtt_channel/src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ pub struct BrokerConfig {
8080
pub authentication: Option<AuthenticationConfig>,
8181
}
8282

83+
impl BrokerConfig {
84+
pub fn is_using_tls(&self) -> bool {
85+
self.authentication
86+
.as_ref()
87+
.is_some_and(|a| a.is_using_tls())
88+
}
89+
}
90+
8391
/// MQTT certificate authentication configuration.
8492
///
8593
/// Intended to mirror authentication model found in the [mosquitto] MQTT
@@ -143,6 +151,10 @@ impl AuthenticationConfig {
143151
self.password = Some(password);
144152
}
145153

154+
pub fn is_using_tls(&self) -> bool {
155+
!self.cert_store.is_empty()
156+
}
157+
146158
pub fn to_rustls_client_config(&self) -> Result<Option<rustls::ClientConfig>, rustls::Error> {
147159
if self.cert_store.is_empty() {
148160
return Ok(None);

crates/common/mqtt_channel/src/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ impl Connection {
219219
const INSECURE_MQTT_PORT: u16 = 1883;
220220
const SECURE_MQTT_PORT: u16 = 8883;
221221

222-
if config.broker.port == INSECURE_MQTT_PORT && config.broker.authentication.is_some() {
222+
if config.broker.port == INSECURE_MQTT_PORT && config.broker.is_using_tls() {
223223
warn!(target: "MQTT", "Connecting on port 1883 for insecure MQTT using a TLS connection");
224224
}
225-
if config.broker.port == SECURE_MQTT_PORT && config.broker.authentication.is_none() {
225+
if config.broker.port == SECURE_MQTT_PORT && !config.broker.is_using_tls() {
226226
warn!(target: "MQTT", "Connecting on port 8883 for secure MQTT without a CA file");
227227
}
228228

0 commit comments

Comments
 (0)