2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 03:11:24 +00:00

Don't automatically prepend bucket to endpoint when path_style is disabled

This commit is contained in:
asonix 2024-06-26 13:16:45 -05:00
parent 38a5b72606
commit 4b67c696d8

View file

@ -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)