Skip to content

[Storage] list_containers for BlobServiceClient #2692

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

use crate::{
generated::clients::BlobServiceClient as GeneratedBlobServiceClient,
models::{BlobServiceClientGetPropertiesOptions, StorageServiceProperties},
models::{
BlobServiceClientGetPropertiesOptions, BlobServiceClientListContainersSegmentOptions,
ListContainersSegmentResponse, StorageServiceProperties,
},
pipeline::StorageHeadersPolicy,
BlobContainerClient, BlobServiceClientOptions,
};
use azure_core::{
credentials::TokenCredential,
http::{
policies::{BearerTokenCredentialPolicy, Policy},
Response, Url, XmlFormat,
PageIterator, Response, Url, XmlFormat,
},
Result,
};
Expand Down Expand Up @@ -89,4 +92,16 @@ impl BlobServiceClient {
) -> Result<Response<StorageServiceProperties, XmlFormat>> {
self.client.get_properties(options).await
}

/// Returns a list of the containers under the specified Storage account.
///
/// # Arguments
///
/// * `options` - Optional configuration for the request.
pub fn list_containers(
&self,
options: Option<BlobServiceClientListContainersSegmentOptions<'_>>,
) -> Result<PageIterator<Response<ListContainersSegmentResponse, XmlFormat>>> {
self.client.list_containers_segment(options)
}
}
7 changes: 4 additions & 3 deletions sdk/storage/azure_storage_blob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ pub mod models {
BlobContainerClientGetPropertiesOptions, BlobContainerClientGetPropertiesResult,
BlobContainerClientGetPropertiesResultHeaders,
BlobContainerClientListBlobFlatSegmentOptions, BlobContainerClientSetMetadataOptions,
BlobImmutabilityPolicyMode, BlobServiceClientGetPropertiesOptions, BlobType,
BlobImmutabilityPolicyMode, BlobServiceClientGetPropertiesOptions,
BlobServiceClientListContainersSegmentOptions, BlobType,
BlockBlobClientCommitBlockListOptions, BlockBlobClientCommitBlockListResult,
BlockBlobClientGetBlockListOptions, BlockBlobClientStageBlockOptions,
BlockBlobClientStageBlockResult, BlockBlobClientUploadOptions, BlockBlobClientUploadResult,
BlockList, BlockListType, BlockLookupList, CopyStatus, LeaseState, LeaseStatus,
ListBlobsFlatSegmentResponse, PublicAccessType, RehydratePriority,
StorageServiceProperties,
ListBlobsFlatSegmentResponse, ListContainersSegmentResponse, PublicAccessType,
RehydratePriority, StorageServiceProperties,
};
}
67 changes: 67 additions & 0 deletions sdk/storage/azure_storage_blob/tests/blob_service_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use azure_core_test::{recorded, TestContext};
use azure_storage_blob::models::BlobServiceClientGetPropertiesOptions;
use azure_storage_blob_test::get_blob_service_client;
use futures::StreamExt;
use std::error::Error;

#[recorded::test]
Expand All @@ -22,3 +23,69 @@ async fn test_get_service_properties(ctx: TestContext) -> Result<(), Box<dyn Err
assert!(hour_metrics.is_some());
Ok(())
}

// #[recorded::test]
// async fn test_list_containers(ctx: TestContext) -> Result<(), Box<dyn Error>> {
// // Recording Setup
// let recording = ctx.recording();
// let service_client = get_blob_service_client(recording)?;
// let container_names = [
// "testcontainer1".to_string(),
// "testcontainer2".to_string(),
// "testcontainer3".to_string(),
// "testcontainer4".to_string(),
// ];
// let mut container_clients = Vec::new();
// for container_name in container_names.clone() {
// let container_client = service_client.blob_container_client(container_name);
// container_client.create_container(None).await?;
// container_clients.push(container_client);
// }

// // Assert
// let mut pager_response = service_client.list_containers(None)?;
// while let Some(page) = pager_response.next().await {
// let current_page = page.unwrap().into_body().await?;
// let container_list = current_page.container_items;
// for container in container_list {
// let container_name = container.name.unwrap();
// assert!(container_names.contains(&container_name));
// }
// }

// for container_client in container_clients {
// container_client.delete_container(None).await?;
// }

// Ok(())
// }

#[recorded::test]
async fn test_list_containers_singleton(ctx: TestContext) -> Result<(), Box<dyn Error>> {
// Recording Setup
let recording = ctx.recording();
let service_client = get_blob_service_client(recording)?;
let container_client = service_client.blob_container_client("testcontainer".to_string());
container_client.create_container(None).await?;

// Assert
let mut pager_response = service_client.list_containers(None)?;
while let Some(page) = pager_response.next().await {
let current_page = page.unwrap().into_body().await?;
let container_list = current_page.container_items;
for container in container_list {
println!("Is Deleted Option Some: {}", container.delete.is_some());
println!("Is Metadata Option Some: {}", container.metadata.is_some());
println!("Is Name Option Some: {}", container.name.is_some());
println!(
"Is Properties Option Some: {}",
container.properties.is_some()
);
println!("Is Version Option Some: {}", container.version.is_some());
}
}
Comment on lines +72 to +86
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main area of concern- here I would expect is_some() to return something, for at the very very least name but also the other fields.

Copy link
Member

@jhendrixMSFT jhendrixMSFT Jun 10, 2025

Choose a reason for hiding this comment

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

This will be fixed as part of https://github.com/Azure/typespec-rust/pull/455


container_client.delete_container(None).await?;

Ok(())
}
Loading