Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/services-s3): try load endpoint from config #5279

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ sqlx = { version = "0.8.0", features = [
], optional = true }

# For http based services.
reqsign = { version = "0.16", default-features = false, optional = true }
reqsign = { version = "0.16.1", default-features = false, optional = true }

# for services-atomic-server
atomic_lib = { version = "0.39.0", optional = true }
Expand Down
10 changes: 7 additions & 3 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl Builder for S3Builder {
const SCHEME: Scheme = Scheme::S3;
type Config = S3Config;

fn build(self) -> Result<impl Access> {
fn build(mut self) -> Result<impl Access> {
debug!("backend build started: {:?}", &self);

let root = normalize_root(&self.config.root.clone().unwrap_or_default());
Expand Down Expand Up @@ -753,9 +753,10 @@ impl Builder for S3Builder {
}
}

if let Some(v) = self.config.region.clone() {
cfg.region = Some(v);
if let Some(ref v) = self.config.region {
cfg.region = Some(v.to_string());
}

if cfg.region.is_none() {
return Err(Error::new(
ErrorKind::ConfigInvalid,
Expand All @@ -768,6 +769,9 @@ impl Builder for S3Builder {
let region = cfg.region.to_owned().unwrap();
debug!("backend use region: {region}");

// Retain the user's endpoint if it exists; otherwise, try loading it from the environment.
self.config.endpoint = self.config.endpoint.or_else(|| cfg.endpoint_url.clone());

// Building endpoint.
let endpoint = self.build_endpoint(&region);
debug!("backend use endpoint: {endpoint}");
Expand Down
4 changes: 3 additions & 1 deletion core/src/services/s3/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub struct S3Config {
/// If user inputs endpoint without scheme like "s3.amazonaws.com", we
/// will prepend "https://" before it.
///
/// default to `https://s3.amazonaws.com` if not set.
/// - If endpoint is set, we will take user's input first.
/// - If not, we will try to load it from environment.
/// - If still not set, default to `https://s3.amazonaws.com`.
pub endpoint: Option<String>,
/// Region represent the signing region of this endpoint. This is required
/// if you are using the default AWS S3 endpoint.
Expand Down
Loading