Skip to content

Commit

Permalink
feat(core/services-s3): try load endpoint from config (#5279)
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang authored Nov 4, 2024
1 parent fab80c9 commit c471b56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
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

0 comments on commit c471b56

Please sign in to comment.