Skip to content

Commit ff85ac8

Browse files
[Storage] Lease operations for BlobClient and BlobContainerClient, feature parity for AppendBlobClient (Azure#2739)
1 parent 44b3262 commit ff85ac8

File tree

13 files changed

+611
-134
lines changed

13 files changed

+611
-134
lines changed

sdk/storage/assets.json

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_83b2698a78",
4+
"Tag": "rust/azure_storage_blob_f12afa9550",
55
"TagPrefix": "rust/azure_storage_blob"
66
}

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

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

44
use crate::{
55
generated::clients::AppendBlobClient as GeneratedAppendBlobClient,
6-
models::{AppendBlobClientCreateOptions, AppendBlobClientCreateResult},
6+
models::{
7+
AppendBlobClientAppendBlockFromUrlOptions, AppendBlobClientAppendBlockFromUrlResult,
8+
AppendBlobClientAppendBlockOptions, AppendBlobClientAppendBlockResult,
9+
AppendBlobClientCreateOptions, AppendBlobClientCreateResult, AppendBlobClientSealOptions,
10+
AppendBlobClientSealResult,
11+
},
712
pipeline::StorageHeadersPolicy,
813
AppendBlobClientOptions, BlobClientOptions,
914
};
@@ -97,4 +102,53 @@ impl AppendBlobClient {
97102
) -> Result<Response<AppendBlobClientCreateResult, NoFormat>> {
98103
self.client.create(options).await
99104
}
105+
106+
/// Commits a new block of data to the end of an Append blob.
107+
///
108+
/// # Arguments
109+
///
110+
/// * `data` - The blob data to append.
111+
/// * `content_length` - Total length of the blob data to be appended.
112+
/// * `options` - Optional configuration for the request.
113+
pub async fn append_block(
114+
&self,
115+
data: RequestContent<Bytes>,
116+
content_length: u64,
117+
options: Option<AppendBlobClientAppendBlockOptions<'_>>,
118+
) -> Result<Response<AppendBlobClientAppendBlockResult, NoFormat>> {
119+
self.client
120+
.append_block(data, content_length, options)
121+
.await
122+
}
123+
124+
/// Creates a new block to be committed as part of an Append blob where the contents are
125+
/// read from a URL.
126+
///
127+
/// # Arguments
128+
///
129+
/// * `source_url` - The URL of the copy source.
130+
/// * `content_length` - Total length of the blob data to be appended.
131+
/// * `options` - Optional configuration for the request.
132+
pub async fn append_block_from_url(
133+
&self,
134+
source_url: String,
135+
content_length: u64,
136+
options: Option<AppendBlobClientAppendBlockFromUrlOptions<'_>>,
137+
) -> Result<Response<AppendBlobClientAppendBlockFromUrlResult, NoFormat>> {
138+
self.client
139+
.append_block_from_url(source_url, content_length, options)
140+
.await
141+
}
142+
143+
/// Seals the Append blob to make it read-only. Seal is supported only on version 2019-12-12 or later.
144+
///
145+
/// # Arguments
146+
///
147+
/// * `options` - Optional parameters for the request.
148+
pub async fn seal(
149+
&self,
150+
options: Option<AppendBlobClientSealOptions<'_>>,
151+
) -> Result<Response<AppendBlobClientSealResult, NoFormat>> {
152+
self.client.seal(options).await
153+
}
100154
}

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

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
use crate::{
55
generated::clients::BlobClient as GeneratedBlobClient,
66
generated::models::{
7-
BlobClientDownloadResult, BlobClientGetPropertiesResult,
8-
BlockBlobClientCommitBlockListResult, BlockBlobClientStageBlockResult,
9-
BlockBlobClientUploadResult,
7+
BlobClientAcquireLeaseResult, BlobClientBreakLeaseResult, BlobClientChangeLeaseResult,
8+
BlobClientDownloadResult, BlobClientGetPropertiesResult, BlobClientReleaseLeaseResult,
9+
BlobClientRenewLeaseResult, BlockBlobClientCommitBlockListResult,
10+
BlockBlobClientStageBlockResult, BlockBlobClientUploadResult,
1011
},
1112
models::{
12-
AccessTierOptional, BlobClientDeleteOptions, BlobClientDownloadOptions,
13-
BlobClientGetPropertiesOptions, BlobClientSetMetadataOptions,
14-
BlobClientSetPropertiesOptions, BlobClientSetTierOptions,
13+
AccessTierOptional, BlobClientAcquireLeaseOptions, BlobClientBreakLeaseOptions,
14+
BlobClientChangeLeaseOptions, BlobClientDeleteOptions, BlobClientDownloadOptions,
15+
BlobClientGetPropertiesOptions, BlobClientReleaseLeaseOptions, BlobClientRenewLeaseOptions,
16+
BlobClientSetMetadataOptions, BlobClientSetPropertiesOptions, BlobClientSetTierOptions,
1517
BlockBlobClientCommitBlockListOptions, BlockBlobClientUploadOptions, BlockList,
1618
BlockListType, BlockLookupList,
1719
},
@@ -233,4 +235,82 @@ impl BlobClient {
233235
) -> Result<Response<(), NoFormat>> {
234236
self.client.set_tier(tier, options).await
235237
}
238+
239+
/// Requests a new lease on a blob. The lease lock duration can be 15 to 60 seconds, or can be infinite.
240+
///
241+
/// # Arguments
242+
///
243+
/// * `duration` - Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A
244+
/// non-infinite lease can be between 15 and 60 seconds.
245+
/// * `options` - Optional configuration for the request.
246+
pub async fn acquire_lease(
247+
&self,
248+
duration: i32,
249+
options: Option<BlobClientAcquireLeaseOptions<'_>>,
250+
) -> Result<Response<BlobClientAcquireLeaseResult, NoFormat>> {
251+
self.client.acquire_lease(duration, options).await
252+
}
253+
254+
/// Ends a lease and ensures that another client can't acquire a new lease until the current lease
255+
/// period has expired.
256+
///
257+
/// # Arguments
258+
///
259+
/// * `options` - Optional configuration for the request.
260+
pub async fn break_lease(
261+
&self,
262+
options: Option<BlobClientBreakLeaseOptions<'_>>,
263+
) -> Result<Response<BlobClientBreakLeaseResult, NoFormat>> {
264+
self.client.break_lease(options).await
265+
}
266+
267+
/// Changes the ID of an existing lease to the proposed lease ID.
268+
///
269+
/// # Arguments
270+
///
271+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
272+
/// lease ID must match.
273+
/// * `proposed_lease_id` - The proposed lease ID for the blob.
274+
/// * `options` - Optional configuration for the request.
275+
pub async fn change_lease(
276+
&self,
277+
lease_id: String,
278+
proposed_lease_id: String,
279+
options: Option<BlobClientChangeLeaseOptions<'_>>,
280+
) -> Result<Response<BlobClientChangeLeaseResult, NoFormat>> {
281+
self.client
282+
.change_lease(lease_id, proposed_lease_id, options)
283+
.await
284+
}
285+
286+
/// Frees the lease so that another client can immediately acquire a lease
287+
/// against the blob as soon as the release is complete.
288+
///
289+
/// # Arguments
290+
///
291+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
292+
/// lease ID must match.
293+
/// * `options` - Optional configuration for the request.
294+
pub async fn release_lease(
295+
&self,
296+
lease_id: String,
297+
options: Option<BlobClientReleaseLeaseOptions<'_>>,
298+
) -> Result<Response<BlobClientReleaseLeaseResult, NoFormat>> {
299+
self.client.release_lease(lease_id, options).await
300+
}
301+
302+
/// Renews the lease on a blob.
303+
///
304+
/// # Arguments
305+
///
306+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
307+
/// lease ID must match.
308+
/// * `options` - Optional configuration for the request.
309+
pub async fn renew_lease(
310+
&self,
311+
lease_id: String,
312+
options: Option<BlobClientRenewLeaseOptions<'_>>,
313+
) -> Result<Response<BlobClientRenewLeaseResult, NoFormat>> {
314+
self.client.renew_lease(lease_id, options).await
315+
}
236316
}

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

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
use crate::{
55
generated::clients::BlobContainerClient as GeneratedBlobContainerClient,
6-
generated::models::BlobContainerClientGetPropertiesResult,
6+
generated::models::{
7+
BlobContainerClientAcquireLeaseResult, BlobContainerClientBreakLeaseResult,
8+
BlobContainerClientChangeLeaseResult, BlobContainerClientGetPropertiesResult,
9+
BlobContainerClientReleaseLeaseResult, BlobContainerClientRenewLeaseResult,
10+
},
711
models::{
8-
BlobContainerClientCreateOptions, BlobContainerClientDeleteOptions,
9-
BlobContainerClientGetPropertiesOptions, BlobContainerClientListBlobFlatSegmentOptions,
10-
BlobContainerClientSetMetadataOptions, ListBlobsFlatSegmentResponse,
12+
BlobContainerClientAcquireLeaseOptions, BlobContainerClientBreakLeaseOptions,
13+
BlobContainerClientChangeLeaseOptions, BlobContainerClientCreateOptions,
14+
BlobContainerClientDeleteOptions, BlobContainerClientGetPropertiesOptions,
15+
BlobContainerClientListBlobFlatSegmentOptions, BlobContainerClientReleaseLeaseOptions,
16+
BlobContainerClientRenewLeaseOptions, BlobContainerClientSetMetadataOptions,
17+
ListBlobsFlatSegmentResponse,
1118
},
1219
pipeline::StorageHeadersPolicy,
1320
BlobClient, BlobContainerClientOptions,
@@ -157,4 +164,82 @@ impl BlobContainerClient {
157164
) -> Result<PageIterator<Response<ListBlobsFlatSegmentResponse, XmlFormat>>> {
158165
self.client.list_blob_flat_segment(options)
159166
}
167+
168+
/// Requests a new lease on a container. The lease lock duration can be 15 to 60 seconds, or can be infinite.
169+
///
170+
/// # Arguments
171+
///
172+
/// * `duration` - Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A
173+
/// non-infinite lease can be between 15 and 60 seconds.
174+
/// * `options` - Optional configuration for the request.
175+
pub async fn acquire_lease(
176+
&self,
177+
duration: i32,
178+
options: Option<BlobContainerClientAcquireLeaseOptions<'_>>,
179+
) -> Result<Response<BlobContainerClientAcquireLeaseResult, NoFormat>> {
180+
self.client.acquire_lease(duration, options).await
181+
}
182+
183+
/// Ends a lease and ensures that another client can't acquire a new lease until the current lease
184+
/// period has expired.
185+
///
186+
/// # Arguments
187+
///
188+
/// * `options` - Optional configuration for the request.
189+
pub async fn break_lease(
190+
&self,
191+
options: Option<BlobContainerClientBreakLeaseOptions<'_>>,
192+
) -> Result<Response<BlobContainerClientBreakLeaseResult, NoFormat>> {
193+
self.client.break_lease(options).await
194+
}
195+
196+
/// Changes the ID of an existing lease to the proposed lease ID.
197+
///
198+
/// # Arguments
199+
///
200+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
201+
/// lease ID must match.
202+
/// * `proposed_lease_id` - The proposed lease ID for the container.
203+
/// * `options` - Optional configuration for the request.
204+
pub async fn change_lease(
205+
&self,
206+
lease_id: String,
207+
proposed_lease_id: String,
208+
options: Option<BlobContainerClientChangeLeaseOptions<'_>>,
209+
) -> Result<Response<BlobContainerClientChangeLeaseResult, NoFormat>> {
210+
self.client
211+
.change_lease(lease_id, proposed_lease_id, options)
212+
.await
213+
}
214+
215+
/// Frees the lease so that another client can immediately acquire a lease
216+
/// against the container as soon as the release is complete.
217+
///
218+
/// # Arguments
219+
///
220+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
221+
/// lease ID must match.
222+
/// * `options` - Optional configuration for the request.
223+
pub async fn release_lease(
224+
&self,
225+
lease_id: String,
226+
options: Option<BlobContainerClientReleaseLeaseOptions<'_>>,
227+
) -> Result<Response<BlobContainerClientReleaseLeaseResult, NoFormat>> {
228+
self.client.release_lease(lease_id, options).await
229+
}
230+
231+
/// Renews the lease on a container.
232+
///
233+
/// # Arguments
234+
///
235+
/// * `lease_id` - A lease ID for the source path. The source path must have an active lease and the
236+
/// lease ID must match.
237+
/// * `options` - Optional configuration for the request.
238+
pub async fn renew_lease(
239+
&self,
240+
lease_id: String,
241+
options: Option<BlobContainerClientRenewLeaseOptions<'_>>,
242+
) -> Result<Response<BlobContainerClientRenewLeaseResult, NoFormat>> {
243+
self.client.renew_lease(lease_id, options).await
244+
}
160245
}

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

Lines changed: 4 additions & 3 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_container_client.rs

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

0 commit comments

Comments
 (0)