Skip to content

Commit

Permalink
Merge pull request #592 from helium/andymck/filestore-new-support
Browse files Browse the repository at this point in the history
add filestore new support
  • Loading branch information
jeffgrunewald authored Aug 14, 2023
2 parents ac4b861 + 1a934c0 commit 16558aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion file_store/src/file_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
error::DecodeError, BytesMutStream, Error, FileInfo, FileInfoStream, Result, Settings,
error::DecodeError,
settings::{self, Settings},
BytesMutStream, Error, FileInfo, FileInfoStream, Result,
};
use aws_config::meta::region::RegionProviderChain;
use aws_sdk_s3::{types::ByteStream, Client, Endpoint, Region};
Expand Down Expand Up @@ -57,6 +59,32 @@ impl FileStore {
})
}

pub async fn new(
bucket: String,
endpoint: Option<String>,
region: Option<String>,
) -> Result<Self> {
let endpoint: Option<Endpoint> = match &endpoint {
Some(endpoint) => Uri::from_str(endpoint)
.map(Endpoint::immutable)
.map(Some)
.map_err(DecodeError::from)?,
_ => None,
};
let region = Region::new(region.unwrap_or_else(settings::default_region));
let region_provider = RegionProviderChain::first_try(region).or_default_provider();

let mut config = aws_config::from_env().region(region_provider);
if let Some(endpoint) = endpoint {
config = config.endpoint_resolver(endpoint);
}

let config = config.load().await;

let client = Client::new(&config);
Ok(Self { client, bucket })
}

pub async fn list_all<A, B>(
&self,
file_type: &str,
Expand Down
2 changes: 1 addition & 1 deletion file_store/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Settings {
pub secret_access_key: Option<String>,
}

fn default_region() -> String {
pub fn default_region() -> String {
"us-west-2".to_string()
}

Expand Down

0 comments on commit 16558aa

Please sign in to comment.