Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ humantime-serde = "1.1.1"
indicatif = "0.18.4"
infer = { version = "0.22.0", default-features = false }
insta = "1.48.0"
jsonwebtoken = { version = "10.4.0", features = ["rust_crypto"] }
jsonwebtoken = { version = "11.1.0", features = ["rust_crypto"] }
lru = "0.19.0"
mediatype = "0.21.0"
mediatype = "0.23.0"
metrics = "0.24.6"
metrics-exporter-dogstatsd = "0.9.8"
multer = "3.1.0"
Expand Down
14 changes: 12 additions & 2 deletions clients/rust/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const DEFAULT_PERMISSIONS: [Permission; 3] = [
Permission::ObjectDelete,
];

/// An error creating or signing an auth token, such as an invalid key.
///
/// The message describes the cause. The underlying signing library is an implementation detail
/// and not part of the public API.
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct TokenError(jsonwebtoken::errors::Error);

/// Key configuration that will be used to sign tokens in Objectstore requests.
pub struct SecretKey {
/// A key ID that Objectstore must use to load the corresponding public key.
Expand Down Expand Up @@ -132,7 +140,8 @@ struct JwtClaims {
impl TokenGenerator {
/// Create a new [`TokenGenerator`] for a given key configuration.
pub fn new(secret_key: SecretKey) -> crate::Result<TokenGenerator> {
let encoding_key = EncodingKey::from_ed_pem(secret_key.secret_key.as_bytes())?;
let encoding_key =
EncodingKey::from_ed_pem(secret_key.secret_key.as_bytes()).map_err(TokenError)?;
Ok(TokenGenerator {
kid: secret_key.kid,
encoding_key,
Expand Down Expand Up @@ -256,6 +265,7 @@ impl TokenRequest<'_> {
let mut header = Header::new(Algorithm::EdDSA);
header.kid = Some(self.generator.kid.clone());

Ok(encode(&header, &claims, &self.generator.encoding_key)?)
let token = encode(&header, &claims, &self.generator.encoding_key).map_err(TokenError)?;
Ok(token)
}
}
4 changes: 2 additions & 2 deletions clients/rust/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum Error {
#[error("invalid scope: {0}")]
InvalidScope(#[from] objectstore_types::scope::InvalidScopeError),
/// Error when creating auth tokens, such as invalid keys.
#[error(transparent)]
TokenError(#[from] jsonwebtoken::errors::Error),
#[error("failed to create auth token: {0}")]
TokenError(#[from] crate::TokenError),
/// Error when the permissions requested for a token exceed those granted to the
/// [`TokenGenerator`](crate::TokenGenerator).
#[error("requested permissions not granted to this token generator: {escalated:?}")]
Expand Down
13 changes: 11 additions & 2 deletions objectstore-types/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ pub enum ExpiryAnchor {
Now,
}

/// A content type is not a valid [IANA Media
/// Type](https://www.iana.org/assignments/media-types/media-types.xhtml).
///
/// The message describes which part is malformed. The underlying parser is an implementation
/// detail and not part of the public API.
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct InvalidContentType(mediatype::MediaTypeError);

/// Errors that can happen dealing with metadata
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand All @@ -143,7 +152,7 @@ pub enum Error {
Compression,
/// The content type is invalid.
#[error("invalid content type")]
ContentType(#[from] mediatype::MediaTypeError),
ContentType(#[from] InvalidContentType),
/// The creation time is invalid.
#[error("invalid creation time")]
CreationTime(#[from] humantime::TimestampError),
Expand Down Expand Up @@ -598,7 +607,7 @@ impl Metadata {
/// Validates that `content_type` is a valid [IANA Media
/// Type](https://www.iana.org/assignments/media-types/media-types.xhtml).
fn validate_content_type(content_type: &str) -> Result<(), Error> {
mediatype::MediaType::parse(content_type)?;
mediatype::MediaType::parse(content_type).map_err(InvalidContentType)?;
Ok(())
}

Expand Down
Loading