mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 20:06:37 +00:00
refactor(logging): standardize protocol and observability events (#3419)
* refactor(logging): standardize object capacity events * refactor(logging): standardize protocol server events * refactor(logging): standardize swift protocol events * refactor(logging): standardize observability events * refactor(logging): move masking helper and extend guardrails
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use rustfs_security_governance::{RedactionLevel, RedactionPolicyError, RedactionRule, validate_redaction_rules};
|
||||
use std::fmt;
|
||||
pub use rustfs_utils::MaskedAccessKey;
|
||||
|
||||
pub const REDACTED_LOG_VALUE: &str = "***redacted***";
|
||||
|
||||
@@ -56,41 +56,6 @@ pub fn redacted_optional_log_value(value: Option<&str>) -> Option<&'static str>
|
||||
value.map(redacted_log_value)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MaskedAccessKey<'a>(pub &'a str);
|
||||
|
||||
impl fmt::Display for MaskedAccessKey<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let value = self.0;
|
||||
if value.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let chars: Vec<char> = value.chars().collect();
|
||||
match chars.len() {
|
||||
0 => Ok(()),
|
||||
1..=4 => f.write_str("***"),
|
||||
5..=8 => write!(f, "{}***{}", chars[0], chars[chars.len() - 1]),
|
||||
len => {
|
||||
for ch in &chars[..4] {
|
||||
write!(f, "{ch}")?;
|
||||
}
|
||||
f.write_str("***")?;
|
||||
for ch in &chars[len - 4..] {
|
||||
write!(f, "{ch}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for MaskedAccessKey<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user