recomp 0.3.1

Reusable components
Documentation
use object_store::{
    Result,
    gcp::{GoogleCloudStorage, GoogleCloudStorageBuilder},
};

use super::super::ObjectStorage;

/// Builder for Google Cloud Storage.
#[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(),
        }
    }

    /// Sets the GCS bucket name.
    #[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
    }

    /// Sets the GCS service account file path.
    #[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
    }

    /// Sets the GCS service account JSON key.
    #[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
    }

    /// Sets the GCS builder URL.
    #[must_use]
    pub fn with_url(mut self, url: impl Into<String>) -> Self {
        self.builder = self.builder.with_url(url);
        self
    }

    /// Configures the underlying provider builder.
    #[must_use]
    pub fn configure_store(
        mut self,
        configure: impl FnOnce(GoogleCloudStorageBuilder) -> GoogleCloudStorageBuilder,
    ) -> Self {
        self.builder = configure(self.builder);
        self
    }

    /// Builds the object storage component.
    pub fn build(self) -> Result<ObjectStorage<GoogleCloudStorage>> {
        self.builder
            .build()
            .map(|store| ObjectStorage::from_store(self.name, store))
    }
}