Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] get_blob_properties for BlobClient #2014

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

vincenttran-msft
Copy link
Member

@vincenttran-msft vincenttran-msft commented Jan 22, 2025

This PR contains the following:

  • Fleshed out implementation of BlobClient to support get_blob_properties
  • get_blob_properties and simple test cases (get properties with existing blob, container not exists case)

@vincenttran-msft vincenttran-msft marked this pull request as ready for review January 24, 2025 20:39
@vincenttran-msft vincenttran-msft changed the title [Storage] get_blob_properties initial implementation [Storage] get_blob_properties for BlobClient Jan 24, 2025
heaths
heaths previously requested changes Jan 27, 2025
sdk/storage/azure_storage_blob/Cargo.toml Outdated Show resolved Hide resolved
sdk/storage/azure_storage_blob/src/clients/blob_client.rs Outdated Show resolved Hide resolved
sdk/storage/azure_storage_blob/src/clients/blob_client.rs Outdated Show resolved Hide resolved
sdk/storage/azure_storage_blob/src/lib.rs Outdated Show resolved Hide resolved
sdk/storage/azure_storage_blob/src/lib.rs Outdated Show resolved Hide resolved
sdk/storage/azure_storage_blob/tests/test_blob_client.rs Outdated Show resolved Hide resolved
@vincenttran-msft vincenttran-msft dismissed heaths’s stale review January 31, 2025 23:25

Will fix in upcoming PR.

@vincenttran-msft
Copy link
Member Author

Hi @heaths Heath, I have documented the remaining 4 feedback items into my notes, and will address them in the following PR. I have commented out the testcases since they currently rely on static resources and have a hard dependency on some NYI functionality. With that in mind- please let me know if there is any other showstoppers in this specific PR. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't start your module with test_ (the file name). It's already in tests/ and this is redundant. blob_client.rs is perfect.

Comment on lines +4 to +10
// use azure_core_test::recorded;
// use azure_identity::DefaultAzureCredentialBuilder;
// use azure_storage_blob::{BlobBlobClientGetPropertiesOptions, BlobClient, BlobClientOptions};
// use std::{env, error::Error};

// #[recorded::test(live)]
// async fn test_get_blob_properties() -> Result<(), Box<dyn Error>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is all this commented out? If you're not ready to record, fine. But you've already marked them as live-only tests anyway so that's not a concern. We still want to build them to make sure they work.

Comment on lines +12 to +14
pub endpoint: Url,
pub container_name: String,
pub blob_name: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clients shouldn't have public members. We only do that for plain ol' data objects (models). We have thread-safety guarantees for clients and making them mutable violates that. You can add accessors, which is already covered in our guidelines for endpoint.

client: GeneratedBlobClient,
}

impl BlobClient {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other languages, I thought you can only get a BlobClient from a ContainerClient or something i.e., these aren't creatable. If so, they must be exported from both the crate root (re-exported) and from the clients module in which all clients - creatable or gettable - are exported.

Comment on lines +16 to +19
pub(crate) use blob_client::BlobClient as GeneratedBlobClient;

pub use blob_client::BlobClient;
pub use crate::generated::clients::blob_blob_client::BlobBlobClientGetPropertiesOptions;
pub use crate::generated::clients::blob_client::BlobClientOptions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why export them from the root for the crate? Just have the modules within the crate import crate::generated::clients::BlobClient. Re-exporting types only for the crate like this is going to lead to a lot of confusion, I think. It's not typical.

/// Properties of an Azure Storage blob.
///
#[derive(Clone, Default, Debug)]
pub struct BlobProperties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model properties must all be Option<T>.

}

impl BlobProperties {
pub(crate) fn build_from_response_headers(response_headers: &Headers) -> BlobProperties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FromHeaders and AsHeaders.

};
for (key, value) in response_headers.iter() {
match key.as_str() {
"content-length" => properties.content_length = String::from(value.as_str()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some, like this, aren't strings. Why are you parsing them as such? You should use our header traits and even define a header. We also have a bunch of these already defined as HeaderNames that you should use for consistency.

"content-length" => properties.content_length = String::from(value.as_str()),
"content-md5" => properties.content_md5 = String::from(value.as_str()),
"content-type" => properties.content_type = String::from(value.as_str()),
"etag" => properties.etag = String::from(value.as_str()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use our existing Etag header type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants