in core/src/services/azblob/backend.rs [376:472]
fn build(&mut self) -> Result<Self::Accessor> {
debug!("backend build started: {:?}", &self);
let root = normalize_root(&self.root.take().unwrap_or_default());
debug!("backend use root {}", root);
// Handle endpoint, region and container name.
let container = match self.container.is_empty() {
false => Ok(&self.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.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 client = if let Some(client) = self.http_client.take() {
client
} else {
HttpClient::new().map_err(|err| {
err.with_operation("Builder::build")
.with_context("service", Scheme::Azblob)
})?
};
let config_loader = AzureStorageConfig {
account_name: self
.account_name
.clone()
.or_else(|| infer_storage_name_from_endpoint(endpoint.as_str())),
account_key: self.account_key.clone(),
sas_token: self.sas_token.clone(),
..Default::default()
};
let encryption_key =
match &self.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.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.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();
let batch_max_operations = self.batch_max_operations.unwrap_or(AZBLOB_BATCH_LIMIT);
debug!("backend build finished: {:?}", &self);
Ok(AzblobBackend {
core: Arc::new(AzblobCore {
root,
endpoint,
encryption_key,
encryption_key_sha256,
encryption_algorithm,
container: self.container.clone(),
client,
loader: cred_loader,
signer,
batch_max_operations,
}),
has_sas_token: self.sas_token.is_some(),
})
}