Skip to content

Commit

Permalink
[object_store] Propagate env vars as object store client options (apa…
Browse files Browse the repository at this point in the history
…che#6334)

* [object_store] Propagate env vars as object store client options

* [object_store] Include the missing variants in the FromStr implementation of ClientConfigKey

* cargo fmt
  • Loading branch information
ccciudatu authored Sep 4, 2024
1 parent d4be752 commit efe867a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
15 changes: 14 additions & 1 deletion object_store/src/aws/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl FromStr for AmazonS3ConfigKey {
"aws_sse_customer_key_base64" => Ok(Self::Encryption(
S3EncryptionConfigKey::CustomerEncryptionKey,
)),
_ => match s.parse() {
_ => match s.strip_prefix("aws_").unwrap_or(s).parse() {
Ok(key) => Ok(Self::Client(key)),
Err(_) => Err(Error::UnknownConfigurationKey { key: s.into() }.into()),
},
Expand Down Expand Up @@ -1455,4 +1455,17 @@ mod tests {
assert_eq!(parse_bucket_az(bucket), expected)
}
}

#[test]
fn aws_test_client_opts() {
let key = "AWS_PROXY_URL";
if let Ok(config_key) = key.to_ascii_lowercase().parse() {
assert_eq!(
AmazonS3ConfigKey::Client(ClientConfigKey::ProxyUrl),
config_key
);
} else {
panic!("{} not propagated as ClientConfigKey", key);
}
}
}
15 changes: 14 additions & 1 deletion object_store/src/azure/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl FromStr for AzureConfigKey {
"azure_disable_tagging" | "disable_tagging" => Ok(Self::DisableTagging),
// Backwards compatibility
"azure_allow_http" => Ok(Self::Client(ClientConfigKey::AllowHttp)),
_ => match s.parse() {
_ => match s.strip_prefix("azure_").unwrap_or(s).parse() {
Ok(key) => Ok(Self::Client(key)),
Err(_) => Err(Error::UnknownConfigurationKey { key: s.into() }.into()),
},
Expand Down Expand Up @@ -1103,4 +1103,17 @@ mod tests {
let pairs = split_sas(raw_sas).unwrap();
assert_eq!(expected, pairs);
}

#[test]
fn azure_test_client_opts() {
let key = "AZURE_PROXY_URL";
if let Ok(config_key) = key.to_ascii_lowercase().parse() {
assert_eq!(
AzureConfigKey::Client(ClientConfigKey::ProxyUrl),
config_key
);
} else {
panic!("{} not propagated as ClientConfigKey", key);
}
}
}
2 changes: 2 additions & 0 deletions object_store/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ impl FromStr for ClientConfigKey {
"pool_idle_timeout" => Ok(Self::PoolIdleTimeout),
"pool_max_idle_per_host" => Ok(Self::PoolMaxIdlePerHost),
"proxy_url" => Ok(Self::ProxyUrl),
"proxy_ca_certificate" => Ok(Self::ProxyCaCertificate),
"proxy_excludes" => Ok(Self::ProxyExcludes),
"timeout" => Ok(Self::Timeout),
"user_agent" => Ok(Self::UserAgent),
_ => Err(super::Error::UnknownConfigurationKey {
Expand Down
15 changes: 14 additions & 1 deletion object_store/src/gcp/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl FromStr for GoogleConfigKey {
"google_service_account_key" | "service_account_key" => Ok(Self::ServiceAccountKey),
"google_bucket" | "google_bucket_name" | "bucket" | "bucket_name" => Ok(Self::Bucket),
"google_application_credentials" => Ok(Self::ApplicationCredentials),
_ => match s.parse() {
_ => match s.strip_prefix("google_").unwrap_or(s).parse() {
Ok(key) => Ok(Self::Client(key)),
Err(_) => Err(Error::UnknownConfigurationKey { key: s.into() }.into()),
},
Expand Down Expand Up @@ -671,4 +671,17 @@ mod tests {
google_bucket_name
);
}

#[test]
fn gcp_test_client_opts() {
let key = "GOOGLE_PROXY_URL";
if let Ok(config_key) = key.to_ascii_lowercase().parse() {
assert_eq!(
GoogleConfigKey::Client(ClientConfigKey::ProxyUrl),
config_key
);
} else {
panic!("{} not propagated as ClientConfigKey", key);
}
}
}

0 comments on commit efe867a

Please sign in to comment.