Improve diff
This commit is contained in:
parent
792f57dc7e
commit
e5373ab2bb
23 changed files with 312 additions and 220 deletions
|
|
@ -20,15 +20,7 @@ where
|
|||
let mut user_token_map = BiHashMap::new();
|
||||
for user in &users {
|
||||
if let Some(existing_name) = user_token_map.get_by_right(&user.token) {
|
||||
let redacted = if user.token.len() > 6 {
|
||||
format!(
|
||||
"{}...{}",
|
||||
&user.token[..3],
|
||||
&user.token[user.token.len() - 3..]
|
||||
)
|
||||
} else {
|
||||
"***".to_owned()
|
||||
};
|
||||
let redacted = redact_token(&user.token);
|
||||
return Err(D::Error::custom(format!(
|
||||
"Duplicate user token found: `{redacted}` for users `{}` and `{}`. User tokens \
|
||||
must be unique.",
|
||||
|
|
@ -49,6 +41,23 @@ where
|
|||
Ok(users)
|
||||
}
|
||||
|
||||
fn redact_token(token: &str) -> String {
|
||||
if token.chars().count() <= 6 {
|
||||
return "***".to_owned();
|
||||
}
|
||||
|
||||
let prefix = token.chars().take(3).collect::<String>();
|
||||
let suffix = token
|
||||
.chars()
|
||||
.rev()
|
||||
.take(3)
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.rev()
|
||||
.collect::<String>();
|
||||
format!("{prefix}...{suffix}")
|
||||
}
|
||||
|
||||
impl UserConfig {
|
||||
pub fn get_user(&self, token: &str) -> Option<&User> {
|
||||
self.user_configs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue