use crate::{operations::*, QueueClient, QueueServiceProperties};
use azure_core::{ClientOptions, Context, Pipeline, Request, Response};
use azure_storage::{
clients::{new_pipeline_from_options, ServiceType},
prelude::StorageCredentials,
CloudLocation,
};
use std::fmt::Debug;
#[derive(Debug, Clone)]
pub struct QueueServiceClientBuilder {
cloud_location: CloudLocation,
options: ClientOptions,
}
impl QueueServiceClientBuilder {
#[must_use]
pub fn new(account: impl Into<String>, credentials: impl Into<StorageCredentials>) -> Self {
Self::with_location(CloudLocation::Public {
account: account.into(),
credentials: credentials.into(),
})
}
#[must_use]
pub fn with_location(cloud_location: CloudLocation) -> Self {
Self {
options: ClientOptions::default(),
cloud_location,
}
}
#[must_use]
pub fn emulator() -> Self {
Self::with_location(CloudLocation::Emulator {
address: "127.0.0.1".to_owned(),
port: 10001,
})
}
#[must_use]
pub fn build(self) -> QueueServiceClient {
let credentials = self.cloud_location.credentials();
QueueServiceClient {
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 QueueServiceClient {
pipeline: Pipeline,
cloud_location: CloudLocation,
}
impl QueueServiceClient {
#[must_use]
pub fn new(account: impl Into<String>, credentials: impl Into<StorageCredentials>) -> Self {
QueueServiceClientBuilder::new(account, credentials).build()
}
pub fn list_queues(&self) -> ListQueuesBuilder {
ListQueuesBuilder::new(self.clone())
}
pub fn get_queue_service_properties(&self) -> GetQueueServicePropertiesBuilder {
GetQueueServicePropertiesBuilder::new(self.clone())
}
pub fn set_queue_service_properties(
&self,
properties: QueueServiceProperties,
) -> SetQueueServicePropertiesBuilder {
SetQueueServicePropertiesBuilder::new(self.clone(), properties)
}
pub fn get_queue_service_stats(&self) -> GetQueueServiceStatsBuilder {
GetQueueServiceStatsBuilder::new(self.clone())
}
pub fn queue_client<S: Into<String>>(&self, queue_name: S) -> QueueClient {
QueueClient::new(self.clone(), queue_name.into())
}
pub fn url(&self) -> azure_core::Result<url::Url> {
self.cloud_location.url(ServiceType::Queue)
}
pub(crate) fn finalize_request(
&self,
url: url::Url,
method: azure_core::Method,
headers: azure_core::headers::Headers,
request_body: Option<azure_core::Body>,
) -> azure_core::Result<Request> {
azure_storage::clients::finalize_request(url, method, headers, request_body)
}
pub(crate) async fn send(
&self,
context: &mut Context,
request: &mut Request,
) -> azure_core::Result<Response> {
self.pipeline
.send(context.insert(ServiceType::Queue), request)
.await
}
}