azure_storage_blob/clients/
page_blob_client.rs1pub use crate::generated::clients::{PageBlobClient, PageBlobClientOptions};
5
6use azure_core::{
7 credentials::TokenCredential,
8 http::{
9 policies::{auth::BearerTokenAuthorizationPolicy, Policy},
10 Pipeline, Url,
11 },
12 tracing, Result,
13};
14use std::sync::Arc;
15
16impl PageBlobClient {
17 #[tracing::new("Storage.Blob.PageBlob")]
26 pub fn new(
27 blob_url: Url,
28 credential: Option<Arc<dyn TokenCredential>>,
29 options: Option<PageBlobClientOptions>,
30 ) -> Result<Self> {
31 if blob_url.cannot_be_a_base() {
33 return Err(azure_core::Error::with_message(
34 azure_core::error::ErrorKind::Other,
35 format!("{blob_url} is not a valid base URL"),
36 ));
37 }
38
39 let mut options = options.unwrap_or_default();
40 super::apply_client_defaults(&mut options.client_options);
41
42 let mut per_retry_policies: Vec<Arc<dyn Policy>> = Vec::default();
43 if let Some(token_credential) = credential {
44 if !blob_url.scheme().starts_with("https") {
45 return Err(azure_core::Error::with_message(
46 azure_core::error::ErrorKind::Other,
47 format!("{blob_url} must use https"),
48 ));
49 }
50 per_retry_policies.push(Arc::new(BearerTokenAuthorizationPolicy::new(
51 token_credential,
52 vec!["https://storage.azure.com/.default"],
53 )));
54 }
55
56 let pipeline = Pipeline::new(
57 option_env!("CARGO_PKG_NAME"),
58 option_env!("CARGO_PKG_VERSION"),
59 options.client_options.clone(),
60 Vec::default(),
61 per_retry_policies,
62 None,
63 );
64
65 Ok(Self {
66 endpoint: blob_url,
67 version: options.version,
68 pipeline,
69 })
70 }
71
72 pub fn url(&self) -> &Url {
74 &self.endpoint
75 }
76}