Skip to content

Commit 2368a67

Browse files
[Storage] find_blobs_by_tags for BlobServiceClient and BlobContainerClient (#2973)
1 parent ca68ec5 commit 2368a67

File tree

19 files changed

+393
-166
lines changed

19 files changed

+393
-166
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"etag",
5151
"eventhub",
5252
"eventhubs",
53+
"headerless",
5354
"hmac",
5455
"iothub",
5556
"keyvault",

sdk/storage/.dict.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ blockid
55
blocklist
66
blocklisttype
77
copyid
8+
deletedwithversions
89
deletetype
10+
firsttag
11+
immutabilitypolicy
912
incrementalcopy
1013
legalhold
1114
missingcontainer
12-
RAGRS
13-
restype
14-
testcontainer
1515
pagelist
16-
prevsnapshot
17-
deletedwithversions
18-
immutabilitypolicy
19-
uncommittedblobs
2016
policyid
17+
prevsnapshot
18+
RAGRS
19+
restype
2120
ruleid
22-
westus
21+
secondtag
2322
testblob1
2423
testblob2
2524
testblob3
2625
testblob4
26+
testcontainer
27+
uncommittedblobs
28+
westus
29+
yourtagname
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
4-
"Tag": "rust/azure_storage_blob_3bece8d6c3",
4+
"Tag": "rust/azure_storage_blob_094782fa40",
55
"TagPrefix": "rust/azure_storage_blob"
66
}

