opendal/services/azblob/
config.rs1use std::fmt::Debug;
19use std::fmt::Formatter;
20
21use serde::Deserialize;
22use serde::Serialize;
23
24#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
26pub struct AzblobConfig {
27 pub root: Option<String>,
31
32 #[serde(alias = "azure_container_name", alias = "container_name")]
34 pub container: String,
35
36 #[serde(alias = "azure_storage_endpoint", alias = "azure_endpoint")]
43 pub endpoint: Option<String>,
44
45 #[serde(alias = "azure_storage_account_name")]
47 pub account_name: Option<String>,
48
49 #[serde(
51 alias = "azure_storage_account_key",
52 alias = "azure_storage_access_key",
53 alias = "azure_storage_master_key",
54 alias = "access_key",
55 alias = "master_key"
56 )]
57 pub account_key: Option<String>,
58
59 pub encryption_key: Option<String>,
61
62 pub encryption_key_sha256: Option<String>,
64
65 pub encryption_algorithm: Option<String>,
67
68 #[serde(
70 alias = "azure_storage_sas_key",
71 alias = "azure_storage_sas_token",
72 alias = "sas_key"
73 )]
74 pub sas_token: Option<String>,
75
76 pub batch_max_operations: Option<usize>,
78}
79
80impl Debug for AzblobConfig {
81 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
82 let mut ds = f.debug_struct("AzblobConfig");
83
84 ds.field("root", &self.root);
85 ds.field("container", &self.container);
86 ds.field("endpoint", &self.endpoint);
87
88 if self.account_name.is_some() {
89 ds.field("account_name", &"<redacted>");
90 }
91 if self.account_key.is_some() {
92 ds.field("account_key", &"<redacted>");
93 }
94 if self.sas_token.is_some() {
95 ds.field("sas_token", &"<redacted>");
96 }
97
98 ds.finish()
99 }
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105
106 #[test]
107 fn test_container_name_aliases() {
108 let json = r#"{"container": "test-container"}"#;
110 let config: AzblobConfig = serde_json::from_str(json).unwrap();
111 assert_eq!(config.container, "test-container");
112
113 let json = r#"{"azure_container_name": "test-container"}"#;
115 let config: AzblobConfig = serde_json::from_str(json).unwrap();
116 assert_eq!(config.container, "test-container");
117
118 let json = r#"{"container_name": "test-container"}"#;
120 let config: AzblobConfig = serde_json::from_str(json).unwrap();
121 assert_eq!(config.container, "test-container");
122 }
123
124 #[test]
125 fn test_account_name_aliases() {
126 let json = r#"{"container": "test", "account_name": "testaccount"}"#;
128 let config: AzblobConfig = serde_json::from_str(json).unwrap();
129 assert_eq!(config.account_name, Some("testaccount".to_string()));
130
131 let json = r#"{"container": "test", "azure_storage_account_name": "testaccount"}"#;
133 let config: AzblobConfig = serde_json::from_str(json).unwrap();
134 assert_eq!(config.account_name, Some("testaccount".to_string()));
135 }
136
137 #[test]
138 fn test_account_key_aliases() {
139 let json = r#"{"container": "test", "account_key": "dGVzdGtleQ=="}"#;
141 let config: AzblobConfig = serde_json::from_str(json).unwrap();
142 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
143
144 let json = r#"{"container": "test", "azure_storage_account_key": "dGVzdGtleQ=="}"#;
146 let config: AzblobConfig = serde_json::from_str(json).unwrap();
147 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
148
149 let json = r#"{"container": "test", "azure_storage_access_key": "dGVzdGtleQ=="}"#;
151 let config: AzblobConfig = serde_json::from_str(json).unwrap();
152 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
153
154 let json = r#"{"container": "test", "azure_storage_master_key": "dGVzdGtleQ=="}"#;
156 let config: AzblobConfig = serde_json::from_str(json).unwrap();
157 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
158
159 let json = r#"{"container": "test", "access_key": "dGVzdGtleQ=="}"#;
161 let config: AzblobConfig = serde_json::from_str(json).unwrap();
162 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
163
164 let json = r#"{"container": "test", "master_key": "dGVzdGtleQ=="}"#;
166 let config: AzblobConfig = serde_json::from_str(json).unwrap();
167 assert_eq!(config.account_key, Some("dGVzdGtleQ==".to_string()));
168 }
169
170 #[test]
171 fn test_sas_token_aliases() {
172 let json = r#"{"container": "test", "sas_token": "test-token"}"#;
174 let config: AzblobConfig = serde_json::from_str(json).unwrap();
175 assert_eq!(config.sas_token, Some("test-token".to_string()));
176
177 let json = r#"{"container": "test", "azure_storage_sas_key": "test-token"}"#;
179 let config: AzblobConfig = serde_json::from_str(json).unwrap();
180 assert_eq!(config.sas_token, Some("test-token".to_string()));
181
182 let json = r#"{"container": "test", "azure_storage_sas_token": "test-token"}"#;
184 let config: AzblobConfig = serde_json::from_str(json).unwrap();
185 assert_eq!(config.sas_token, Some("test-token".to_string()));
186
187 let json = r#"{"container": "test", "sas_key": "test-token"}"#;
189 let config: AzblobConfig = serde_json::from_str(json).unwrap();
190 assert_eq!(config.sas_token, Some("test-token".to_string()));
191 }
192
193 #[test]
194 fn test_endpoint_aliases() {
195 let json = r#"{"container": "test", "endpoint": "https://test.blob.core.windows.net"}"#;
197 let config: AzblobConfig = serde_json::from_str(json).unwrap();
198 assert_eq!(
199 config.endpoint,
200 Some("https://test.blob.core.windows.net".to_string())
201 );
202
203 let json = r#"{"container": "test", "azure_storage_endpoint": "https://test.blob.core.windows.net"}"#;
205 let config: AzblobConfig = serde_json::from_str(json).unwrap();
206 assert_eq!(
207 config.endpoint,
208 Some("https://test.blob.core.windows.net".to_string())
209 );
210
211 let json =
213 r#"{"container": "test", "azure_endpoint": "https://test.blob.core.windows.net"}"#;
214 let config: AzblobConfig = serde_json::from_str(json).unwrap();
215 assert_eq!(
216 config.endpoint,
217 Some("https://test.blob.core.windows.net".to_string())
218 );
219 }
220}