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 2 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
11 changes: 8 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,8 +753,8 @@ 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(
Expand All @@ -769,6 +769,11 @@ impl Builder for S3Builder {
debug!("backend use region: {region}");

// Building endpoint.
if let Some(ref v) = self.config.endpoint {
cfg.endpoint_url = Some(v.to_string());
} else if let Some(ref v) = cfg.endpoint_url {
TennyZhuang marked this conversation as resolved.
Show resolved Hide resolved
self.config.endpoint = Some(v.to_string());
}
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