Skip to content

Commit

Permalink
Adds helper method to get region from s3_uri (#5)
Browse files Browse the repository at this point in the history
* helper method to get region from s3_uri

* cargo fmt
  • Loading branch information
Ryan Aston authored Oct 21, 2023
1 parent ab8a21e commit 9681267
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rust/src/storage/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::ops::Range;
use std::sync::Arc;
use std::time::Duration;
use tokio::io::AsyncWrite;
use url::Url;

const STORE_NAME: &str = "DeltaS3ObjectStore";

Expand Down Expand Up @@ -539,6 +540,24 @@ fn try_create_lock_client(options: &S3StorageOptions) -> Result<Option<S3LockCli
}
}

/// attempts to resolve the bucket region, returns empty if unable
pub async fn try_resolve_bucket_region(s3_uri: impl AsRef<str>) -> String {
let url = match Url::parse(s3_uri.as_ref()) {
Err(_) => return "".to_string(),
Ok(url) => url,
};

match object_store::aws::resolve_bucket_region(
url.host_str().unwrap(),
&object_store::ClientOptions::new(),
)
.await
{
Err(_) => return "".to_string(),
Ok(v) => return v,
}
}

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

0 comments on commit 9681267

Please sign in to comment.