pub use crate::generated::clients::{PageBlobClient, PageBlobClientOptions};
use azure_core::{
credentials::TokenCredential,
http::{
policies::{auth::BearerTokenAuthorizationPolicy, Policy},
Pipeline, Url,
},
tracing, Result,
};
use std::sync::Arc;
impl PageBlobClient {
#[tracing::new("Storage.Blob.PageBlob")]
pub fn new(
blob_url: Url,
credential: Option<Arc<dyn TokenCredential>>,
options: Option<PageBlobClientOptions>,
) -> Result<Self> {
if blob_url.cannot_be_a_base() {
return Err(azure_core::Error::with_message(
azure_core::error::ErrorKind::Other,
format!("{blob_url} is not a valid base URL"),
));
}
let mut options = options.unwrap_or_default();
super::apply_client_defaults(&mut options.client_options);
let mut per_retry_policies: Vec<Arc<dyn Policy>> = Vec::default();
if let Some(token_credential) = credential {
if !blob_url.scheme().starts_with("https") {
return Err(azure_core::Error::with_message(
azure_core::error::ErrorKind::Other,
format!("{blob_url} must use https"),
));
}
per_retry_policies.push(Arc::new(BearerTokenAuthorizationPolicy::new(
token_credential,
vec!["https://storage.azure.com/.default"],
)));
}
let pipeline = Pipeline::new(
option_env!("CARGO_PKG_NAME"),
option_env!("CARGO_PKG_VERSION"),
options.client_options.clone(),
Vec::default(),
per_retry_policies,
None,
);
Ok(Self {
endpoint: blob_url,
version: options.version,
pipeline,
})
}
pub fn url(&self) -> &Url {
&self.endpoint
}
}