recomp 0.3.1

Reusable components
Documentation
use object_store::{
    Result,
    azure::{MicrosoftAzure, MicrosoftAzureBuilder},
};

use super::super::ObjectStorage;

/// Builder for Microsoft Azure Blob Storage.
#[derive(Clone, Debug)]
pub struct AzureObjectStorageBuilder {
    name: String,
    builder: MicrosoftAzureBuilder,
}

impl AzureObjectStorageBuilder {
    pub(crate) fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            builder: MicrosoftAzureBuilder::from_env(),
        }
    }

    /// Sets the Azure storage account name.
    #[must_use]
    pub fn with_account(mut self, account: impl Into<String>) -> Self {
        self.builder = self.builder.with_account(account);
        self
    }

    /// Sets the Azure container name.
    #[must_use]
    pub fn with_container_name(mut self, container_name: impl Into<String>) -> Self {
        self.builder = self.builder.with_container_name(container_name);
        self
    }

    /// Sets the Azure access key.
    #[must_use]
    pub fn with_access_key(mut self, access_key: impl Into<String>) -> Self {
        self.builder = self.builder.with_access_key(access_key);
        self
    }

    /// Sets the Azure 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(MicrosoftAzureBuilder) -> MicrosoftAzureBuilder,
    ) -> Self {
        self.builder = configure(self.builder);
        self
    }

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