mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-20 11:21:14 +00:00
Don't automatically prepend bucket to endpoint when path_style is disabled
This commit is contained in:
parent
38a5b72606
commit
4b67c696d8
1 changed files with 4 additions and 23 deletions
|
@ -20,9 +20,6 @@ const CHUNK_SIZE: usize = 8_388_608; // 8 Mebibytes, min is 5 (5_242_880);
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub(crate) enum ObjectError {
|
pub(crate) enum ObjectError {
|
||||||
#[error("Failed to set the vhost-style bucket name")]
|
|
||||||
SetHost,
|
|
||||||
|
|
||||||
#[error("IO Error")]
|
#[error("IO Error")]
|
||||||
IO(#[from] std::io::Error),
|
IO(#[from] std::io::Error),
|
||||||
|
|
||||||
|
@ -39,9 +36,7 @@ pub(crate) enum ObjectError {
|
||||||
impl ObjectError {
|
impl ObjectError {
|
||||||
pub(super) const fn error_code(&self) -> ErrorCode {
|
pub(super) const fn error_code(&self) -> ErrorCode {
|
||||||
match self {
|
match self {
|
||||||
Self::SetHost | Self::BuildClient(_) | Self::Request(_) => {
|
Self::BuildClient(_) | Self::Request(_) => ErrorCode::OBJECT_REQUEST_ERROR,
|
||||||
ErrorCode::OBJECT_REQUEST_ERROR
|
|
||||||
}
|
|
||||||
Self::IO(_) => ErrorCode::OBJECT_IO_ERROR,
|
Self::IO(_) => ErrorCode::OBJECT_IO_ERROR,
|
||||||
Self::Canceled => ErrorCode::PANIC,
|
Self::Canceled => ErrorCode::PANIC,
|
||||||
}
|
}
|
||||||
|
@ -307,11 +302,10 @@ impl Store for ObjectStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectStore {
|
impl ObjectStore {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[tracing::instrument(skip(endpoint, access_key, secret_key, session_token), fields(endpoint = %endpoint))]
|
||||||
#[tracing::instrument(skip(access_key, secret_key, session_token))]
|
|
||||||
pub(crate) async fn new(
|
pub(crate) async fn new(
|
||||||
crate::config::ObjectStorage {
|
crate::config::ObjectStorage {
|
||||||
mut endpoint,
|
endpoint,
|
||||||
bucket_name,
|
bucket_name,
|
||||||
use_path_style,
|
use_path_style,
|
||||||
region,
|
region,
|
||||||
|
@ -328,23 +322,10 @@ impl ObjectStore {
|
||||||
.with_timeout(Duration::from_secs(client_timeout))
|
.with_timeout(Duration::from_secs(client_timeout))
|
||||||
.with_allow_http(!https);
|
.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()
|
let builder = AmazonS3Builder::new()
|
||||||
.with_endpoint(endpoint.as_str().trim_end_matches('/'))
|
.with_endpoint(endpoint.as_str().trim_end_matches('/'))
|
||||||
.with_bucket_name(bucket_name)
|
.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_region(region)
|
||||||
.with_access_key_id(access_key)
|
.with_access_key_id(access_key)
|
||||||
.with_secret_access_key(secret_key)
|
.with_secret_access_key(secret_key)
|
||||||
|
|
Loading…
Reference in a new issue