From 4b67c696d8eedd3e9f7a1681fd0c236df911039f Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 26 Jun 2024 13:16:45 -0500 Subject: [PATCH] Don't automatically prepend bucket to endpoint when path_style is disabled --- src/store/object_store.rs | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/store/object_store.rs b/src/store/object_store.rs index bf2a42a..c1d90fb 100644 --- a/src/store/object_store.rs +++ b/src/store/object_store.rs @@ -20,9 +20,6 @@ const CHUNK_SIZE: usize = 8_388_608; // 8 Mebibytes, min is 5 (5_242_880); #[derive(Debug, thiserror::Error)] pub(crate) enum ObjectError { - #[error("Failed to set the vhost-style bucket name")] - SetHost, - #[error("IO Error")] IO(#[from] std::io::Error), @@ -39,9 +36,7 @@ pub(crate) enum ObjectError { impl ObjectError { pub(super) const fn error_code(&self) -> ErrorCode { match self { - Self::SetHost | Self::BuildClient(_) | Self::Request(_) => { - ErrorCode::OBJECT_REQUEST_ERROR - } + Self::BuildClient(_) | Self::Request(_) => ErrorCode::OBJECT_REQUEST_ERROR, Self::IO(_) => ErrorCode::OBJECT_IO_ERROR, Self::Canceled => ErrorCode::PANIC, } @@ -307,11 +302,10 @@ impl Store for ObjectStore { } impl ObjectStore { - #[allow(clippy::too_many_arguments)] - #[tracing::instrument(skip(access_key, secret_key, session_token))] + #[tracing::instrument(skip(endpoint, access_key, secret_key, session_token), fields(endpoint = %endpoint))] pub(crate) async fn new( crate::config::ObjectStorage { - mut endpoint, + endpoint, bucket_name, use_path_style, region, @@ -328,23 +322,10 @@ impl ObjectStore { .with_timeout(Duration::from_secs(client_timeout)) .with_allow_http(!https); - let use_vhost_style = !use_path_style; - - if use_vhost_style { - if let Some(host) = endpoint.host() { - if !host.to_string().starts_with(&bucket_name) { - let new_host = format!("{bucket_name}.{host}"); - endpoint - .set_host(Some(&new_host)) - .map_err(|_| ObjectError::SetHost)?; - } - } - } - let builder = AmazonS3Builder::new() .with_endpoint(endpoint.as_str().trim_end_matches('/')) .with_bucket_name(bucket_name) - .with_virtual_hosted_style_request(use_vhost_style) + .with_virtual_hosted_style_request(!use_path_style) .with_region(region) .with_access_key_id(access_key) .with_secret_access_key(secret_key)