Skip to content

Commit da2e429

Browse files
authored
add blob service client get properties (#1499)
1 parent a0b9067 commit da2e429

File tree

6 files changed

+86
-8
lines changed

6 files changed

+86
-8
lines changed

sdk/storage_blobs/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ edition = "2021"
1515
[dependencies]
1616
azure_core = { path = "../core", version = "0.17", features = ["xml"] }
1717
azure_storage = { path = "../storage", version = "0.17", default-features = false }
18+
azure_svc_blobstorage = {path="../../services/svc/blobstorage", version="0.17", default-features=false, features=["default_tag"]}
1819
bytes = "1.0"
1920
time = "0.3.10"
2021
futures = "0.3"
@@ -38,12 +39,12 @@ clap = { version = "4.0", features = ["derive", "env"] }
3839
azure_core = {path = "../core", version = "0.17", features = ["tokio-fs"]}
3940

4041
[features]
41-
default = ["enable_reqwest"]
42+
default = ["enable_reqwest", "hmac_rust"]
4243
test_e2e = []
4344
test_integration = []
4445
azurite_workaround = ["azure_core/azurite_workaround"]
45-
enable_reqwest = ["azure_core/enable_reqwest", "azure_storage/enable_reqwest"]
46-
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls", "azure_storage/enable_reqwest_rustls"]
46+
enable_reqwest = ["azure_core/enable_reqwest", "azure_storage/enable_reqwest", "azure_svc_blobstorage/enable_reqwest"]
47+
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls", "azure_storage/enable_reqwest_rustls", "azure_svc_blobstorage/enable_reqwest_rustls"]
4748
md5 = ["dep:md5"]
4849
hmac_rust = ["azure_core/hmac_rust"]
4950
hmac_openssl = ["azure_core/hmac_openssl"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use azure_storage::prelude::*;
2+
use azure_storage_blobs::prelude::*;
3+
4+
#[tokio::main]
5+
async fn main() -> azure_core::Result<()> {
6+
env_logger::init();
7+
// First we retrieve the account name and access key from environment variables.
8+
let account =
9+
std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
10+
let access_key =
11+
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
12+
13+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
14+
let service_client = BlobServiceClient::new(account, storage_credentials);
15+
16+
let properties = service_client.get_properties().await?;
17+
println!("properties: {:#?}", properties);
18+
19+
Ok(())
20+
}

sdk/storage_blobs/src/clients/blob_service_client.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::service::operations::*;
1+
use crate::{
2+
clients::{BlobClient, BlobLeaseClient, ContainerClient, ContainerLeaseClient},
3+
service::operations::*,
4+
};
25
use azure_core::{
36
headers::Headers, request_options::LeaseId, Body, ClientOptions, Context, Method, Pipeline,
47
Request, Response, Url,
@@ -11,8 +14,6 @@ use azure_storage::{
1114
};
1215
use time::OffsetDateTime;
1316

14-
use super::{BlobClient, BlobLeaseClient, ContainerClient, ContainerLeaseClient};
15-
1617
/// A builder for the blob service client.
1718
#[derive(Debug, Clone)]
1819
pub struct ClientBuilder {
@@ -196,6 +197,10 @@ impl BlobServiceClient {
196197
ListContainersBuilder::new(self.clone())
197198
}
198199

200+
pub fn get_properties(&self) -> GetBlobServicePropertiesBuilder {
201+
GetBlobServicePropertiesBuilder::new(self.clone())
202+
}
203+
199204
pub fn url(&self) -> azure_core::Result<Url> {
200205
self.cloud_location.url(ServiceType::Blob)
201206
}

sdk/storage_blobs/src/prelude.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
pub use super::container::PublicAccess;
2-
pub use crate::options::*;
31
pub use crate::{
42
blob::{Blob, BlobBlockType, BlockList, BlockListType},
53
clients::{
64
BlobClient, BlobLeaseClient, BlobServiceClient, ClientBuilder, ContainerClient,
75
ContainerLeaseClient,
86
},
7+
container::PublicAccess,
8+
options::*,
99
};
1010
pub use azure_storage::{StoredAccessPolicy, StoredAccessPolicyList};
11+
pub use azure_svc_blobstorage::models::{
12+
storage_service_properties::Cors, CorsRule, Logging, Metrics, RetentionPolicy, StaticWebsite,
13+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use crate::prelude::BlobServiceClient;
2+
use azure_core::headers::Headers;
3+
use azure_core::{Method, Response};
4+
use azure_storage::headers::CommonStorageResponseHeaders;
5+
use azure_svc_blobstorage::models::StorageServiceProperties;
6+
7+
operation! {
8+
GetBlobServiceProperties,
9+
client: BlobServiceClient,
10+
}
11+
12+
impl GetBlobServicePropertiesBuilder {
13+
pub fn into_future(mut self) -> GetBlobServiceProperties {
14+
Box::pin(async move {
15+
let mut url = self.client.url()?;
16+
17+
url.query_pairs_mut()
18+
.extend_pairs([("restype", "service"), ("comp", "properties")]);
19+
20+
let mut request =
21+
BlobServiceClient::finalize_request(url, Method::Get, Headers::new(), None)?;
22+
23+
let response = self.client.send(&mut self.context, &mut request).await?;
24+
25+
GetBlobServicePropertiesResponse::try_from(response).await
26+
})
27+
}
28+
}
29+
30+
#[derive(Debug, Clone)]
31+
pub struct GetBlobServicePropertiesResponse {
32+
pub common: CommonStorageResponseHeaders,
33+
pub properties: StorageServiceProperties,
34+
}
35+
36+
impl GetBlobServicePropertiesResponse {
37+
pub(crate) async fn try_from(
38+
response: Response,
39+
) -> azure_core::Result<GetBlobServicePropertiesResponse> {
40+
let common = CommonStorageResponseHeaders::try_from(response.headers())?;
41+
let body = response.into_body().collect().await?;
42+
println!("body {body:?}");
43+
let properties = azure_core::xml::read_xml(&body)?;
44+
45+
Ok(GetBlobServicePropertiesResponse { common, properties })
46+
}
47+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
mod find_blobs_by_tags;
22
mod get_account_information;
3+
mod get_blob_service_properties;
34
mod get_user_delegation_key;
45
mod list_containers;
56

67
pub use find_blobs_by_tags::*;
78
pub use get_account_information::*;
9+
pub use get_blob_service_properties::*;
810
pub use get_user_delegation_key::*;
911
pub use list_containers::*;

0 commit comments

Comments
 (0)