forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerRestClient.cs
More file actions
1692 lines (1609 loc) · 124 KB
/
ContainerRestClient.cs
File metadata and controls
1692 lines (1609 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Storage.Blobs.Models;
namespace Azure.Storage.Blobs
{
internal partial class ContainerRestClient
{
private readonly HttpPipeline _pipeline;
private readonly string _url;
private readonly string _version;
/// <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>
internal ClientDiagnostics ClientDiagnostics { get; }
/// <summary> Initializes a new instance of ContainerRestClient. </summary>
/// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
/// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
/// <param name="url"> The URL of the service account, container, or blob that is the target of the desired operation. </param>
/// <param name="version"> Specifies the version of the operation to use for this request. The default value is "2024-08-04". </param>
/// <exception cref="ArgumentNullException"> <paramref name="clientDiagnostics"/>, <paramref name="pipeline"/>, <paramref name="url"/> or <paramref name="version"/> is null. </exception>
public ContainerRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version)
{
ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics));
_pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline));
_url = url ?? throw new ArgumentNullException(nameof(url));
_version = version ?? throw new ArgumentNullException(nameof(version));
}
internal HttpMessage CreateCreateRequest(int? timeout, IDictionary<string, string> metadata, PublicAccessType? access, string defaultEncryptionScope, bool? preventEncryptionScopeOverride)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (metadata != null)
{
request.Headers.Add("x-ms-meta-", metadata);
}
if (access != null)
{
request.Headers.Add("x-ms-blob-public-access", access.Value.ToSerialString());
}
request.Headers.Add("x-ms-version", _version);
if (defaultEncryptionScope != null)
{
request.Headers.Add("x-ms-default-encryption-scope", defaultEncryptionScope);
}
if (preventEncryptionScopeOverride != null)
{
request.Headers.Add("x-ms-deny-encryption-scope-override", preventEncryptionScopeOverride.Value);
}
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> creates a new container under the specified account. If the container with the same name already exists, the operation fails. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="metadata"> Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and Metadata for more information. </param>
/// <param name="access"> Specifies whether data in the container may be accessed publicly and the level of access. </param>
/// <param name="defaultEncryptionScope"> Optional. Version 2019-07-07 and later. Specifies the default encryption scope to set on the container and use for all future writes. </param>
/// <param name="preventEncryptionScopeOverride"> Optional. Version 2019-07-07 and newer. If true, prevents any request from specifying a different encryption scope than the scope set on the container. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerCreateHeaders>> CreateAsync(int? timeout = null, IDictionary<string, string> metadata = null, PublicAccessType? access = null, string defaultEncryptionScope = null, bool? preventEncryptionScopeOverride = null, CancellationToken cancellationToken = default)
{
using var message = CreateCreateRequest(timeout, metadata, access, defaultEncryptionScope, preventEncryptionScopeOverride);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerCreateHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> creates a new container under the specified account. If the container with the same name already exists, the operation fails. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="metadata"> Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and Metadata for more information. </param>
/// <param name="access"> Specifies whether data in the container may be accessed publicly and the level of access. </param>
/// <param name="defaultEncryptionScope"> Optional. Version 2019-07-07 and later. Specifies the default encryption scope to set on the container and use for all future writes. </param>
/// <param name="preventEncryptionScopeOverride"> Optional. Version 2019-07-07 and newer. If true, prevents any request from specifying a different encryption scope than the scope set on the container. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerCreateHeaders> Create(int? timeout = null, IDictionary<string, string> metadata = null, PublicAccessType? access = null, string defaultEncryptionScope = null, bool? preventEncryptionScopeOverride = null, CancellationToken cancellationToken = default)
{
using var message = CreateCreateRequest(timeout, metadata, access, defaultEncryptionScope, preventEncryptionScopeOverride);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerCreateHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateGetPropertiesRequest(int? timeout, string leaseId)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Get;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (leaseId != null)
{
request.Headers.Add("x-ms-lease-id", leaseId);
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerGetPropertiesHeaders>> GetPropertiesAsync(int? timeout = null, string leaseId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetPropertiesRequest(timeout, leaseId);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerGetPropertiesHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerGetPropertiesHeaders> GetProperties(int? timeout = null, string leaseId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetPropertiesRequest(timeout, leaseId);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerGetPropertiesHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateDeleteRequest(int? timeout, string leaseId, DateTimeOffset? ifModifiedSince, DateTimeOffset? ifUnmodifiedSince)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Delete;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (leaseId != null)
{
request.Headers.Add("x-ms-lease-id", leaseId);
}
if (ifModifiedSince != null)
{
request.Headers.Add("If-Modified-Since", ifModifiedSince.Value, "R");
}
if (ifUnmodifiedSince != null)
{
request.Headers.Add("If-Unmodified-Since", ifUnmodifiedSince.Value, "R");
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> operation marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerDeleteHeaders>> DeleteAsync(int? timeout = null, string leaseId = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateDeleteRequest(timeout, leaseId, ifModifiedSince, ifUnmodifiedSince);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerDeleteHeaders(message.Response);
switch (message.Response.Status)
{
case 202:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> operation marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerDeleteHeaders> Delete(int? timeout = null, string leaseId = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateDeleteRequest(timeout, leaseId, ifModifiedSince, ifUnmodifiedSince);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerDeleteHeaders(message.Response);
switch (message.Response.Status)
{
case 202:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateSetMetadataRequest(int? timeout, string leaseId, IDictionary<string, string> metadata, DateTimeOffset? ifModifiedSince)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "metadata", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (leaseId != null)
{
request.Headers.Add("x-ms-lease-id", leaseId);
}
if (metadata != null)
{
request.Headers.Add("x-ms-meta-", metadata);
}
if (ifModifiedSince != null)
{
request.Headers.Add("If-Modified-Since", ifModifiedSince.Value, "R");
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> operation sets one or more user-defined name-value pairs for the specified container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="metadata"> Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and Metadata for more information. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerSetMetadataHeaders>> SetMetadataAsync(int? timeout = null, string leaseId = null, IDictionary<string, string> metadata = null, DateTimeOffset? ifModifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateSetMetadataRequest(timeout, leaseId, metadata, ifModifiedSince);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerSetMetadataHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> operation sets one or more user-defined name-value pairs for the specified container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="metadata"> Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and Metadata for more information. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerSetMetadataHeaders> SetMetadata(int? timeout = null, string leaseId = null, IDictionary<string, string> metadata = null, DateTimeOffset? ifModifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateSetMetadataRequest(timeout, leaseId, metadata, ifModifiedSince);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerSetMetadataHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateGetAccessPolicyRequest(int? timeout, string leaseId)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Get;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "acl", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (leaseId != null)
{
request.Headers.Add("x-ms-lease-id", leaseId);
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<IReadOnlyList<BlobSignedIdentifier>, ContainerGetAccessPolicyHeaders>> GetAccessPolicyAsync(int? timeout = null, string leaseId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetAccessPolicyRequest(timeout, leaseId);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerGetAccessPolicyHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
{
IReadOnlyList<BlobSignedIdentifier> value = default;
var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
if (document.Element("SignedIdentifiers") is XElement signedIdentifiersElement)
{
var array = new List<BlobSignedIdentifier>();
foreach (var e in signedIdentifiersElement.Elements("SignedIdentifier"))
{
array.Add(BlobSignedIdentifier.DeserializeBlobSignedIdentifier(e));
}
value = array;
}
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<IReadOnlyList<BlobSignedIdentifier>, ContainerGetAccessPolicyHeaders> GetAccessPolicy(int? timeout = null, string leaseId = null, CancellationToken cancellationToken = default)
{
using var message = CreateGetAccessPolicyRequest(timeout, leaseId);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerGetAccessPolicyHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
{
IReadOnlyList<BlobSignedIdentifier> value = default;
var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
if (document.Element("SignedIdentifiers") is XElement signedIdentifiersElement)
{
var array = new List<BlobSignedIdentifier>();
foreach (var e in signedIdentifiersElement.Elements("SignedIdentifier"))
{
array.Add(BlobSignedIdentifier.DeserializeBlobSignedIdentifier(e));
}
value = array;
}
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateSetAccessPolicyRequest(int? timeout, string leaseId, PublicAccessType? access, DateTimeOffset? ifModifiedSince, DateTimeOffset? ifUnmodifiedSince, IEnumerable<BlobSignedIdentifier> containerAcl)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "acl", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
if (leaseId != null)
{
request.Headers.Add("x-ms-lease-id", leaseId);
}
if (access != null)
{
request.Headers.Add("x-ms-blob-public-access", access.Value.ToSerialString());
}
if (ifModifiedSince != null)
{
request.Headers.Add("If-Modified-Since", ifModifiedSince.Value, "R");
}
if (ifUnmodifiedSince != null)
{
request.Headers.Add("If-Unmodified-Since", ifUnmodifiedSince.Value, "R");
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
if (containerAcl != null)
{
request.Headers.Add("Content-Type", "application/xml");
var content = new XmlWriterContent();
content.XmlWriter.WriteStartElement("SignedIdentifiers");
foreach (var item in containerAcl)
{
content.XmlWriter.WriteObjectValue(item, "SignedIdentifier");
}
content.XmlWriter.WriteEndElement();
request.Content = content;
}
return message;
}
/// <summary> sets the permissions for the specified container. The permissions indicate whether blobs in a container may be accessed publicly. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="access"> Specifies whether data in the container may be accessed publicly and the level of access. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="containerAcl"> the acls for the container. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerSetAccessPolicyHeaders>> SetAccessPolicyAsync(int? timeout = null, string leaseId = null, PublicAccessType? access = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, IEnumerable<BlobSignedIdentifier> containerAcl = null, CancellationToken cancellationToken = default)
{
using var message = CreateSetAccessPolicyRequest(timeout, leaseId, access, ifModifiedSince, ifUnmodifiedSince, containerAcl);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerSetAccessPolicyHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> sets the permissions for the specified container. The permissions indicate whether blobs in a container may be accessed publicly. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="leaseId"> If specified, the operation only succeeds if the resource's lease is active and matches this ID. </param>
/// <param name="access"> Specifies whether data in the container may be accessed publicly and the level of access. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="containerAcl"> the acls for the container. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerSetAccessPolicyHeaders> SetAccessPolicy(int? timeout = null, string leaseId = null, PublicAccessType? access = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, IEnumerable<BlobSignedIdentifier> containerAcl = null, CancellationToken cancellationToken = default)
{
using var message = CreateSetAccessPolicyRequest(timeout, leaseId, access, ifModifiedSince, ifUnmodifiedSince, containerAcl);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerSetAccessPolicyHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateRestoreRequest(int? timeout, string deletedContainerName, string deletedContainerVersion)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "undelete", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
request.Headers.Add("x-ms-version", _version);
if (deletedContainerName != null)
{
request.Headers.Add("x-ms-deleted-container-name", deletedContainerName);
}
if (deletedContainerVersion != null)
{
request.Headers.Add("x-ms-deleted-container-version", deletedContainerVersion);
}
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> Restores a previously-deleted container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="deletedContainerName"> Optional. Version 2019-12-12 and later. Specifies the name of the deleted container to restore. </param>
/// <param name="deletedContainerVersion"> Optional. Version 2019-12-12 and later. Specifies the version of the deleted container to restore. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerRestoreHeaders>> RestoreAsync(int? timeout = null, string deletedContainerName = null, string deletedContainerVersion = null, CancellationToken cancellationToken = default)
{
using var message = CreateRestoreRequest(timeout, deletedContainerName, deletedContainerVersion);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerRestoreHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> Restores a previously-deleted container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="deletedContainerName"> Optional. Version 2019-12-12 and later. Specifies the name of the deleted container to restore. </param>
/// <param name="deletedContainerVersion"> Optional. Version 2019-12-12 and later. Specifies the version of the deleted container to restore. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerRestoreHeaders> Restore(int? timeout = null, string deletedContainerName = null, string deletedContainerVersion = null, CancellationToken cancellationToken = default)
{
using var message = CreateRestoreRequest(timeout, deletedContainerName, deletedContainerVersion);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerRestoreHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateRenameRequest(string sourceContainerName, int? timeout, string sourceLeaseId)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "rename", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("x-ms-source-container-name", sourceContainerName);
if (sourceLeaseId != null)
{
request.Headers.Add("x-ms-source-lease-id", sourceLeaseId);
}
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> Renames an existing container. </summary>
/// <param name="sourceContainerName"> Required. Specifies the name of the container to rename. </param>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="sourceLeaseId"> A lease ID for the source path. If specified, the source path must have an active lease and the lease ID must match. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="sourceContainerName"/> is null. </exception>
public async Task<ResponseWithHeaders<ContainerRenameHeaders>> RenameAsync(string sourceContainerName, int? timeout = null, string sourceLeaseId = null, CancellationToken cancellationToken = default)
{
if (sourceContainerName == null)
{
throw new ArgumentNullException(nameof(sourceContainerName));
}
using var message = CreateRenameRequest(sourceContainerName, timeout, sourceLeaseId);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerRenameHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> Renames an existing container. </summary>
/// <param name="sourceContainerName"> Required. Specifies the name of the container to rename. </param>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="sourceLeaseId"> A lease ID for the source path. If specified, the source path must have an active lease and the lease ID must match. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="sourceContainerName"/> is null. </exception>
public ResponseWithHeaders<ContainerRenameHeaders> Rename(string sourceContainerName, int? timeout = null, string sourceLeaseId = null, CancellationToken cancellationToken = default)
{
if (sourceContainerName == null)
{
throw new ArgumentNullException(nameof(sourceContainerName));
}
using var message = CreateRenameRequest(sourceContainerName, timeout, sourceLeaseId);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerRenameHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateSubmitBatchRequest(long contentLength, string multipartContentType, Stream body, int? timeout)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Post;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "batch", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
request.Headers.Add("Content-Length", contentLength);
request.Headers.Add("Content-Type", multipartContentType);
request.Content = RequestContent.Create(body);
return message;
}
/// <summary> The Batch operation allows multiple API calls to be embedded into a single HTTP request. </summary>
/// <param name="contentLength"> The length of the request. </param>
/// <param name="multipartContentType"> Required. The value of this header must be multipart/mixed with a batch boundary. Example header value: multipart/mixed; boundary=batch_<GUID>. </param>
/// <param name="body"> Initial data. </param>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="multipartContentType"/> or <paramref name="body"/> is null. </exception>
public async Task<ResponseWithHeaders<Stream, ContainerSubmitBatchHeaders>> SubmitBatchAsync(long contentLength, string multipartContentType, Stream body, int? timeout = null, CancellationToken cancellationToken = default)
{
if (multipartContentType == null)
{
throw new ArgumentNullException(nameof(multipartContentType));
}
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
using var message = CreateSubmitBatchRequest(contentLength, multipartContentType, body, timeout);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerSubmitBatchHeaders(message.Response);
switch (message.Response.Status)
{
case 202:
{
var value = message.ExtractResponseContent();
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> The Batch operation allows multiple API calls to be embedded into a single HTTP request. </summary>
/// <param name="contentLength"> The length of the request. </param>
/// <param name="multipartContentType"> Required. The value of this header must be multipart/mixed with a batch boundary. Example header value: multipart/mixed; boundary=batch_<GUID>. </param>
/// <param name="body"> Initial data. </param>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="multipartContentType"/> or <paramref name="body"/> is null. </exception>
public ResponseWithHeaders<Stream, ContainerSubmitBatchHeaders> SubmitBatch(long contentLength, string multipartContentType, Stream body, int? timeout = null, CancellationToken cancellationToken = default)
{
if (multipartContentType == null)
{
throw new ArgumentNullException(nameof(multipartContentType));
}
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
using var message = CreateSubmitBatchRequest(contentLength, multipartContentType, body, timeout);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerSubmitBatchHeaders(message.Response);
switch (message.Response.Status)
{
case 202:
{
var value = message.ExtractResponseContent();
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateFilterBlobsRequest(int? timeout, string @where, string marker, int? maxresults, IEnumerable<FilterBlobsIncludeItem> include)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Get;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("restype", "container", true);
uri.AppendQuery("comp", "blobs", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
if (@where != null)
{
uri.AppendQuery("where", @where, true);
}
if (marker != null)
{
uri.AppendQuery("marker", marker, true);
}
if (maxresults != null)
{
uri.AppendQuery("maxresults", maxresults.Value, true);
}
if (include != null && !(include is ChangeTrackingList<FilterBlobsIncludeItem> changeTrackingList && changeTrackingList.IsUndefined))
{
uri.AppendQueryDelimited("include", include, ",", true);
}
request.Uri = uri;
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> The Filter Blobs operation enables callers to list blobs in a container whose tags match a given search expression. Filter blobs searches within the given container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="where"> Filters the results to return only to return only blobs whose tags match the specified expression. </param>
/// <param name="marker"> A string value that identifies the portion of the list of containers to be returned with the next listing operation. The operation returns the NextMarker value within the response body if the listing operation did not return all containers remaining to be listed with the current page. The NextMarker value can be used as the value for the marker parameter in a subsequent call to request the next page of list items. The marker value is opaque to the client. </param>
/// <param name="maxresults"> Specifies the maximum number of containers to return. If the request does not specify maxresults, or specifies a value greater than 5000, the server will return up to 5000 items. Note that if the listing operation crosses a partition boundary, then the service will return a continuation token for retrieving the remainder of the results. For this reason, it is possible that the service will return fewer results than specified by maxresults, or than the default of 5000. </param>
/// <param name="include"> Include this parameter to specify one or more datasets to include in the response. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<FilterBlobSegment, ContainerFilterBlobsHeaders>> FilterBlobsAsync(int? timeout = null, string @where = null, string marker = null, int? maxresults = null, IEnumerable<FilterBlobsIncludeItem> include = null, CancellationToken cancellationToken = default)
{
using var message = CreateFilterBlobsRequest(timeout, @where, marker, maxresults, include);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerFilterBlobsHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
{
FilterBlobSegment value = default;
var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
if (document.Element("EnumerationResults") is XElement enumerationResultsElement)
{
value = FilterBlobSegment.DeserializeFilterBlobSegment(enumerationResultsElement);
}
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> The Filter Blobs operation enables callers to list blobs in a container whose tags match a given search expression. Filter blobs searches within the given container. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="where"> Filters the results to return only to return only blobs whose tags match the specified expression. </param>
/// <param name="marker"> A string value that identifies the portion of the list of containers to be returned with the next listing operation. The operation returns the NextMarker value within the response body if the listing operation did not return all containers remaining to be listed with the current page. The NextMarker value can be used as the value for the marker parameter in a subsequent call to request the next page of list items. The marker value is opaque to the client. </param>
/// <param name="maxresults"> Specifies the maximum number of containers to return. If the request does not specify maxresults, or specifies a value greater than 5000, the server will return up to 5000 items. Note that if the listing operation crosses a partition boundary, then the service will return a continuation token for retrieving the remainder of the results. For this reason, it is possible that the service will return fewer results than specified by maxresults, or than the default of 5000. </param>
/// <param name="include"> Include this parameter to specify one or more datasets to include in the response. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<FilterBlobSegment, ContainerFilterBlobsHeaders> FilterBlobs(int? timeout = null, string @where = null, string marker = null, int? maxresults = null, IEnumerable<FilterBlobsIncludeItem> include = null, CancellationToken cancellationToken = default)
{
using var message = CreateFilterBlobsRequest(timeout, @where, marker, maxresults, include);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerFilterBlobsHeaders(message.Response);
switch (message.Response.Status)
{
case 200:
{
FilterBlobSegment value = default;
var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace);
if (document.Element("EnumerationResults") is XElement enumerationResultsElement)
{
value = FilterBlobSegment.DeserializeFilterBlobSegment(enumerationResultsElement);
}
return ResponseWithHeaders.FromValue(value, headers, message.Response);
}
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateAcquireLeaseRequest(int? timeout, long? duration, string proposedLeaseId, DateTimeOffset? ifModifiedSince, DateTimeOffset? ifUnmodifiedSince)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("comp", "lease", true);
uri.AppendQuery("restype", "container", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
request.Headers.Add("x-ms-lease-action", "acquire");
if (duration != null)
{
request.Headers.Add("x-ms-lease-duration", duration.Value);
}
if (proposedLeaseId != null)
{
request.Headers.Add("x-ms-proposed-lease-id", proposedLeaseId);
}
if (ifModifiedSince != null)
{
request.Headers.Add("If-Modified-Since", ifModifiedSince.Value, "R");
}
if (ifUnmodifiedSince != null)
{
request.Headers.Add("If-Unmodified-Since", ifUnmodifiedSince.Value, "R");
}
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
return message;
}
/// <summary> [Update] establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="duration"> Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. </param>
/// <param name="proposedLeaseId"> Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID string formats. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async Task<ResponseWithHeaders<ContainerAcquireLeaseHeaders>> AcquireLeaseAsync(int? timeout = null, long? duration = null, string proposedLeaseId = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateAcquireLeaseRequest(timeout, duration, proposedLeaseId, ifModifiedSince, ifUnmodifiedSince);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
var headers = new ContainerAcquireLeaseHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
/// <summary> [Update] establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite. </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="duration"> Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. </param>
/// <param name="proposedLeaseId"> Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID string formats. </param>
/// <param name="ifModifiedSince"> Specify this header value to operate only on a blob if it has been modified since the specified date/time. </param>
/// <param name="ifUnmodifiedSince"> Specify this header value to operate only on a blob if it has not been modified since the specified date/time. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public ResponseWithHeaders<ContainerAcquireLeaseHeaders> AcquireLease(int? timeout = null, long? duration = null, string proposedLeaseId = null, DateTimeOffset? ifModifiedSince = null, DateTimeOffset? ifUnmodifiedSince = null, CancellationToken cancellationToken = default)
{
using var message = CreateAcquireLeaseRequest(timeout, duration, proposedLeaseId, ifModifiedSince, ifUnmodifiedSince);
_pipeline.Send(message, cancellationToken);
var headers = new ContainerAcquireLeaseHeaders(message.Response);
switch (message.Response.Status)
{
case 201:
return ResponseWithHeaders.FromValue(headers, message.Response);
default:
throw new RequestFailedException(message.Response);
}
}
internal HttpMessage CreateAcquireLeaseRequest(int? timeout, long? duration, string proposedLeaseId, RequestConditions requestConditions, RequestContext context)
{
var message = _pipeline.CreateMessage(context, ResponseClassifier201);
var request = message.Request;
request.Method = RequestMethod.Put;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(_url, false);
uri.AppendQuery("comp", "lease", true);
uri.AppendQuery("restype", "container", true);
if (timeout != null)
{
uri.AppendQuery("timeout", timeout.Value, true);
}
request.Uri = uri;
request.Headers.Add("x-ms-lease-action", "acquire");
request.Headers.Add("x-ms-version", _version);
request.Headers.Add("Accept", "application/xml");
if (duration != null)
{
request.Headers.Add("x-ms-lease-duration", duration.Value);
}
if (proposedLeaseId != null)
{
request.Headers.Add("x-ms-proposed-lease-id", proposedLeaseId);
}
if (requestConditions != null)
{
request.Headers.Add(requestConditions, "R");
}
return message;
}
/// <summary>
/// [Protocol Method] [Update] establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="duration"> Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. </param>
/// <param name="proposedLeaseId"> Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID string formats. </param>
/// <param name="requestConditions"> The content to send as the request conditions of the request. </param>
/// <param name="context"> The request context, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="RequestFailedException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual async Task<Response> AcquireLeaseAsync(int? timeout = null, long? duration = null, string proposedLeaseId = null, RequestConditions requestConditions = null, RequestContext context = null)
{
Argument.AssertNull(requestConditions?.IfMatch, nameof(requestConditions), "Service does not support the If-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
using var scope = ClientDiagnostics.CreateScope("Container.AcquireLease");
scope.Start();
try
{
using HttpMessage message = CreateAcquireLeaseRequest(timeout, duration, proposedLeaseId, requestConditions, context);
return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// [Protocol Method] [Update] establishes and manages a lock on a container for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="timeout"> The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting Timeouts for Blob Service Operations.</a>. </param>
/// <param name="duration"> Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. </param>
/// <param name="proposedLeaseId"> Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format. See Guid Constructor (String) for a list of valid GUID string formats. </param>
/// <param name="requestConditions"> The content to send as the request conditions of the request. </param>
/// <param name="context"> The request context, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="RequestFailedException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public virtual Response AcquireLease(int? timeout = null, long? duration = null, string proposedLeaseId = null, RequestConditions requestConditions = null, RequestContext context = null)
{
Argument.AssertNull(requestConditions?.IfMatch, nameof(requestConditions), "Service does not support the If-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
using var scope = ClientDiagnostics.CreateScope("Container.AcquireLease");
scope.Start();
try
{
using HttpMessage message = CreateAcquireLeaseRequest(timeout, duration, proposedLeaseId, requestConditions, context);
return _pipeline.ProcessMessage(message, context);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
internal HttpMessage CreateReleaseLeaseRequest(string leaseId, int? timeout, DateTimeOffset? ifModifiedSince, DateTimeOffset? ifUnmodifiedSince)
{
var message = _pipeline.CreateMessage();
var request = message.Request;