use object_store::{
Result,
aws::{AmazonS3, AmazonS3Builder},
};
use super::super::ObjectStorage;
#[derive(Clone, Debug)]
pub struct S3ObjectStorageBuilder {
name: String,
builder: AmazonS3Builder,
}
impl S3ObjectStorageBuilder {
pub(crate) fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
builder: AmazonS3Builder::from_env(),
}
}
#[must_use]
pub fn with_bucket_name(mut self, bucket_name: impl Into<String>) -> Self {
self.builder = self.builder.with_bucket_name(bucket_name);
self
}
#[must_use]
pub fn with_region(mut self, region: impl Into<String>) -> Self {
self.builder = self.builder.with_region(region);
self
}
#[must_use]
pub fn with_endpoint(mut self, endpoint: impl Into<String>) -> Self {
self.builder = self.builder.with_endpoint(endpoint);
self
}
#[must_use]
pub fn with_url(mut self, url: impl Into<String>) -> Self {
self.builder = self.builder.with_url(url);
self
}
#[must_use]
pub fn configure_store(
mut self,
configure: impl FnOnce(AmazonS3Builder) -> AmazonS3Builder,
) -> Self {
self.builder = configure(self.builder);
self
}
pub fn build(self) -> Result<ObjectStorage<AmazonS3>> {
self.builder
.build()
.map(|store| ObjectStorage::from_store(self.name, store))
}
}