Skip to content

Commit

Permalink
enable virtual host style for s3 backend via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Oct 20, 2024
1 parent 2932b22 commit 8211e63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ pub fn storage_from_config(
c.endpoint.as_deref(),
c.use_ssl,
c.server_side_encryption,
c.use_virtual_host_style
)
.map_err(|err| anyhow!("create s3 cache failed: {err:?}"))?;

Expand Down
5 changes: 5 additions & 0 deletions src/cache/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ impl S3Cache {
endpoint: Option<&str>,
use_ssl: Option<bool>,
server_side_encryption: Option<bool>,
use_virtual_host_style: Option<bool>,
) -> Result<Operator> {
let mut builder = S3::default()
.http_client(set_user_agent())
.bucket(bucket)
.root(key_prefix);

if use_virtual_host_style.unwrap_or_default() {
builder = builder.enable_virtual_host_style();
}

if let Some(region) = region {
builder = builder.region(region);
}
Expand Down
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ pub struct S3CacheConfig {
pub endpoint: Option<String>,
pub use_ssl: Option<bool>,
pub server_side_encryption: Option<bool>,
pub use_virtual_host_style: Option<bool>

}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -640,6 +642,7 @@ fn config_from_env() -> Result<EnvConfig> {
let server_side_encryption = bool_from_env_var("SCCACHE_S3_SERVER_SIDE_ENCRYPTION")?;
let endpoint = env::var("SCCACHE_ENDPOINT").ok();
let key_prefix = key_prefix_from_env_var("SCCACHE_S3_KEY_PREFIX");
let use_virtual_host_style = bool_from_env_var("SCCACHE_S3_ENABLE_VIRTUAL_HOST_STYLE")?;

Some(S3CacheConfig {
bucket,
Expand All @@ -649,6 +652,7 @@ fn config_from_env() -> Result<EnvConfig> {
endpoint,
use_ssl,
server_side_encryption,
use_virtual_host_style
})
} else {
None
Expand Down Expand Up @@ -1544,7 +1548,8 @@ no_credentials = true
use_ssl: Some(true),
key_prefix: "s3prefix".into(),
no_credentials: true,
server_side_encryption: Some(false)
server_side_encryption: Some(false),
use_virtual_host_style: Some(false)
}),
webdav: Some(WebdavCacheConfig {
endpoint: "http://127.0.0.1:8080".to_string(),
Expand Down

0 comments on commit 8211e63

Please sign in to comment.