mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-11 15:46:53 +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:
@@ -47,6 +47,8 @@ pub mod crypto;
|
||||
#[cfg(feature = "compress")]
|
||||
pub mod compress;
|
||||
|
||||
pub mod logging;
|
||||
|
||||
#[cfg(feature = "path")]
|
||||
pub mod dirs;
|
||||
|
||||
@@ -74,3 +76,4 @@ mod dunce;
|
||||
pub use dunce::*;
|
||||
mod envs;
|
||||
pub use envs::*;
|
||||
pub use logging::*;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2024 RustFS Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[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::MaskedAccessKey;
|
||||
|
||||
#[test]
|
||||
fn masks_short_values() {
|
||||
assert_eq!(MaskedAccessKey("").to_string(), "");
|
||||
assert_eq!(MaskedAccessKey("a").to_string(), "***");
|
||||
assert_eq!(MaskedAccessKey("abcd").to_string(), "***");
|
||||
assert_eq!(MaskedAccessKey("abcde").to_string(), "a***e");
|
||||
assert_eq!(MaskedAccessKey("abcdefgh").to_string(), "a***h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn masks_long_values() {
|
||||
assert_eq!(MaskedAccessKey("AKIAIOSFODNN7EXAMPLE").to_string(), "AKIA***MPLE");
|
||||
assert_eq!(format!("{:?}", MaskedAccessKey("keystone:user-1234")), "keys***1234");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user