use crate::clients::FileSystemClient;
use crate::operations::ListFileSystemsBuilder;
use azure_core::{ClientOptions, Pipeline};
use azure_storage::clients::{new_pipeline_from_options, ServiceType};
use azure_storage::prelude::StorageCredentials;
use azure_storage::CloudLocation;
#[derive(Debug, Clone)]
pub struct DataLakeClientBuilder {
cloud_location: CloudLocation,
options: ClientOptions,
}
impl DataLakeClientBuilder {
#[must_use]
pub fn new(account: impl Into<String>, credentials: StorageCredentials) -> Self {
Self::with_location(CloudLocation::Public {
account: account.into(),
credentials,
})
}
#[must_use]
pub fn with_location(cloud_location: CloudLocation) -> Self {
Self {
options: ClientOptions::default(),
cloud_location,
}
}
#[must_use]
pub fn build(self) -> DataLakeClient {
let credentials = self.cloud_location.credentials();
DataLakeClient {
pipeline: new_pipeline_from_options(self.options, credentials.clone()),
cloud_location: self.cloud_location,
}
}
#[must_use]
pub fn cloud_location(mut self, cloud_location: CloudLocation) -> Self {
self.cloud_location = cloud_location;
self
}
#[must_use]
pub fn retry(mut self, retry: impl Into<azure_core::RetryOptions>) -> Self {
self.options = self.options.retry(retry);
self
}
#[must_use]
pub fn transport(mut self, transport: impl Into<azure_core::TransportOptions>) -> Self {
self.options = self.options.transport(transport);
self
}
#[must_use]
pub fn client_options(mut self, options: impl Into<azure_core::ClientOptions>) -> Self {
self.options = options.into();
self
}
}
#[derive(Debug, Clone)]
pub struct DataLakeClient {
pipeline: Pipeline,
cloud_location: CloudLocation,
}
impl DataLakeClient {
pub fn new(account: impl Into<String>, credentials: StorageCredentials) -> Self {
DataLakeClientBuilder::new(account, credentials).build()
}
#[must_use]
pub fn builder(
account: impl Into<String>,
credentials: StorageCredentials,
) -> DataLakeClientBuilder {
DataLakeClientBuilder::new(account, credentials)
}
pub(crate) fn url(&self) -> azure_core::Result<url::Url> {
self.cloud_location.url(ServiceType::DataLake)
}
pub fn list_file_systems(&self) -> ListFileSystemsBuilder {
ListFileSystemsBuilder::new(self.clone())
}
pub fn file_system_client<FS>(&self, file_system_name: FS) -> FileSystemClient
where
FS: Into<String>,
{
FileSystemClient::new(self.clone(), file_system_name.into())
}
pub(crate) async fn send(
&self,
ctx: &mut azure_core::Context,
request: &mut azure_core::Request,
) -> azure_core::Result<azure_core::Response> {
let mut r = azure_storage::clients::finalize_request(
request.url().clone(),
*request.method(),
request.headers().clone(),
Some(request.body().clone()),
)?;
let result = self
.pipeline
.send(ctx.insert(ServiceType::DataLake), &mut r)
.await;
*request = r;
result
}
}