Add new error when using /keys without masterkey set

This commit is contained in:
vishalsodani 2022-10-18 10:48:45 +05:30
parent 96acbf815d
commit 1cf6efa740
3 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,8 @@ pub enum AuthenticationError {
// Triggered on configuration error. // Triggered on configuration error.
#[error("An internal error has occurred. `Irretrievable state`.")] #[error("An internal error has occurred. `Irretrievable state`.")]
IrretrievableState, 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 { impl ErrorCode for AuthenticationError {
@ -17,6 +19,7 @@ impl ErrorCode for AuthenticationError {
AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader, AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader,
AuthenticationError::InvalidToken => Code::InvalidToken, AuthenticationError::InvalidToken => Code::InvalidToken,
AuthenticationError::IrretrievableState => Code::Internal, AuthenticationError::IrretrievableState => Code::Internal,
AuthenticationError::MissingMasterKey => Code::MissingMasterKey,
} }
} }
} }

View File

@ -57,7 +57,7 @@ impl<P, D> GuardedData<P, D> {
}), }),
None => Err(AuthenticationError::IrretrievableState.into()), None => Err(AuthenticationError::IrretrievableState.into()),
}, },
None => Err(AuthenticationError::MissingAuthorizationHeader.into()), None => Err(AuthenticationError::MissingMasterKey.into()),
} }
} }

View File

@ -144,6 +144,7 @@ pub enum Code {
InvalidStore, InvalidStore,
InvalidToken, InvalidToken,
MissingAuthorizationHeader, MissingAuthorizationHeader,
MissingMasterKey,
NoSpaceLeftOnDevice, NoSpaceLeftOnDevice,
DumpNotFound, DumpNotFound,
TaskNotFound, TaskNotFound,
@ -231,6 +232,9 @@ impl Code {
MissingAuthorizationHeader => { MissingAuthorizationHeader => {
ErrCode::authentication("missing_authorization_header", StatusCode::UNAUTHORIZED) ErrCode::authentication("missing_authorization_header", StatusCode::UNAUTHORIZED)
} }
MissingMasterKey => {
ErrCode::authentication("missing_master_key", StatusCode::UNAUTHORIZED)
}
TaskNotFound => ErrCode::invalid("task_not_found", StatusCode::NOT_FOUND), TaskNotFound => ErrCode::invalid("task_not_found", StatusCode::NOT_FOUND),
DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND), DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND),
NoSpaceLeftOnDevice => { NoSpaceLeftOnDevice => {