Skip to content

Commit

Permalink
chore: The source files in the copy from function support Aliyun oss …
Browse files Browse the repository at this point in the history
…files.
  • Loading branch information
paomian committed Nov 24, 2023
1 parent 64a36e9 commit 12948b1
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/common/datasource/src/object_store/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::collections::HashMap;

use object_store::services::S3;
use object_store::services::{Oss, S3};
use object_store::ObjectStore;
use snafu::ResultExt;

Expand All @@ -36,7 +36,7 @@ pub fn is_supported_in_s3(key: &str) -> bool {
|| key == ENABLE_VIRTUAL_HOST_STYLE
}

pub fn build_s3_backend(
fn build_aws_backend(
host: &str,
path: &str,
connection: &HashMap<String, String>,
Expand Down Expand Up @@ -85,6 +85,47 @@ pub fn build_s3_backend(
.finish())
}

fn build_aliyun_backend(
host: &str,
path: &str,
connection: &HashMap<String, String>,
) -> Result<ObjectStore> {
let mut builder = Oss::default();
let _ = builder.root(path).bucket(host);

if let Some(endpoint) = connection.get(ENDPOINT) {
let _ = builder.endpoint(endpoint);
}

if let Some(key_id) = connection.get(ACCESS_KEY_ID) {
let _ = builder.access_key_id(key_id);
}

if let Some(key) = connection.get(SECRET_ACCESS_KEY) {
builder.access_key_secret(key);
}

Ok(ObjectStore::new(builder)
.context(error::BuildBackendSnafu)?
.finish())
}

pub fn build_s3_backend(
host: &str,
path: &str,
connection: &HashMap<String, String>,
) -> Result<ObjectStore> {
if let Some(endpoint) = connection.get(ENDPOINT) {
if endpoint.ends_with("aliyuncs.com") {
return build_aliyun_backend(host, path, connection);
} else {
return build_aws_backend(host, path, connection);
}
} else {
return build_aws_backend(host, path, connection);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 12948b1

Please sign in to comment.