From 1cf6efa7405655233d94c28d9800703c763b24a5 Mon Sep 17 00:00:00 2001 From: vishalsodani Date: Tue, 18 Oct 2022 10:48:45 +0530 Subject: [PATCH] Add new error when using /keys without masterkey set --- meilisearch-http/src/extractors/authentication/error.rs | 3 +++ meilisearch-http/src/extractors/authentication/mod.rs | 2 +- meilisearch-types/src/error.rs | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/meilisearch-http/src/extractors/authentication/error.rs b/meilisearch-http/src/extractors/authentication/error.rs index bb78c53d0..7fa0319b8 100644 --- a/meilisearch-http/src/extractors/authentication/error.rs +++ b/meilisearch-http/src/extractors/authentication/error.rs @@ -9,6 +9,8 @@ pub enum AuthenticationError { // Triggered on configuration error. #[error("An internal error has occurred. `Irretrievable state`.")] IrretrievableState, + #[error("Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.")] + MissingMasterKey, } impl ErrorCode for AuthenticationError { @@ -17,6 +19,7 @@ impl ErrorCode for AuthenticationError { AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader, AuthenticationError::InvalidToken => Code::InvalidToken, AuthenticationError::IrretrievableState => Code::Internal, + AuthenticationError::MissingMasterKey => Code::MissingMasterKey, } } } diff --git a/meilisearch-http/src/extractors/authentication/mod.rs b/meilisearch-http/src/extractors/authentication/mod.rs index f6feabbbd..b9e2f711a 100644 --- a/meilisearch-http/src/extractors/authentication/mod.rs +++ b/meilisearch-http/src/extractors/authentication/mod.rs @@ -57,7 +57,7 @@ impl GuardedData { }), None => Err(AuthenticationError::IrretrievableState.into()), }, - None => Err(AuthenticationError::MissingAuthorizationHeader.into()), + None => Err(AuthenticationError::MissingMasterKey.into()), } } diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 56ac65f9e..147207aec 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -144,6 +144,7 @@ pub enum Code { InvalidStore, InvalidToken, MissingAuthorizationHeader, + MissingMasterKey, NoSpaceLeftOnDevice, DumpNotFound, TaskNotFound, @@ -231,6 +232,9 @@ impl Code { MissingAuthorizationHeader => { ErrCode::authentication("missing_authorization_header", StatusCode::UNAUTHORIZED) } + MissingMasterKey => { + ErrCode::authentication("missing_master_key", StatusCode::UNAUTHORIZED) + } TaskNotFound => ErrCode::invalid("task_not_found", StatusCode::NOT_FOUND), DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND), NoSpaceLeftOnDevice => {