Skip to content

Commit

Permalink
Attempt skipping passwords in mqtt config
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumEntangledAndy committed Aug 3, 2024
1 parent 7158943 commit 5fc9bc2
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 56 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "neolink"
description = "A standards-compliant bridge to Reolink IP cameras"
version = "0.6.3-rc.2"
version = "0.6.3-rc.3"
authors = ["George Hilliard <[email protected]>", "Andrew King <[email protected]>"]
edition = "2018"
license = "AGPL-3.0-or-later"
Expand Down Expand Up @@ -30,7 +30,7 @@ gstreamer-rtsp-server = { version = "0.23.0", features = ["v1_20"], optional = t
heck = "0.5.0"
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
md5 = {version = "0.7.0", optional = true}
neolink_core = { path = "crates/core", version = "0.6.3-rc.2" }
neolink_core = { path = "crates/core", version = "0.6.3-rc.3" }
once_cell = "1.19.0"
quick-xml = { version = "0.36.1", features = ["serialize"] }
regex = "1.7.3"
Expand Down Expand Up @@ -62,4 +62,4 @@ pushnoti = [
"dep:fcm-push-listener",
"dep:dirs",
"dep:md5"
]
]
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "neolink_core"
description = "Core services and structure for Reolink IP cameras"
version = "0.6.3-rc.2"
version = "0.6.3-rc.3"
authors = ["George Hilliard <[email protected]>", "Andrew King <[email protected]>"]
edition = "2018"
license = "AGPL-3.0-or-later"
Expand Down
2 changes: 1 addition & 1 deletion crates/decoder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "neolink_decoder"
description = "A cli decoder for the AES encrypted packets"
version = "0.6.3-rc.2"
version = "0.6.3-rc.3"
authors = ["Andrew King <[email protected]>"]
edition = "2018"
license = "AGPL-3.0-or-later"
Expand Down
4 changes: 2 additions & 2 deletions crates/pushnoti/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pushnoti"
version = "0.6.3-rc.2"
version = "0.6.3-rc.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -12,7 +12,7 @@ env_logger = "0.10.0"
fcm-push-listener = "2.0.1"
lazy_static = "1.4.0"
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
neolink_core = { path = "../core", version = "0.6.3-rc.2" }
neolink_core = { path = "../core", version = "0.6.3-rc.3" }
regex = "1.8.1"
serde = "1.0.163"
tokio = { version = "1.28.1", features = ["full"] }
Expand Down
12 changes: 6 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub(crate) struct MqttServerConfig {

pub(crate) port: u16,

#[serde(default)]
#[serde(default, skip_serializing)]
pub(crate) credentials: Option<(String, String)>,

#[serde(default)]
#[serde(default, skip_serializing)]
pub(crate) ca: Option<std::path::PathBuf>,

#[serde(default)]
#[serde(default, skip_serializing)]
pub(crate) client_auth: Option<(std::path::PathBuf, std::path::PathBuf)>,
}

Expand Down Expand Up @@ -139,7 +139,7 @@ pub(crate) struct CameraConfig {

pub(crate) username: String,

#[serde(alias = "pass")]
#[serde(alias = "pass", skip_serializing, default)]
pub(crate) password: Option<String>,

#[serde(default = "default_stream")]
Expand Down Expand Up @@ -226,8 +226,8 @@ pub(crate) struct UserConfig {
#[serde(alias = "username")]
pub(crate) name: String,

#[serde(alias = "password")]
pub(crate) pass: String,
#[serde(alias = "password", skip_serializing, default)]
pub(crate) pass: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone, Validate, PartialEq, Eq)]
Expand Down
35 changes: 0 additions & 35 deletions src/mqtt/app.rs

This file was deleted.

35 changes: 34 additions & 1 deletion src/mqtt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,40 @@ pub(crate) async fn main(_: Opt, reactor: NeoReactor) -> Result<()> {
.await?;
continue;
}
let config = config?;
let curr_config = thread_config.borrow().clone();
let mut config = config?;

// Fill in skipped passwords
if let (Some(mqtt), Some(curr_mqtt)) = (config.mqtt.as_mut(), curr_config.mqtt.as_ref()) {
if mqtt.credentials.is_none() {
mqtt.credentials = curr_mqtt.credentials.clone();
}
if mqtt.ca.is_none() {
mqtt.ca = curr_mqtt.ca.clone();
}
if mqtt.client_auth.is_none() {
mqtt.client_auth = curr_mqtt.client_auth.clone();
}
}
for cam in config.cameras.iter_mut() {
let name = cam.name.clone();
let cur_cam = curr_config.cameras.iter().find(|c| c.name == name);
if let Some(cur_cam) = cur_cam.as_ref() {
if cam.password.is_none() {
cam.password = cur_cam.password.clone();
}
}
}
for user in config.users.iter_mut() {
let name = user.name.clone();
let cur_user = curr_config.users.iter().find(|c| c.name == name);
if let Some(cur_user) = cur_user.as_ref() {
if user.pass.is_none() {
user.pass = cur_user.pass.clone();
}
}
}
// Passwords should now be restored if they were not set

let validate = config.validate().with_context(|| {
format!("Failed to validate the MQTT {:?} config file", msg.topic)
Expand Down
3 changes: 2 additions & 1 deletion src/rtsp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ async fn apply_users(rtsp: &NeoRtspServer, curr_users: &HashSet<UserConfig>) ->
// Add those missing
for user in curr_users.iter() {
log::debug!("Adding user {} to rtsp server", user.name);
rtsp.add_user(&user.name, &user.pass).await?;
rtsp.add_user(&user.name, &user.pass.clone().unwrap_or_default())
.await?;
}
// Remove unused
let rtsp_users = rtsp.get_users().await?;
Expand Down

0 comments on commit 5fc9bc2

Please sign in to comment.