Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added debug_credentials flag #915

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ pub struct SharedConfigValues {
)]
password_cmd: Option<String>,

/// Whether the credentials should be debugged.
#[structopt(long)]
#[serde(skip)]
debug_credentials: bool,

/// A script that gets evaluated in the user's shell when the song changes
#[structopt(visible_alias = "onevent", long, value_name = "string")]
#[serde(alias = "onevent")]
Expand Down Expand Up @@ -404,30 +409,25 @@ impl fmt::Debug for SharedConfigValues {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let placeholder = "taken out for privacy";

// TODO: somehow replace with a appropiate macro.
let password_value = if self.password.is_some() {
Some(&placeholder)
} else {
None
macro_rules! extract_credential {
( $e:expr ) => {
match $e {
Some(s) => match self.debug_credentials {
true => Some(s.as_str()),
false => Some(placeholder),
},
None => None,
}
};
};

let password_cmd_value = if self.password_cmd.is_some() {
Some(&placeholder)
} else {
None
};
let password_value = extract_credential!(&self.password);

let username_value = if self.username.is_some() {
Some(&placeholder)
} else {
None
};
let password_cmd_value = extract_credential!(&self.password_cmd);

let username_cmd_value = if self.username_cmd.is_some() {
Some(&placeholder)
} else {
None
};
let username_value = extract_credential!(&self.username);

let username_cmd_value = extract_credential!(&self.username_cmd);

f.debug_struct("SharedConfigValues")
.field("username", &username_value)
Expand Down