Skip to content

Commit

Permalink
add blob service client get properties (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
demoray authored Dec 7, 2023
1 parent a0b9067 commit da2e429
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
7 changes: 4 additions & 3 deletions sdk/storage_blobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ edition = "2021"
[dependencies]
azure_core = { path = "../core", version = "0.17", features = ["xml"] }
azure_storage = { path = "../storage", version = "0.17", default-features = false }
azure_svc_blobstorage = {path="../../services/svc/blobstorage", version="0.17", default-features=false, features=["default_tag"]}
bytes = "1.0"
time = "0.3.10"
futures = "0.3"
Expand All @@ -38,12 +39,12 @@ clap = { version = "4.0", features = ["derive", "env"] }
azure_core = {path = "../core", version = "0.17", features = ["tokio-fs"]}

[features]
default = ["enable_reqwest"]
default = ["enable_reqwest", "hmac_rust"]
test_e2e = []
test_integration = []
azurite_workaround = ["azure_core/azurite_workaround"]
enable_reqwest = ["azure_core/enable_reqwest", "azure_storage/enable_reqwest"]
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls", "azure_storage/enable_reqwest_rustls"]
enable_reqwest = ["azure_core/enable_reqwest", "azure_storage/enable_reqwest", "azure_svc_blobstorage/enable_reqwest"]
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls", "azure_storage/enable_reqwest_rustls", "azure_svc_blobstorage/enable_reqwest_rustls"]
md5 = ["dep:md5"]
hmac_rust = ["azure_core/hmac_rust"]
hmac_openssl = ["azure_core/hmac_openssl"]
Expand Down
20 changes: 20 additions & 0 deletions sdk/storage_blobs/examples/service_properties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use azure_storage::prelude::*;
use azure_storage_blobs::prelude::*;

#[tokio::main]
async fn main() -> azure_core::Result<()> {
env_logger::init();
// First we retrieve the account name and access key from environment variables.
let account =
std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
let access_key =
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");

let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
let service_client = BlobServiceClient::new(account, storage_credentials);

let properties = service_client.get_properties().await?;
println!("properties: {:#?}", properties);

Ok(())
}
11 changes: 8 additions & 3 deletions sdk/storage_blobs/src/clients/blob_service_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::service::operations::*;
use crate::{
clients::{BlobClient, BlobLeaseClient, ContainerClient, ContainerLeaseClient},
service::operations::*,
};
use azure_core::{
headers::Headers, request_options::LeaseId, Body, ClientOptions, Context, Method, Pipeline,
Request, Response, Url,
Expand All @@ -11,8 +14,6 @@ use azure_storage::{
};
use time::OffsetDateTime;

use super::{BlobClient, BlobLeaseClient, ContainerClient, ContainerLeaseClient};

/// A builder for the blob service client.
#[derive(Debug, Clone)]
pub struct ClientBuilder {
Expand Down Expand Up @@ -196,6 +197,10 @@ impl BlobServiceClient {
ListContainersBuilder::new(self.clone())
}

pub fn get_properties(&self) -> GetBlobServicePropertiesBuilder {
GetBlobServicePropertiesBuilder::new(self.clone())
}

pub fn url(&self) -> azure_core::Result<Url> {
self.cloud_location.url(ServiceType::Blob)
}
Expand Down
7 changes: 5 additions & 2 deletions sdk/storage_blobs/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
pub use super::container::PublicAccess;
pub use crate::options::*;
pub use crate::{
blob::{Blob, BlobBlockType, BlockList, BlockListType},
clients::{
BlobClient, BlobLeaseClient, BlobServiceClient, ClientBuilder, ContainerClient,
ContainerLeaseClient,
},
container::PublicAccess,
options::*,
};
pub use azure_storage::{StoredAccessPolicy, StoredAccessPolicyList};
pub use azure_svc_blobstorage::models::{
storage_service_properties::Cors, CorsRule, Logging, Metrics, RetentionPolicy, StaticWebsite,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::prelude::BlobServiceClient;
use azure_core::headers::Headers;
use azure_core::{Method, Response};
use azure_storage::headers::CommonStorageResponseHeaders;
use azure_svc_blobstorage::models::StorageServiceProperties;

operation! {
GetBlobServiceProperties,
client: BlobServiceClient,
}

impl GetBlobServicePropertiesBuilder {
pub fn into_future(mut self) -> GetBlobServiceProperties {
Box::pin(async move {
let mut url = self.client.url()?;

url.query_pairs_mut()
.extend_pairs([("restype", "service"), ("comp", "properties")]);

let mut request =
BlobServiceClient::finalize_request(url, Method::Get, Headers::new(), None)?;

let response = self.client.send(&mut self.context, &mut request).await?;

GetBlobServicePropertiesResponse::try_from(response).await
})
}
}

#[derive(Debug, Clone)]
pub struct GetBlobServicePropertiesResponse {
pub common: CommonStorageResponseHeaders,
pub properties: StorageServiceProperties,
}

impl GetBlobServicePropertiesResponse {
pub(crate) async fn try_from(
response: Response,
) -> azure_core::Result<GetBlobServicePropertiesResponse> {
let common = CommonStorageResponseHeaders::try_from(response.headers())?;
let body = response.into_body().collect().await?;
println!("body {body:?}");
let properties = azure_core::xml::read_xml(&body)?;

Ok(GetBlobServicePropertiesResponse { common, properties })
}
}
2 changes: 2 additions & 0 deletions sdk/storage_blobs/src/service/operations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod find_blobs_by_tags;
mod get_account_information;
mod get_blob_service_properties;
mod get_user_delegation_key;
mod list_containers;

pub use find_blobs_by_tags::*;
pub use get_account_information::*;
pub use get_blob_service_properties::*;
pub use get_user_delegation_key::*;
pub use list_containers::*;

0 comments on commit da2e429

Please sign in to comment.