fix things up

This commit is contained in:
Alex 2025-01-31 18:34:57 +01:00
parent 9fa20d45be
commit 84f1db91c4
34 changed files with 130 additions and 102 deletions

View file

@ -69,3 +69,6 @@ quick-xml.workspace = true
opentelemetry.workspace = true opentelemetry.workspace = true
opentelemetry-prometheus = { workspace = true, optional = true } opentelemetry-prometheus = { workspace = true, optional = true }
prometheus = { workspace = true, optional = true } prometheus = { workspace = true, optional = true }
[features]
metrics = [ "opentelemetry-prometheus", "prometheus", "garage_api_common/metrics" ]

View file

@ -21,6 +21,7 @@ use garage_util::error::Error as GarageError;
use garage_util::socket_address::UnixOrTCPSocketAddress; use garage_util::socket_address::UnixOrTCPSocketAddress;
use garage_api_common::generic_server::*; use garage_api_common::generic_server::*;
use garage_api_common::helpers::*;
use crate::bucket::*; use crate::bucket::*;
use crate::cluster::*; use crate::cluster::*;
@ -28,7 +29,6 @@ use crate::error::*;
use crate::key::*; use crate::key::*;
use crate::router_v0; use crate::router_v0;
use crate::router_v1::{Authorization, Endpoint}; use crate::router_v1::{Authorization, Endpoint};
use garage_api_common::helpers::*;
pub type ResBody = BoxBody<Error>; pub type ResBody = BoxBody<Error>;

View file

