From 9dcc5232a6cc9cf58b1e17c02120bc782274f9f2 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 25 Mar 2025 13:07:45 +0100 Subject: [PATCH] admin api: use fast local reads for token verification --- src/api/admin/api_server.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs index a214dfa7..97b1fe0d 100644 --- a/src/api/admin/api_server.rs +++ b/src/api/admin/api_server.rs @@ -169,8 +169,7 @@ impl AdminApiServer { }; if token_required { - verify_authorization(&self.garage, global_token_hash, auth_header, request.name()) - .await?; + verify_authorization(&self.garage, global_token_hash, auth_header, request.name())?; } match request { @@ -245,7 +244,7 @@ fn hash_bearer_token(token: &str) -> String { .to_string() } -async fn verify_authorization( +fn verify_authorization( garage: &Garage, global_token_hash: Option<&str>, auth_header: Option, @@ -271,8 +270,7 @@ async fn verify_authorization( let token_hash_string = if let Some((prefix, _)) = token.split_once('.') { garage .admin_token_table - .get(&EmptyKey, &prefix.to_string()) - .await? + .get_local(&EmptyKey, &prefix.to_string())? .and_then(|k| k.state.into_option()) .filter(|p| { p.expiration