Skip to content

Commit

Permalink
feat(oli): support s3 uri without profile (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan authored Feb 12, 2023
1 parent 1b7c403 commit d062e02
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions binaries/oli/src/utils/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,25 @@ pub fn parse_location(s: &str) -> Result<(Operator, &str)> {

let s = s.splitn(2, "://").collect::<Vec<_>>();
debug_assert!(s.len() == 2);
Ok((parse_profile(s[0])?, s[1]))

if let Ok(scheme) = Scheme::from_str(s[0]) {
// If name is a valid scheme, we will load from env directly.
match scheme {
Scheme::S3 => {
let (bucket, location) = parse_s3_uri(s[1]);
let mut builder = services::S3::default();
builder.bucket(bucket);
Ok((Operator::create(builder)?.finish(), location))
}
_ => todo!(),
}
} else {
// Otherwise, try to load profile.
Ok((parse_profile(s[0])?, s[1]))
}
}

/// If name is a valid scheme, we will load from env directly.
/// Or, we will try to get env from `OLI_PROFILE_{NAME}_XXX`.
/// Try to get env from `OLI_PROFILE_{NAME}_XXX`.
///
/// Especially, the type is specified by `OLI_PROFILE_{NAME}_TYPE`
pub fn parse_profile(name: &str) -> Result<Operator> {
Expand All @@ -67,3 +81,12 @@ pub fn parse_profile(name: &str) -> Result<Operator> {

Ok(op)
}

/// Parses bucket and key from [`S3Uri`](https://docs.aws.amazon.com/cli/latest/reference/s3/#path-argument-type)
fn parse_s3_uri(s3uri: &str) -> (&str, &str) {
// TODO: support ARN

let s = s3uri.splitn(2, "/").collect::<Vec<_>>();
debug_assert!(s.len() == 2);
return (s[0], s[1]);
}

1 comment on commit d062e02

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for opendal ready!

✅ Preview
https://opendal-qtzidu4o1-databend.vercel.app

Built with commit d062e02.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.