From 89c40c83c303ac3ebce9dd79eaea2a84b9342917 Mon Sep 17 00:00:00 2001 From: vishalsodani Date: Thu, 27 Oct 2022 14:08:29 +0530 Subject: [PATCH] refactor code to avoid cloning --- meilisearch-http/src/extractors/authentication/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/meilisearch-http/src/extractors/authentication/mod.rs b/meilisearch-http/src/extractors/authentication/mod.rs index 7497d6377..d36db02c8 100644 --- a/meilisearch-http/src/extractors/authentication/mod.rs +++ b/meilisearch-http/src/extractors/authentication/mod.rs @@ -48,8 +48,7 @@ impl GuardedData { where P: Policy + 'static, { - let auth_clone = auth.clone(); - let master_key: Option<&String> = auth_clone.get_master_key(); + let missing_master_key = auth.get_master_key().is_none(); match Self::authenticate(auth, String::new(), None).await? { Some(filters) => match data { @@ -61,10 +60,10 @@ impl GuardedData { None => Err(AuthenticationError::IrretrievableState.into()), }, - None => match master_key { - Some(_) => Err(AuthenticationError::MissingAuthorizationHeader.into()), - None => Err(AuthenticationError::MissingMasterKey.into()), - }, + None if missing_master_key => { + Err(AuthenticationError::MissingMasterKey.into()) + } + None => Err(AuthenticationError::MissingAuthorizationHeader.into()), } }