mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-30 20:57:35 +00:00
perf(keystone): avoid redundant KeystoneToken clones and tenant prefix allocs (#9753)
This commit is contained in:
committed by
GitHub
parent
798391899c
commit
551bfab922
@@ -108,10 +108,9 @@ impl KeystoneAuthProvider {
|
||||
}
|
||||
|
||||
// Cache token
|
||||
let keystone_token = Arc::new(keystone_token);
|
||||
if self.enable_cache {
|
||||
self.token_cache
|
||||
.insert(token.to_string(), Arc::new(keystone_token.clone()))
|
||||
.await;
|
||||
self.token_cache.insert(token.to_string(), Arc::clone(&keystone_token)).await;
|
||||
}
|
||||
|
||||
info!(
|
||||
@@ -163,8 +162,9 @@ impl KeystoneAuthProvider {
|
||||
let keystone_token = self.ec2_to_keystone_token(&ec2_cred).await?;
|
||||
|
||||
// Cache
|
||||
let keystone_token = Arc::new(keystone_token);
|
||||
if self.enable_cache {
|
||||
self.ec2_cache.insert(cache_key, Arc::new(keystone_token.clone())).await;
|
||||
self.ec2_cache.insert(cache_key, Arc::clone(&keystone_token)).await;
|
||||
}
|
||||
|
||||
info!(
|
||||
@@ -194,7 +194,7 @@ impl KeystoneAuthProvider {
|
||||
let groups = Some(token.roles.clone());
|
||||
|
||||
// Add Keystone-specific claims
|
||||
let mut claims = HashMap::new();
|
||||
let mut claims = HashMap::with_capacity(8);
|
||||
claims.insert("keystone_user_id".to_string(), json!(token.user_id));
|
||||
claims.insert("keystone_username".to_string(), json!(token.username));
|
||||
if let Some(ref proj_id) = token.project_id {
|
||||
|
||||
@@ -97,13 +97,12 @@ impl KeystoneIdentityMapper {
|
||||
return prefixed_bucket.to_string();
|
||||
}
|
||||
|
||||
if let Some(proj_id) = project_id {
|
||||
let prefix = format!("{}:", proj_id);
|
||||
if prefixed_bucket.starts_with(&prefix) {
|
||||
let unprefixed = prefixed_bucket[prefix.len()..].to_string();
|
||||
debug!("Removed tenant prefix: {} -> {}", prefixed_bucket, unprefixed);
|
||||
return unprefixed;
|
||||
}
|
||||
if let Some(proj_id) = project_id
|
||||
&& let Some(rest) = prefixed_bucket.strip_prefix(proj_id).and_then(|rest| rest.strip_prefix(':'))
|
||||
{
|
||||
let unprefixed = rest.to_string();
|
||||
debug!("Removed tenant prefix: {} -> {}", prefixed_bucket, unprefixed);
|
||||
return unprefixed;
|
||||
}
|
||||
|
||||
prefixed_bucket.to_string()
|
||||
@@ -116,8 +115,7 @@ impl KeystoneIdentityMapper {
|
||||
}
|
||||
|
||||
if let Some(proj_id) = project_id {
|
||||
let prefix = format!("{}:", proj_id);
|
||||
bucket.starts_with(&prefix)
|
||||
bucket.strip_prefix(proj_id).is_some_and(|rest| rest.starts_with(':'))
|
||||
} else {
|
||||
!bucket.contains(':') // No project ID, only unprefixed buckets
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user