mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Merge #2922
2922: Add new error when using /keys without masterkey set r=ManyTheFish a=vishalsodani # Pull Request ## Related issue Fixes #2918 Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: vishalsodani <vishalsodani@rediffmail.com>
This commit is contained in:
commit
ab1800551f
4 changed files with 14 additions and 3 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ impl<P, D> GuardedData<P, D> {
|
|||
where
|
||||
P: Policy + 'static,
|
||||
{
|
||||
let missing_master_key = auth.get_master_key().is_none();
|
||||
|
||||
match Self::authenticate(auth, String::new(), None).await? {
|
||||
Some(filters) => match data {
|
||||
Some(data) => Ok(Self {
|
||||
|
@ -55,8 +57,10 @@ impl<P, D> GuardedData<P, D> {
|
|||
filters,
|
||||
_marker: PhantomData,
|
||||
}),
|
||||
|
||||
None => Err(AuthenticationError::IrretrievableState.into()),
|
||||
},
|
||||
None if missing_master_key => Err(AuthenticationError::MissingMasterKey.into()),
|
||||
None => Err(AuthenticationError::MissingAuthorizationHeader.into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue