Skip to main content

entrenar/storage/cloud/
azure.rs

1//! Azure Blob Storage configuration
2
3use serde::{Deserialize, Serialize};
4
5/// Azure Blob Storage configuration
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct AzureConfig {
8    /// Storage account name
9    pub account: String,
10    /// Container name
11    pub container: String,
12    /// Blob prefix
13    pub prefix: String,
14    /// Connection string (if not using managed identity)
15    pub connection_string: Option<String>,
16}
17
18impl AzureConfig {
19    /// Create a new Azure configuration
20    pub fn new(account: &str, container: &str) -> Self {
21        Self {
22            account: account.to_string(),
23            container: container.to_string(),
24            prefix: String::new(),
25            connection_string: None,
26        }
27    }
28
29    /// Set blob prefix
30    pub fn with_prefix(mut self, prefix: &str) -> Self {
31        self.prefix = prefix.to_string();
32        self
33    }
34
35    /// Set connection string
36    pub fn with_connection_string(mut self, conn_str: &str) -> Self {
37        self.connection_string = Some(conn_str.to_string());
38        self
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_azure_config_new() {
48        let config = AzureConfig::new("myaccount", "mycontainer");
49        assert_eq!(config.account, "myaccount");
50        assert_eq!(config.container, "mycontainer");
51    }
52
53    #[test]
54    fn test_azure_config_with_prefix() {
55        let config = AzureConfig::new("account", "container").with_prefix("models/");
56        assert_eq!(config.prefix, "models/");
57    }
58
59    #[test]
60    fn test_azure_config_with_connection_string() {
61        let config = AzureConfig::new("account", "container")
62            .with_connection_string("DefaultEndpointsProtocol=https;...");
63        assert!(config.connection_string.is_some());
64    }
65
66    #[test]
67    fn test_azure_config_serde() {
68        let config = AzureConfig::new("account", "container")
69            .with_prefix("models/")
70            .with_connection_string("conn");
71
72        let json = serde_json::to_string(&config).expect("JSON serialization should succeed");
73        let parsed: AzureConfig =
74            serde_json::from_str(&json).expect("JSON deserialization should succeed");
75
76        assert_eq!(config.account, parsed.account);
77        assert_eq!(config.container, parsed.container);
78        assert_eq!(config.prefix, parsed.prefix);
79    }
80}