use object_store::{
Result,
gcp::{GoogleCloudStorage, GoogleCloudStorageBuilder},
};
use super::super::ObjectStorage;
#[derive(Clone, Debug)]
pub struct GcpObjectStorageBuilder {
name: String,
builder: GoogleCloudStorageBuilder,
}
impl GcpObjectStorageBuilder {
pub(crate) fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
builder: GoogleCloudStorageBuilder::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_service_account_path(mut self, path: impl Into<String>) -> Self {
self.builder = self.builder.with_service_account_path(path);
self
}
#[must_use]
pub fn with_service_account_key(mut self, key: impl Into<String>) -> Self {
self.builder = self.builder.with_service_account_key(key);
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(GoogleCloudStorageBuilder) -> GoogleCloudStorageBuilder,
) -> Self {
self.builder = configure(self.builder);
self
}
pub fn build(self) -> Result<ObjectStorage<GoogleCloudStorage>> {
self.builder
.build()
.map(|store| ObjectStorage::from_store(self.name, store))
}
}