Skip to content

Commit

Permalink
Replace redact with derive_more
Browse files Browse the repository at this point in the history
Next try. Get back the nicer debug output.
  • Loading branch information
tmatilai committed Dec 7, 2024
1 parent 602e18f commit 6b8cb44
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
38 changes: 28 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ strip = true
anyhow = "1.0"
btleplug = "0.11.6"
clap = { version = "4.5.21", features = ["derive", "env", "wrap_help"] }
derive_more = { version = "1.0.0", features = ["debug"] }
env_logger = "0.11.3"
futures = "0.3.19"
log = "0.4.17"
rand = "0.8.4"
redact = { version = "0.1.10", features = ["serde"] }
rumqttc = "0.24.0"
ruuvi-sensor-protocol = "0.6.1"
serde = { version = "1.0", features = ["derive"] }
Expand Down
13 changes: 7 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{collections::HashMap, fmt, fs, path::PathBuf, time::Duration};
use std::{collections::HashMap, fs, path::PathBuf, time::Duration};

use anyhow::{Context, Result};
use clap::{CommandFactory, Parser};
use derive_more::Debug;
use rand::Rng;
use redact::Secret;
use serde::Deserialize;
use serde_with::{formats::Flexible, serde_as, DisplayFromStr, DurationSeconds};
use sysinfo::System;
Expand All @@ -25,7 +25,8 @@ pub struct Mqtt {
#[serde(default = "default_mqtt_port")]
pub port: u16,
pub user: Option<String>,
pub password: Option<Secret<String>>,
#[debug("{}", fmt_secret(password))]
pub password: Option<String>,
#[serde(default = "default_mqtt_client_id")]
pub client_id: String,
#[serde_as(as = "DurationSeconds<u32, Flexible>")]
Expand Down Expand Up @@ -92,10 +93,10 @@ fn default_mqtt_base_topic() -> String {
String::from("ruuvi2mqtt")
}

fn fmt_secret(value: &Option<String>, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt_secret(value: &Option<String>) -> &str {
match value {
None => formatter.write_str("None"),
Some(_) => formatter.write_str("Some(<REDACTED>)"),
None => "None",
Some(_) => "Some(<REDACTED>)",
}
}

Expand Down
1 change: 0 additions & 1 deletion src/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl Mqtt {
let password = config
.password
.as_ref()
.map(|secret| secret.expose_secret())
.context("MQTT password not specified")?;
options.set_credentials(user, password);
}
Expand Down

0 comments on commit 6b8cb44

Please sign in to comment.