sdk/storage/azure_storage_blob/src/clients/blob_container_client.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use crate::{
1212
models::{
1313
BlobContainerClientAcquireLeaseOptions, BlobContainerClientBreakLeaseOptions,
1414
BlobContainerClientChangeLeaseOptions, BlobContainerClientCreateOptions,
15-
BlobContainerClientDeleteOptions, BlobContainerClientGetAccountInfoOptions,
16-
BlobContainerClientGetPropertiesOptions, BlobContainerClientListBlobFlatSegmentOptions,
17-
BlobContainerClientReleaseLeaseOptions, BlobContainerClientRenewLeaseOptions,
18-
BlobContainerClientSetMetadataOptions, ListBlobsFlatSegmentResponse,
15+
BlobContainerClientDeleteOptions, BlobContainerClientFindBlobsByTagsOptions,
16+
BlobContainerClientGetAccountInfoOptions, BlobContainerClientGetPropertiesOptions,
17+
BlobContainerClientListBlobFlatSegmentOptions, BlobContainerClientReleaseLeaseOptions,
18+
BlobContainerClientRenewLeaseOptions, BlobContainerClientSetMetadataOptions,
19+
FilterBlobSegment, ListBlobsFlatSegmentResponse,
1920
},
2021
pipeline::StorageHeadersPolicy,
2122
BlobClient, BlobContainerClientOptions,
@@ -159,6 +160,31 @@ impl BlobContainerClient {
159160
self.client.list_blob_flat_segment(options)
160161
}
161162

163+
/// Returns a list of blobs in the container whose tags match a given search expression.
164+
///
165+
/// # Arguments
166+
///
167+
/// * `filter_expression` - The expression to find blobs whose tags matches the specified condition.
168+
/// eg.
169+
/// ```text
170+
/// "\"yourtagname\"='firsttag' and \"yourtagname2\"='secondtag'"
171+
/// ```
172+
/// To specify a container, eg.
173+
/// ```text
174+
/// "@container='containerName' and \"Name\"='C'"
175+
/// ```
176+
/// See [`format_filter_expression()`](crate::format_filter_expression) for help with the expected String format.
177+
/// * `options` - Optional parameters for the request.
178+
pub async fn find_blobs_by_tags(
179+
&self,
180+
filter_expression: &str,
181+
options: Option<BlobContainerClientFindBlobsByTagsOptions<'_>>,
182+
) -> Result<Response<FilterBlobSegment, XmlFormat>> {
183+
self.client
184+
.find_blobs_by_tags(filter_expression, options)
185+
.await
186+
}
187+
162188
/// Requests a new lease on a container. The lease lock duration can be 15 to 60 seconds, or can be infinite.
163189
///
164190
/// # Arguments

sdk/storage/azure_storage_blob/src/clients/blob_service_client.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::{
55
generated::clients::BlobServiceClient as GeneratedBlobServiceClient,
66
generated::models::BlobServiceClientGetAccountInfoResult,
77
models::{
8-
BlobServiceClientGetAccountInfoOptions, BlobServiceClientGetPropertiesOptions,
9-
BlobServiceClientListContainersSegmentOptions, BlobServiceClientSetPropertiesOptions,
10-
BlobServiceProperties, ListContainersSegmentResponse,
8+
BlobServiceClientFindBlobsByTagsOptions, BlobServiceClientGetAccountInfoOptions,
9+
BlobServiceClientGetPropertiesOptions, BlobServiceClientListContainersSegmentOptions,
10+
BlobServiceClientSetPropertiesOptions, BlobServiceProperties, FilterBlobSegment,
11+
ListContainersSegmentResponse,
1112
},
1213
pipeline::StorageHeadersPolicy,
1314
BlobContainerClient, BlobServiceClientOptions,
@@ -98,6 +99,31 @@ impl BlobServiceClient {
9899
self.client.list_containers_segment(options)
99100
}
100101

102+
/// Returns a list of blobs across all containers whose tags match a given search expression.
103+
///
104+
/// # Arguments
105+
///
106+
/// * `filter_expression` - The expression to find blobs whose tags matches the specified condition.
107+
/// eg.
108+
/// ```text
109+
/// "\"yourtagname\"='firsttag' and \"yourtagname2\"='secondtag'"
110+
/// ```
111+
/// To specify a container, eg.
112+
/// ```text
113+
/// "@container='containerName' and \"Name\"='C'"
114+
/// ```
115+
/// See [`format_filter_expression()`](crate::format_filter_expression) for help with the expected String format.
116+
/// * `options` - Optional parameters for the request.
117+
pub async fn find_blobs_by_tags(
118+
&self,
119+
filter_expression: &str,
120+
options: Option<BlobServiceClientFindBlobsByTagsOptions<'_>>,
121+
) -> Result<Response<FilterBlobSegment, XmlFormat>> {
122+
self.client
123+
.find_blobs_by_tags(filter_expression, options)
124+
.await
125+
}
126+
101127
/// Sets properties for a Storage account's Blob service endpoint, including properties for Storage Analytics and CORS rules.
102128
///
103129
/// # Arguments

sdk/storage/azure_storage_blob/src/generated/clients/blob_container_client.rs

Lines changed: 8 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/generated/clients/blob_service_client.rs

Lines changed: 8 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/generated/models/header_traits.rs

Lines changed: 2 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/generated/models/method_options.rs

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/models/extensions.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::models::{
55
AppendBlobClientCreateOptions, BlobTag, BlobTags, BlockBlobClientUploadBlobFromUrlOptions,
6-
PageBlobClientCreateOptions,
6+
BlockBlobClientUploadOptions, PageBlobClientCreateOptions,
77
};
88
use azure_core::error::ErrorKind;
99
use std::collections::HashMap;
@@ -47,6 +47,26 @@ impl<'a> BlockBlobClientUploadBlobFromUrlOptions<'a> {
4747
}
4848
}
4949

50+
/// Augments the current options bag to include blob tags.
51+
/// # Arguments
52+
///
53+
/// * `self` - The options bag to be modified.
54+
/// * `tags` - A HashMap of key-value pairs representing the blob tags.
55+
impl<'a> BlockBlobClientUploadOptions<'a> {
56+
pub fn with_tags(self, tags: HashMap<String, String>) -> Self {
57+
let tags_string = tags
58+
.iter()
59+
.map(|(key, value)| format!("{}={}", key, value))
60+
.collect::<Vec<_>>()
61+
.join("&");
62+
63+
Self {
64+
blob_tags_string: Some(tags_string),
65+
..self
66+
}
67+
}
68+
}
69+
5070
/// Converts a `BlobTags` struct into `HashMap<String, String>`.
5171
impl TryFrom<BlobTags> for HashMap<String, String> {
5272
type Error = azure_core::Error;

0 commit comments

Comments
 (0)