in core/src/services/azblob/backend.rs [357:515]
fn build(self) -> Result<impl Access> {
debug!("backend build started: {:?}", &self);
let root = normalize_root(&self.config.root.unwrap_or_default());
debug!("backend use root {}", root);
// Handle endpoint, region and container name.
let container = match self.config.container.is_empty() {
false => Ok(&self.config.container),
true => Err(Error::new(ErrorKind::ConfigInvalid, "container is empty")
.with_operation("Builder::build")
.with_context("service", Scheme::Azblob)),
}?;
debug!("backend use container {}", &container);
let endpoint = match &self.config.endpoint {
Some(endpoint) => Ok(endpoint.clone()),
None => Err(Error::new(ErrorKind::ConfigInvalid, "endpoint is empty")
.with_operation("Builder::build")
.with_context("service", Scheme::Azblob)),
}?;
debug!("backend use endpoint {}", &container);
let mut config_loader = AzureStorageConfig::default().from_env();
if let Some(v) = self
.config
.account_name
.clone()
.or_else(|| infer_storage_name_from_endpoint(endpoint.as_str()))
{
config_loader.account_name = Some(v);
}
if let Some(v) = self.config.account_key.clone() {
config_loader.account_key = Some(v);
}
if let Some(v) = self.config.sas_token.clone() {
config_loader.sas_token = Some(v);
}
let encryption_key =
match &self.config.encryption_key {
None => None,
Some(v) => Some(build_header_value(v).map_err(|err| {
err.with_context("key", "server_side_encryption_customer_key")
})?),
};
let encryption_key_sha256 = match &self.config.encryption_key_sha256 {
None => None,
Some(v) => Some(build_header_value(v).map_err(|err| {
err.with_context("key", "server_side_encryption_customer_key_sha256")
})?),
};
let encryption_algorithm = match &self.config.encryption_algorithm {
None => None,
Some(v) => {
if v == "AES256" {
Some(build_header_value(v).map_err(|err| {
err.with_context("key", "server_side_encryption_customer_algorithm")
})?)
} else {
return Err(Error::new(
ErrorKind::ConfigInvalid,
"encryption_algorithm value must be AES256",
));
}
}
};
let cred_loader = AzureStorageLoader::new(config_loader);
let signer = AzureStorageSigner::new();
Ok(AzblobBackend {
core: Arc::new(AzblobCore {
info: {
let am = AccessorInfo::default();
am.set_scheme(Scheme::Azblob)
.set_root(&root)
.set_name(container)
.set_native_capability(Capability {
stat: true,
stat_with_if_match: true,
stat_with_if_none_match: true,
stat_has_cache_control: true,
stat_has_content_length: true,
stat_has_content_type: true,
stat_has_content_encoding: true,
stat_has_content_range: true,
stat_has_etag: true,
stat_has_content_md5: true,
stat_has_last_modified: true,
stat_has_content_disposition: true,
read: true,
read_with_if_match: true,
read_with_if_none_match: true,
read_with_override_content_disposition: true,
read_with_if_modified_since: true,
read_with_if_unmodified_since: true,
write: true,
write_can_append: true,
write_can_empty: true,
write_can_multi: true,
write_with_cache_control: true,
write_with_content_type: true,
write_with_if_not_exists: true,
write_with_if_none_match: true,
write_with_user_metadata: true,
delete: true,
delete_max_size: Some(AZBLOB_BATCH_LIMIT),
copy: true,
list: true,
list_with_recursive: true,
list_has_etag: true,
list_has_content_length: true,
list_has_content_md5: true,
list_has_content_type: true,
list_has_last_modified: true,
presign: self.config.sas_token.is_some(),
presign_stat: self.config.sas_token.is_some(),
presign_read: self.config.sas_token.is_some(),
presign_write: self.config.sas_token.is_some(),
shared: true,
..Default::default()
});
// allow deprecated api here for compatibility
#[allow(deprecated)]
if let Some(client) = self.http_client {
am.update_http_client(|_| client);
}
am.into()
},
root,
endpoint,
encryption_key,
encryption_key_sha256,
encryption_algorithm,
container: self.config.container.clone(),
loader: cred_loader,
signer,
}),
})
}