@ -17,11 +17,12 @@ use garage_model::permission::*;
use garage_model::s3::mpu_table; use garage_model::s3::mpu_table;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_api_common::common_error::CommonError;
use garage_api_common::helpers::*;
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::error::*; use crate::error::*;
use crate::key::ApiBucketKeyPerm; use crate::key::ApiBucketKeyPerm;
use garage_api_common::common_error::CommonError;
use garage_api_common::helpers::*;
pub async fn handle_list_buckets(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> { pub async fn handle_list_buckets(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> {
let buckets = garage let buckets = garage

View file

@ -12,9 +12,10 @@ use garage_rpc::layout;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_api_common::helpers::{json_ok_response, parse_json_body};
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::error::*; use crate::error::*;
use garage_api_common::helpers::{json_ok_response, parse_json_body};
pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> { pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> {
let layout = garage.system.cluster_layout(); let layout = garage.system.cluster_layout();

View file

@ -6,7 +6,7 @@ use hyper::{HeaderMap, StatusCode};
pub use garage_model::helper::error::Error as HelperError; pub use garage_model::helper::error::Error as HelperError;
use garage_api_common::common_error::CommonError; use garage_api_common::common_error::{commonErrorDerivative, CommonError};
pub use garage_api_common::common_error::{ pub use garage_api_common::common_error::{
CommonErrorDerivative, OkOrBadRequest, OkOrInternalError, CommonErrorDerivative, OkOrBadRequest, OkOrInternalError,
}; };
@ -18,7 +18,7 @@ use garage_api_common::helpers::*;
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
Common(CommonError), Common(#[error(source)] CommonError),
// Category: cannot process // Category: cannot process
/// The API access key does not exist /// The API access key does not exist
@ -33,14 +33,7 @@ pub enum Error {
KeyAlreadyExists(String), KeyAlreadyExists(String),
} }
impl<T> From<T> for Error commonErrorDerivative!(Error);
where
CommonError: From<T>,
{
fn from(err: T) -> Self {
Error::Common(CommonError::from(err))
}
}
/// FIXME: helper errors are transformed into their corresponding variants /// FIXME: helper errors are transformed into their corresponding variants
/// in the Error struct, but in many case a helper error should be considered /// in the Error struct, but in many case a helper error should be considered
@ -55,8 +48,6 @@ impl From<HelperError> for Error {
} }
} }
impl CommonErrorDerivative for Error {}
impl Error { impl Error {
fn code(&self) -> &'static str { fn code(&self) -> &'static str {
match self { match self {

View file

@ -9,9 +9,10 @@ use garage_table::*;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_model::key_table::*; use garage_model::key_table::*;
use garage_api_common::helpers::*;
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::error::*; use crate::error::*;
use garage_api_common::helpers::*;
pub async fn handle_list_keys(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> { pub async fn handle_list_keys(garage: &Arc<Garage>) -> Result<Response<ResBody>, Error> {
let res = garage let res = garage

View file

@ -2,9 +2,10 @@ use std::borrow::Cow;
use hyper::{Method, Request}; use hyper::{Method, Request};
use crate::error::*;
use garage_api_common::router_macros::*; use garage_api_common::router_macros::*;
use crate::error::*;
router_match! {@func router_match! {@func
/// List of all Admin API endpoints. /// List of all Admin API endpoints.

View file

@ -2,9 +2,10 @@ use std::borrow::Cow;
use hyper::{Method, Request}; use hyper::{Method, Request};
use garage_api_common::router_macros::*;
use crate::error::*; use crate::error::*;
use crate::router_v0; use crate::router_v0;
use garage_api_common::router_macros::*;
pub enum Authorization { pub enum Authorization {
None, None,

View file

@ -57,6 +57,35 @@ pub enum CommonError {
InvalidBucketName(String), InvalidBucketName(String),
} }
#[macro_export]
macro_rules! commonErrorDerivative {
( $error_struct: ident ) => {
impl From<garage_util::error::Error> for $error_struct {
fn from(err: garage_util::error::Error) -> Self {
Self::Common(CommonError::InternalError(err))
}
}
impl From<http::Error> for $error_struct {
fn from(err: http::Error) -> Self {
Self::Common(CommonError::Http(err))
}
}
impl From<hyper::Error> for $error_struct {
fn from(err: hyper::Error) -> Self {
Self::Common(CommonError::Hyper(err))
}
}
impl From<hyper::header::ToStrError> for $error_struct {
fn from(err: hyper::header::ToStrError) -> Self {
Self::Common(CommonError::InvalidHeader(err))
}
}
impl CommonErrorDerivative for $error_struct {}
};
}
pub use commonErrorDerivative;
impl CommonError { impl CommonError {
pub fn http_status_code(&self) -> StatusCode { pub fn http_status_code(&self) -> StatusCode {
match self { match self {

View file

@ -12,17 +12,16 @@ use garage_util::socket_address::UnixOrTCPSocketAddress;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use crate::error::*;
use garage_api_common::generic_server::*; use garage_api_common::generic_server::*;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_request; use garage_api_common::signature::verify_request;
use garage_api_s3::cors::*;
use crate::batch::*; use crate::batch::*;
use crate::error::*;
use crate::index::*; use crate::index::*;
use crate::item::*; use crate::item::*;
use crate::router::Endpoint; use crate::router::Endpoint;
use garage_api_common::helpers::*;
use garage_api_s3::cors::*;
pub use garage_api_common::signature::streaming::ReqBody; pub use garage_api_common::signature::streaming::ReqBody;
pub type ResBody = BoxBody<Error>; pub type ResBody = BoxBody<Error>;
@ -31,7 +30,7 @@ pub struct K2VApiServer {
garage: Arc<Garage>, garage: Arc<Garage>,
} }
pub(crate) struct K2VApiEndpoint { pub struct K2VApiEndpoint {
bucket_name: String, bucket_name: String,
endpoint: Endpoint, endpoint: Endpoint,
} }

View file

@ -6,12 +6,13 @@ use garage_table::{EnumerationOrder, TableSchema};
use garage_model::k2v::item_table::*; use garage_model::k2v::item_table::*;
use crate::k2v::api_server::{ReqBody, ResBody};
use crate::k2v::error::*;
use crate::k2v::item::parse_causality_token;
use crate::k2v::range::read_range;
use garage_api_common::helpers::*; use garage_api_common::helpers::*;
use crate::api_server::{ReqBody, ResBody};
use crate::error::*;
use crate::item::parse_causality_token;
use crate::range::read_range;
pub async fn handle_insert_batch( pub async fn handle_insert_batch(
ctx: ReqCtx, ctx: ReqCtx,
req: Request<ReqBody>, req: Request<ReqBody>,

View file

@ -2,7 +2,7 @@ use err_derive::Error;
use hyper::header::HeaderValue; use hyper::header::HeaderValue;
use hyper::{HeaderMap, StatusCode}; use hyper::{HeaderMap, StatusCode};
use garage_api_common::common_error::CommonError; use garage_api_common::common_error::{commonErrorDerivative, CommonError};
pub(crate) use garage_api_common::common_error::{helper_error_as_internal, pass_helper_error}; pub(crate) use garage_api_common::common_error::{helper_error_as_internal, pass_helper_error};
pub use garage_api_common::common_error::{ pub use garage_api_common::common_error::{
CommonErrorDerivative, OkOrBadRequest, OkOrInternalError, CommonErrorDerivative, OkOrBadRequest, OkOrInternalError,
@ -16,7 +16,7 @@ use garage_api_common::signature::error::Error as SignatureError;
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
Common(CommonError), Common(#[error(source)] CommonError),
// Category: cannot process // Category: cannot process
/// Authorization Header Malformed /// Authorization Header Malformed
@ -44,16 +44,7 @@ pub enum Error {
InvalidUtf8Str(#[error(source)] std::str::Utf8Error), InvalidUtf8Str(#[error(source)] std::str::Utf8Error),
} }
impl<T> From<T> for Error commonErrorDerivative!(Error);
where
CommonError: From<T>,
{
fn from(err: T) -> Self {
Error::Common(CommonError::from(err))
}
}
impl CommonErrorDerivative for Error {}
impl From<SignatureError> for Error { impl From<SignatureError> for Error {
fn from(err: SignatureError) -> Self { fn from(err: SignatureError) -> Self {

View file

@ -5,10 +5,11 @@ use garage_table::util::*;
use garage_model::k2v::item_table::{BYTES, CONFLICTS, ENTRIES, VALUES}; use garage_model::k2v::item_table::{BYTES, CONFLICTS, ENTRIES, VALUES};
use garage_api_common::helpers::*;
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::error::*; use crate::error::*;
use crate::range::read_range; use crate::range::read_range;
use garage_api_common::helpers::*;
pub async fn handle_read_index( pub async fn handle_read_index(
ctx: ReqCtx, ctx: ReqCtx,

View file

@ -6,9 +6,10 @@ use hyper::{Request, Response, StatusCode};
use garage_model::k2v::causality::*; use garage_model::k2v::causality::*;
use garage_model::k2v::item_table::*; use garage_model::k2v::item_table::*;
use garage_api_common::helpers::*;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::error::*; use crate::error::*;
use garage_api_common::helpers::*;
pub const X_GARAGE_CAUSALITY_TOKEN: &str = "X-Garage-Causality-Token"; pub const X_GARAGE_CAUSALITY_TOKEN: &str = "X-Garage-Causality-Token";

View file

@ -7,9 +7,10 @@ use std::sync::Arc;
use garage_table::replication::TableShardedReplication; use garage_table::replication::TableShardedReplication;
use garage_table::*; use garage_table::*;
use crate::error::*;
use garage_api_common::helpers::key_after_prefix; use garage_api_common::helpers::key_after_prefix;
use crate::error::*;
/// Read range in a Garage table. /// Read range in a Garage table.
/// Returns (entries, more?, nextStart) /// Returns (entries, more?, nextStart)
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]

View file

@ -14,15 +14,15 @@ use garage_util::socket_address::UnixOrTCPSocketAddress;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_model::key_table::Key; use garage_model::key_table::Key;
use crate::error::*;
use garage_api_common::generic_server::*; use garage_api_common::generic_server::*;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_request; use garage_api_common::signature::verify_request;
use crate::bucket::*; use crate::bucket::*;
use crate::copy::*; use crate::copy::*;
use crate::cors::*; use crate::cors::*;
use crate::delete::*; use crate::delete::*;
use crate::error::*;
use crate::get::*; use crate::get::*;
use crate::lifecycle::*; use crate::lifecycle::*;
use crate::list::*; use crate::list::*;
@ -31,7 +31,6 @@ use crate::post_object::handle_post_object;
use crate::put::*; use crate::put::*;
use crate::router::Endpoint; use crate::router::Endpoint;
use crate::website::*; use crate::website::*;
use garage_api_common::helpers::*;
pub use garage_api_common::signature::streaming::ReqBody; pub use garage_api_common::signature::streaming::ReqBody;
pub type ResBody = BoxBody<Error>; pub type ResBody = BoxBody<Error>;
@ -40,7 +39,7 @@ pub struct S3ApiServer {
garage: Arc<Garage>, garage: Arc<Garage>,
} }
pub(crate) struct S3ApiEndpoint { pub struct S3ApiEndpoint {
bucket_name: Option<String>, bucket_name: Option<String>,
endpoint: Endpoint, endpoint: Endpoint,
} }

View file

@ -13,13 +13,14 @@ use garage_util::crdt::*;
use garage_util::data::*; use garage_util::data::*;
use garage_util::time::*; use garage_util::time::*;
use crate::api_server::{ReqBody, ResBody};
use crate::error::*;
use crate::xml as s3_xml;
use garage_api_common::common_error::CommonError; use garage_api_common::common_error::CommonError;
use garage_api_common::helpers::*; use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content; use garage_api_common::signature::verify_signed_content;
use crate::api_server::{ReqBody, ResBody};
use crate::error::*;
use crate::xml as s3_xml;
pub fn handle_get_bucket_location(ctx: ReqCtx) -> Result<Response<ResBody>, Error> { pub fn handle_get_bucket_location(ctx: ReqCtx) -> Result<Response<ResBody>, Error> {
let ReqCtx { garage, .. } = ctx; let ReqCtx { garage, .. } = ctx;
let loc = s3_xml::LocationConstraint { let loc = s3_xml::LocationConstraint {

View file

@ -20,6 +20,8 @@ use garage_model::s3::mpu_table::*;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_model::s3::version_table::*; use garage_model::s3::version_table::*;
use garage_api_common::helpers::*;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::checksum::*; use crate::checksum::*;
use crate::encryption::EncryptionParams; use crate::encryption::EncryptionParams;
@ -28,7 +30,6 @@ use crate::get::full_object_byte_stream;
use crate::multipart; use crate::multipart;
use crate::put::{get_headers, save_stream, ChecksumMode, SaveStreamResult}; use crate::put::{get_headers, save_stream, ChecksumMode, SaveStreamResult};
use crate::xml::{self as s3_xml, xmlns_tag}; use crate::xml::{self as s3_xml, xmlns_tag};
use garage_api_common::helpers::*;
// -------- CopyObject --------- // -------- CopyObject ---------

View file

@ -15,16 +15,17 @@ use http_body_util::BodyExt;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::api_server::{ReqBody, ResBody}; use garage_model::bucket_table::{Bucket, BucketParams, CorsRule as GarageCorsRule};
use crate::error::*; use garage_model::garage::Garage;
use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value}; use garage_util::data::*;
use garage_api_common::common_error::{helper_error_as_internal, CommonError}; use garage_api_common::common_error::{helper_error_as_internal, CommonError};
use garage_api_common::helpers::*; use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content; use garage_api_common::signature::verify_signed_content;
use garage_model::bucket_table::{Bucket, BucketParams, CorsRule as GarageCorsRule}; use crate::api_server::{ReqBody, ResBody};
use garage_model::garage::Garage; use crate::error::*;
use garage_util::data::*; use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value};
pub async fn handle_get_cors(ctx: ReqCtx) -> Result<Response<ResBody>, Error> { pub async fn handle_get_cors(ctx: ReqCtx) -> Result<Response<ResBody>, Error> {
let ReqCtx { bucket_params, .. } = ctx; let ReqCtx { bucket_params, .. } = ctx;

View file

@ -5,12 +5,13 @@ use garage_util::data::*;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::error::*; use crate::error::*;
use crate::put::next_timestamp; use crate::put::next_timestamp;
use crate::xml as s3_xml; use crate::xml as s3_xml;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
async fn handle_delete_internal(ctx: &ReqCtx, key: &str) -> Result<(Uuid, Uuid), Error> { async fn handle_delete_internal(ctx: &ReqCtx, key: &str) -> Result<(Uuid, Uuid), Error> {
let ReqCtx { let ReqCtx {

View file

@ -28,9 +28,10 @@ use garage_util::migrate::Migrate;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_model::s3::object_table::{ObjectVersionEncryption, ObjectVersionMetaInner}; use garage_model::s3::object_table::{ObjectVersionEncryption, ObjectVersionMetaInner};
use garage_api_common::common_error::*;
use crate::checksum::Md5Checksum; use crate::checksum::Md5Checksum;
use crate::error::Error; use crate::error::Error;
use garage_api_common::common_error::*;
const X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM: HeaderName = const X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM: HeaderName =
HeaderName::from_static("x-amz-server-side-encryption-customer-algorithm"); HeaderName::from_static("x-amz-server-side-encryption-customer-algorithm");

View file

@ -8,23 +8,26 @@ use garage_model::helper::error::Error as HelperError;
pub(crate) use garage_api_common::common_error::pass_helper_error; pub(crate) use garage_api_common::common_error::pass_helper_error;
use garage_api_common::common_error::{helper_error_as_internal, CommonError}; use garage_api_common::common_error::{
commonErrorDerivative, helper_error_as_internal, CommonError,
};
pub use garage_api_common::common_error::{ pub use garage_api_common::common_error::{
CommonErrorDerivative, OkOrBadRequest, OkOrInternalError, CommonErrorDerivative, OkOrBadRequest, OkOrInternalError,
}; };
use crate::xml as s3_xml;
use garage_api_common::generic_server::ApiError; use garage_api_common::generic_server::ApiError;
use garage_api_common::helpers::*; use garage_api_common::helpers::*;
use garage_api_common::signature::error::Error as SignatureError; use garage_api_common::signature::error::Error as SignatureError;
use crate::xml as s3_xml;
/// Errors of this crate /// Errors of this crate
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
#[error(display = "{}", _0)] #[error(display = "{}", _0)]
/// Error from common error /// Error from common error
Common(CommonError), Common(#[error(source)] CommonError),
// Category: cannot process // Category: cannot process
/// Authorization Header Malformed /// Authorization Header Malformed
@ -86,14 +89,7 @@ pub enum Error {
NotImplemented(String), NotImplemented(String),
} }
impl<T> From<T> for Error commonErrorDerivative!(Error);
where
CommonError: From<T>,
{
fn from(err: T) -> Self {
Error::Common(CommonError::from(err))
}
}
// Helper errors are always passed as internal errors by default. // Helper errors are always passed as internal errors by default.
// To pass the specific error code back to the client, use `pass_helper_error`. // To pass the specific error code back to the client, use `pass_helper_error`.
@ -103,8 +99,6 @@ impl From<HelperError> for Error {
} }
} }
impl CommonErrorDerivative for Error {}
impl From<roxmltree::Error> for Error { impl From<roxmltree::Error> for Error {
fn from(err: roxmltree::Error) -> Self { fn from(err: roxmltree::Error) -> Self {
Self::InvalidXml(format!("{}", err)) Self::InvalidXml(format!("{}", err))

View file

@ -25,11 +25,12 @@ use garage_model::garage::Garage;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_model::s3::version_table::*; use garage_model::s3::version_table::*;
use garage_api_common::helpers::*;
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::checksum::{add_checksum_response_headers, X_AMZ_CHECKSUM_MODE}; use crate::checksum::{add_checksum_response_headers, X_AMZ_CHECKSUM_MODE};
use crate::encryption::EncryptionParams; use crate::encryption::EncryptionParams;
use crate::error::*; use crate::error::*;
use garage_api_common::helpers::*;
const X_AMZ_MP_PARTS_COUNT: &str = "x-amz-mp-parts-count"; const X_AMZ_MP_PARTS_COUNT: &str = "x-amz-mp-parts-count";

View file

@ -5,11 +5,12 @@ use hyper::{Request, Response, StatusCode};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::error::*; use crate::error::*;
use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value}; use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value};
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
use garage_model::bucket_table::{ use garage_model::bucket_table::{
parse_lifecycle_date, Bucket, LifecycleExpiration as GarageLifecycleExpiration, parse_lifecycle_date, Bucket, LifecycleExpiration as GarageLifecycleExpiration,

View file

@ -13,13 +13,14 @@ use garage_model::s3::object_table::*;
use garage_table::EnumerationOrder; use garage_table::EnumerationOrder;
use garage_api_common::encoding::*;
use garage_api_common::helpers::*;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::encryption::EncryptionParams; use crate::encryption::EncryptionParams;
use crate::error::*; use crate::error::*;
use crate::multipart as s3_multipart; use crate::multipart as s3_multipart;
use crate::xml as s3_xml; use crate::xml as s3_xml;
use garage_api_common::encoding::*;
use garage_api_common::helpers::*;
const DUMMY_NAME: &str = "Dummy Key"; const DUMMY_NAME: &str = "Dummy Key";
const DUMMY_KEY: &str = "GKDummyKey"; const DUMMY_KEY: &str = "GKDummyKey";

View file

@ -15,14 +15,15 @@ use garage_model::s3::mpu_table::*;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_model::s3::version_table::*; use garage_model::s3::version_table::*;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::checksum::*; use crate::checksum::*;
use crate::encryption::EncryptionParams; use crate::encryption::EncryptionParams;
use crate::error::*; use crate::error::*;
use crate::put::*; use crate::put::*;
use crate::xml as s3_xml; use crate::xml as s3_xml;
use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content;
// ---- // ----

View file

@ -16,6 +16,9 @@ use serde::Deserialize;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_api_common::helpers::*;
use garage_api_common::signature::payload::{verify_v4, Authorization};
use crate::api_server::ResBody; use crate::api_server::ResBody;
use crate::checksum::*; use crate::checksum::*;
use crate::cors::*; use crate::cors::*;
@ -23,8 +26,6 @@ use crate::encryption::EncryptionParams;
use crate::error::*; use crate::error::*;
use crate::put::{get_headers, save_stream, ChecksumMode}; use crate::put::{get_headers, save_stream, ChecksumMode};
use crate::xml as s3_xml; use crate::xml as s3_xml;
use garage_api_common::helpers::*;
use garage_api_common::signature::payload::{verify_v4, Authorization};
pub async fn handle_post_object( pub async fn handle_post_object(
garage: Arc<Garage>, garage: Arc<Garage>,

View file

@ -30,11 +30,12 @@ use garage_model::s3::block_ref_table::*;
use garage_model::s3::object_table::*; use garage_model::s3::object_table::*;
use garage_model::s3::version_table::*; use garage_model::s3::version_table::*;
use garage_api_common::helpers::*;
use crate::api_server::{ReqBody, ResBody}; use crate::api_server::{ReqBody, ResBody};
use crate::checksum::*; use crate::checksum::*;
use crate::encryption::EncryptionParams; use crate::encryption::EncryptionParams;
use crate::error::*; use crate::error::*;
use garage_api_common::helpers::*;
const PUT_BLOCKS_MAX_PARALLEL: usize = 3; const PUT_BLOCKS_MAX_PARALLEL: usize = 3;

View file

@ -3,10 +3,11 @@ use std::borrow::Cow;
use hyper::header::HeaderValue; use hyper::header::HeaderValue;
use hyper::{HeaderMap, Method, Request}; use hyper::{HeaderMap, Method, Request};
use crate::error::*;
use garage_api_common::helpers::Authorization; use garage_api_common::helpers::Authorization;
use garage_api_common::router_macros::{generateQueryParameters, router_match}; use garage_api_common::router_macros::{generateQueryParameters, router_match};
use crate::error::*;
router_match! {@func router_match! {@func
/// List of all S3 API endpoints. /// List of all S3 API endpoints.

View file

@ -4,14 +4,15 @@ use http_body_util::BodyExt;
use hyper::{Request, Response, StatusCode}; use hyper::{Request, Response, StatusCode};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::api_server::{ReqBody, ResBody}; use garage_model::bucket_table::*;
use crate::error::*; use garage_util::data::*;
use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value};
use garage_api_common::helpers::*; use garage_api_common::helpers::*;
use garage_api_common::signature::verify_signed_content; use garage_api_common::signature::verify_signed_content;
use garage_model::bucket_table::*; use crate::api_server::{ReqBody, ResBody};
use garage_util::data::*; use crate::error::*;
use crate::xml::{to_xml_with_header, xmlns_tag, IntValue, Value};
pub async fn handle_get_website(ctx: ReqCtx) -> Result<Response<ResBody>, Error> { pub async fn handle_get_website(ctx: ReqCtx) -> Result<Response<ResBody>, Error> {
let ReqCtx { bucket_params, .. } = ctx; let ReqCtx { bucket_params, .. } = ctx;

View file

@ -98,7 +98,7 @@ consul-discovery = [ "garage_rpc/consul-discovery" ]
# Automatic registration and discovery via Kubernetes API # Automatic registration and discovery via Kubernetes API
kubernetes-discovery = [ "garage_rpc/kubernetes-discovery" ] kubernetes-discovery = [ "garage_rpc/kubernetes-discovery" ]
# Prometheus exporter (/metrics endpoint). # Prometheus exporter (/metrics endpoint).
metrics = [ "garage_api_common/metrics", "opentelemetry-prometheus", "prometheus" ] metrics = [ "garage_api_common/metrics", "garage_api_admin/metrics", "opentelemetry-prometheus", "prometheus" ]
# Exporter for the OpenTelemetry Collector. # Exporter for the OpenTelemetry Collector.
telemetry-otlp = [ "opentelemetry-otlp" ] telemetry-otlp = [ "opentelemetry-otlp" ]
# Logging to syslog # Logging to syslog

View file

@ -6,13 +6,13 @@ use garage_util::background::*;
use garage_util::config::*; use garage_util::config::*;
use garage_util::error::Error; use garage_util::error::Error;
use garage_api::admin::api_server::AdminApiServer; use garage_api_admin::api_server::AdminApiServer;
use garage_api::s3::api_server::S3ApiServer; use garage_api_s3::api_server::S3ApiServer;
use garage_model::garage::Garage; use garage_model::garage::Garage;
use garage_web::WebServer; use garage_web::WebServer;
#[cfg(feature = "k2v")] #[cfg(feature = "k2v")]
use garage_api::k2v::api_server::K2VApiServer; use garage_api_k2v::api_server::K2VApiServer;
use crate::admin::*; use crate::admin::*;
use crate::secrets::{fill_secrets, Secrets}; use crate::secrets::{fill_secrets, Secrets};

View file

@ -2,14 +2,14 @@ use err_derive::Error;
use hyper::header::HeaderValue; use hyper::header::HeaderValue;
use hyper::{HeaderMap, StatusCode}; use hyper::{HeaderMap, StatusCode};
use garage_api::generic_server::ApiError; use garage_api_common::generic_server::ApiError;
/// Errors of this crate /// Errors of this crate
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
/// An error received from the API crate /// An error received from the API crate
#[error(display = "API error: {}", _0)] #[error(display = "API error: {}", _0)]
ApiError(garage_api::s3::error::Error), ApiError(garage_api_s3::error::Error),
/// The file does not exist /// The file does not exist
#[error(display = "Not found")] #[error(display = "Not found")]
@ -22,10 +22,10 @@ pub enum Error {
impl<T> From<T> for Error impl<T> From<T> for Error
where where
garage_api::s3::error::Error: From<T>, garage_api_s3::error::Error: From<T>,
{ {
fn from(err: T) -> Self { fn from(err: T) -> Self {
Error::ApiError(garage_api::s3::error::Error::from(err)) Error::ApiError(garage_api_s3::error::Error::from(err))
} }
} }

View file

@ -20,13 +20,13 @@ use opentelemetry::{
use crate::error::*; use crate::error::*;
use garage_api::generic_server::{server_loop, UnixListenerOn}; use garage_api_common::generic_server::{server_loop, UnixListenerOn};
use garage_api::helpers::*; use garage_api_common::helpers::*;
use garage_api::s3::cors::{add_cors_headers, find_matching_cors_rule, handle_options_for_bucket}; use garage_api_s3::cors::{add_cors_headers, find_matching_cors_rule, handle_options_for_bucket};
use garage_api::s3::error::{ use garage_api_s3::error::{
CommonErrorDerivative, Error as ApiError, OkOrBadRequest, OkOrInternalError, CommonErrorDerivative, Error as ApiError, OkOrBadRequest, OkOrInternalError,
}; };
use garage_api::s3::get::{handle_get_without_ctx, handle_head_without_ctx}; use garage_api_s3::get::{handle_get_without_ctx, handle_head_without_ctx};
use garage_model::garage::Garage; use garage_model::garage::Garage;