Fix most of the easy issues

This commit is contained in:
Clément Renault 2025-06-30 18:31:32 +02:00
parent 7219299436
commit 85037352b9
No known key found for this signature in database
GPG key ID: F250A4C4E3AE5F5F
6 changed files with 39 additions and 16 deletions

View file

@ -371,7 +371,10 @@ impl From<Details> for DetailsView {
}
Details::Export { url, api_key, payload_size, indexes } => DetailsView {
url: Some(url),
api_key,
api_key: api_key.map(|mut api_key| {
hide_secret(&mut api_key);
api_key
}),
payload_size: payload_size
.map(|ps| ps.get_appropriate_unit(UnitType::Both).to_string()),
indexes: Some(
@ -390,3 +393,21 @@ impl From<Details> for DetailsView {
}
}
}
// We definitely need to factorize the code to hide the secret key
fn hide_secret(secret: &mut String) {
match secret.len() {
x if x < 10 => {
secret.replace_range(.., "XXX...");
}
x if x < 20 => {
secret.replace_range(2.., "XXXX...");
}
x if x < 30 => {
secret.replace_range(3.., "XXXXX...");
}
_x => {
secret.replace_range(5.., "XXXXXX...");
}
}
}