objectstore_server/auth/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug, PartialEq)]
5pub enum AuthError {
6 #[error("bad request: {0}")]
9 BadRequest(&'static str),
10
11 #[error("internal error: {0}")]
14 InternalError(String),
15
16 #[error("failed to decode token: {0}")]
18 ValidationFailure(#[from] jsonwebtoken::errors::Error),
19
20 #[error("failed to verify token")]
22 VerificationFailure,
23
24 #[error("operation not allowed")]
26 NotPermitted,
27
28 #[error("presigned URLs are not supported for this method")]
30 UnsupportedPresignedMethod,
31
32 #[error("unknown key")]
35 UnknownKey,
36}
37
38impl AuthError {
39 pub fn code(&self) -> &'static str {
41 match self {
42 Self::UnknownKey => "unknown_key",
43 Self::BadRequest(_) => "bad_request",
44 Self::NotPermitted => "not_permitted",
45 Self::InternalError(_) => "internal_error",
46 Self::ValidationFailure(_) => "validation_failure",
47 Self::VerificationFailure => "verification_failure",
48 Self::UnsupportedPresignedMethod => "unsupported_presigned_method",
49 }
50 }
51
52 pub fn log(&self, warn: bool) {
56 let code = self.code();
57 objectstore_metrics::count!("server.auth.failure", code = code);
58
59 if warn {
60 objectstore_log::warn!(code, reason=%self, "Auth failure");
61 } else {
62 objectstore_log::debug!(code, reason=%self, "Auth failure");
63 }
64 }
65}