add sensitive-field directives to config display

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-24 22:49:10 +00:00
parent b1b6dc0479
commit d59f68a51a
2 changed files with 31 additions and 5 deletions

View file

@ -502,6 +502,8 @@ pub struct Config {
/// YOU NEED TO EDIT THIS OR USE registration_token_file. /// YOU NEED TO EDIT THIS OR USE registration_token_file.
/// ///
/// example: "o&^uCtes4HPf0Vu@F20jQeeWE7" /// example: "o&^uCtes4HPf0Vu@F20jQeeWE7"
///
/// display: sensitive
pub registration_token: Option<String>, pub registration_token: Option<String>,
/// Path to a file on the system that gets read for the registration token. /// Path to a file on the system that gets read for the registration token.
@ -793,6 +795,8 @@ pub struct Config {
/// Static TURN password to provide the client if not using a shared secret /// Static TURN password to provide the client if not using a shared secret
/// ("turn_secret"). It is recommended to use a shared secret over static /// ("turn_secret"). It is recommended to use a shared secret over static
/// credentials. /// credentials.
///
/// display: sensitive
#[serde(default)] #[serde(default)]
pub turn_password: String, pub turn_password: String,
@ -814,6 +818,8 @@ pub struct Config {
/// ///
/// This is more secure, but if needed you can use traditional static /// This is more secure, but if needed you can use traditional static
/// username/password credentials. /// username/password credentials.
///
/// display: sensitive
#[serde(default)] #[serde(default)]
pub turn_secret: String, pub turn_secret: String,
@ -1111,6 +1117,8 @@ pub struct Config {
/// security purposes. /// security purposes.
/// ///
/// example: "F670$2CP@Hw8mG7RY1$%!#Ic7YA" /// example: "F670$2CP@Hw8mG7RY1$%!#Ic7YA"
///
/// display: sensitive
pub emergency_password: Option<String>, pub emergency_password: Option<String>,
/// default: "/_matrix/push/v1/notify" /// default: "/_matrix/push/v1/notify"
@ -1560,6 +1568,7 @@ pub struct Config {
/// Sentry reporting URL, if a custom one is desired. /// Sentry reporting URL, if a custom one is desired.
/// ///
/// display: sensitive
/// default: "https://fe2eb4536aa04949e28eff3128d64757@o4506996327251968.ingest.us.sentry.io/4506996334657536" /// default: "https://fe2eb4536aa04949e28eff3128d64757@o4506996327251968.ingest.us.sentry.io/4506996334657536"
#[serde(default = "default_sentry_endpoint")] #[serde(default = "default_sentry_endpoint")]
pub sentry_endpoint: Option<Url>, pub sentry_endpoint: Option<Url>,

View file

@ -15,7 +15,7 @@ use crate::{
const UNDOCUMENTED: &str = "# This item is undocumented. Please contribute documentation for it."; const UNDOCUMENTED: &str = "# This item is undocumented. Please contribute documentation for it.";
const HIDDEN: &[&str] = &["default"]; const HIDDEN: &[&str] = &["default", "display"];
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
pub(super) fn example_generator(input: ItemStruct, args: &[Meta]) -> Result<TokenStream> { pub(super) fn example_generator(input: ItemStruct, args: &[Meta]) -> Result<TokenStream> {
@ -121,10 +121,27 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
.expect("written to config file"); .expect("written to config file");
} }
let name = ident.to_string(); let display = get_doc_comment_line(field, "display");
summary.push(quote! { let display_directive = |key| {
writeln!(out, "| {} | {:?} |", #name, self.#ident)?; display
}); .as_ref()
.into_iter()
.flat_map(|display| display.split(' '))
.any(|directive| directive == key)
};
if !display_directive("hidden") {
let value = if display_directive("sensitive") {
quote! { "***********" }
} else {
quote! { format_args!("{:?}", self.#ident) }
};
let name = ident.to_string();
summary.push(quote! {
writeln!(out, "| {} | {} |", #name, #value)?;
});
}
} }
} }