/
BlobServiceClient.ts
1316 lines (1255 loc) · 46.9 KB
/
BlobServiceClient.ts
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.
// Licensed under the MIT license.
import {
TokenCredential,
isTokenCredential,
isNode,
HttpResponse,
getDefaultProxySettings,
} from "@azure/core-http";
import { SpanStatusCode } from "@azure/core-tracing";
import { AbortSignalLike } from "@azure/abort-controller";
import {
ServiceGetUserDelegationKeyHeaders,
ContainerCreateResponse,
ContainerDeleteResponse,
ServiceGetPropertiesResponse,
BlobServiceProperties,
ServiceSetPropertiesResponse,
ServiceGetStatisticsResponse,
ServiceGetAccountInfoResponse,
ServiceListContainersSegmentResponse,
ContainerItem,
UserDelegationKeyModel,
ContainerUndeleteResponse,
FilterBlobSegmentModel,
ServiceFilterBlobsHeaders,
ContainerRenameResponse,
LeaseAccessConditions,
FilterBlobSegment,
FilterBlobItem,
} from "./generatedModels";
import { Container, Service } from "./generated/src/operations";
import { newPipeline, StoragePipelineOptions, PipelineLike, isPipelineLike } from "./Pipeline";
import {
ContainerClient,
ContainerCreateOptions,
ContainerDeleteMethodOptions,
} from "./ContainerClient";
import {
appendToURLPath,
appendToURLQuery,
extractConnectionStringParts,
toTags,
} from "./utils/utils.common";
import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
import { AnonymousCredential } from "./credentials/AnonymousCredential";
import "@azure/core-paging";
import { PageSettings, PagedAsyncIterableIterator } from "@azure/core-paging";
import { truncatedISO8061Date } from "./utils/utils.common";
import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing";
import { BlobBatchClient } from "./BlobBatchClient";
import { CommonOptions, StorageClient } from "./StorageClient";
import { AccountSASPermissions } from "./sas/AccountSASPermissions";
import { SASProtocol } from "./sas/SASQueryParameters";
import { SasIPRange } from "./sas/SasIPRange";
import { generateAccountSASQueryParameters } from "./sas/AccountSASSignatureValues";
import { AccountSASServices } from "./sas/AccountSASServices";
import { ListContainersIncludeType } from "./generated/src";
/**
* Options to configure the {@link BlobServiceClient.getProperties} operation.
*/
export interface ServiceGetPropertiesOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure the {@link BlobServiceClient.setProperties} operation.
*/
export interface ServiceSetPropertiesOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure the {@link BlobServiceClient.getAccountInfo} operation.
*/
export interface ServiceGetAccountInfoOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure the {@link BlobServiceClient.getStatistics} operation.
*/
export interface ServiceGetStatisticsOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure the Service - Get User Delegation Key.
*/
export interface ServiceGetUserDelegationKeyOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure the {@link BlobServiceClient.listContainerSegment} operation.
*/
interface ServiceListContainersSegmentOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
/**
* Filters the results to return only containers
* whose name begins with the specified prefix.
*/
prefix?: string;
/**
* Specifies the maximum number of containers
* to return. If the request does not specify maxPageSize, 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 maxPageSize, or than the default of 5000.
*/
maxPageSize?: number;
/**
* Include this parameter to
* specify that the container's metadata be returned as part of the response
* body. Possible values include: 'metadata'
*/
include?: ListContainersIncludeType | ListContainersIncludeType[];
}
/**
* Options to configure the {@link BlobServiceClient.listContainers} operation.
*/
export interface ServiceListContainersOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
/**
* Filters the results to return only containers
* whose name begins with the specified prefix.
*/
prefix?: string;
/**
* Specifies whether the container's metadata
* should be returned as part of the response body.
*/
includeMetadata?: boolean;
/**
* Specifies whether soft deleted containers should be included in the response.
*/
includeDeleted?: boolean;
/**
* Specifies whether system containers should be included in the response.
*/
includeSystem?: boolean;
}
/**
* Options to configure the {@link BlobServiceClient.findBlobsByTagsSegment} operation.
*/
interface ServiceFindBlobsByTagsSegmentOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
/**
* Specifies the maximum number of blobs
* to return. If the request does not specify maxPageSize, 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 maxPageSize, or than the default of 5000.
*/
maxPageSize?: number;
}
/**
* Options to configure the {@link BlobServiceClient.findBlobsByTags} operation.
*/
export interface ServiceFindBlobByTagsOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
}
/**
* The response of {@link BlobServiceClient.findBlobsByTags} operation.
*/
export type ServiceFindBlobsByTagsSegmentResponse = FilterBlobSegment &
ServiceFilterBlobsHeaders & {
/**
* The underlying HTTP response.
*/
_response: HttpResponse & {
/**
* The parsed HTTP response headers.
*/
parsedHeaders: ServiceFilterBlobsHeaders;
/**
* The response body as text (string format)
*/
bodyAsText: string;
/**
* The response body as parsed JSON or XML
*/
parsedBody: FilterBlobSegmentModel;
};
};
/**
* A user delegation key.
*/
export interface UserDelegationKey {
/**
* The Azure Active Directory object ID in GUID format.
*/
signedObjectId: string;
/**
* The Azure Active Directory tenant ID in GUID format.
*/
signedTenantId: string;
/**
* The date-time the key is active.
*/
signedStartsOn: Date;
/**
* The date-time the key expires.
*/
signedExpiresOn: Date;
/**
* Abbreviation of the Azure Storage service that accepts the key.
*/
signedService: string;
/**
* The service version that created the key.
*/
signedVersion: string;
/**
* The key as a base64 string.
*/
value: string;
}
/**
* Contains response data for the {@link getUserDelegationKey} operation.
*/
export declare type ServiceGetUserDelegationKeyResponse = UserDelegationKey &
ServiceGetUserDelegationKeyHeaders & {
/**
* The underlying HTTP response.
*/
_response: HttpResponse & {
/**
* The parsed HTTP response headers.
*/
parsedHeaders: ServiceGetUserDelegationKeyHeaders;
/**
* The response body as text (string format)
*/
bodyAsText: string;
/**
* The response body as parsed JSON or XML
*/
parsedBody: UserDelegationKeyModel;
};
};
/**
* Options to configure {@link BlobServiceClient.undeleteContainer} operation.
*/
export interface ServiceUndeleteContainerOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
/**
* Optional. Specifies the new name of the restored container.
* Will use its original name if this is not specified.
* @deprecated Restore container to a different name is not supported by service anymore.
*/
destinationContainerName?: string;
}
/**
* Options to configure {@link BlobServiceClient.renameContainer} operation.
*/
export interface ServiceRenameContainerOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*/
abortSignal?: AbortSignalLike;
/**
* Condition to meet for the source container.
*/
sourceCondition?: LeaseAccessConditions;
}
/**
* Options to configure {@link BlobServiceClient.generateAccountSasUrl} operation.
*/
export interface ServiceGenerateAccountSasUrlOptions {
/**
* The version of the service this SAS will target. If not specified, it will default to the version targeted by the
* library.
*/
version?: string;
/**
* Optional. SAS protocols allowed.
*/
protocol?: SASProtocol;
/**
* Optional. When the SAS will take effect.
*/
startsOn?: Date;
/**
* Optional. IP range allowed.
*/
ipRange?: SasIPRange;
/**
* Optional. Encryption scope to use when sending requests authorized with this SAS URI.
*/
encryptionScope?: string;
}
/**
* A BlobServiceClient represents a Client to the Azure Storage Blob service allowing you
* to manipulate blob containers.
*/
export class BlobServiceClient extends StorageClient {
/**
* serviceContext provided by protocol layer.
*/
private serviceContext: Service;
/**
*
* Creates an instance of BlobServiceClient from connection string.
*
* @param connectionString - Account connection string or a SAS connection string of an Azure storage account.
* [ Note - Account connection string can only be used in NODE.JS runtime. ]
* Account connection string example -
* `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
* SAS connection string example -
* `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
* @param options - Optional. Options to configure the HTTP pipeline.
*/
public static fromConnectionString(
connectionString: string,
// Legacy, no fix for eslint error without breaking. Disable it for this interface.
/* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
options?: StoragePipelineOptions
): BlobServiceClient {
options = options || {};
const extractedCreds = extractConnectionStringParts(connectionString);
if (extractedCreds.kind === "AccountConnString") {
if (isNode) {
const sharedKeyCredential = new StorageSharedKeyCredential(
extractedCreds.accountName!,
extractedCreds.accountKey
);
if (!options.proxyOptions) {
options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
}
const pipeline = newPipeline(sharedKeyCredential, options);
return new BlobServiceClient(extractedCreds.url, pipeline);
} else {
throw new Error("Account connection string is only supported in Node.js environment");
}
} else if (extractedCreds.kind === "SASConnString") {
const pipeline = newPipeline(new AnonymousCredential(), options);
return new BlobServiceClient(extractedCreds.url + "?" + extractedCreds.accountSas, pipeline);
} else {
throw new Error(
"Connection string must be either an Account connection string or a SAS connection string"
);
}
}
/**
* Creates an instance of BlobServiceClient.
*
* @param url - A Client string pointing to Azure Storage blob service, such as
* "https://myaccount.blob.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".
* @param credential - Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the `@azure/identity` package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
* @param options - Optional. Options to configure the HTTP pipeline.
*
* Example using DefaultAzureCredential from `@azure/identity`:
*
* ```js
* const account = "<storage account name>";
*
* const defaultAzureCredential = new DefaultAzureCredential();
*
* const blobServiceClient = new BlobServiceClient(
* `https://${account}.blob.core.windows.net`,
* defaultAzureCredential
* );
* ```
*
* Example using an account name/key:
*
* ```js
* const account = "<storage account name>"
* const sharedKeyCredential = new StorageSharedKeyCredential(account, "<account key>");
*
* const blobServiceClient = new BlobServiceClient(
* `https://${account}.blob.core.windows.net`,
* sharedKeyCredential
* );
* ```
*/
constructor(
url: string,
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential,
// Legacy, no fix for eslint error without breaking. Disable it for this interface.
/* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
options?: StoragePipelineOptions
);
/**
* Creates an instance of BlobServiceClient.
*
* @param url - A Client string pointing to Azure Storage blob service, such as
* "https://myaccount.blob.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".
* @param pipeline - Call newPipeline() to create a default
* pipeline, or provide a customized pipeline.
*/
constructor(url: string, pipeline: PipelineLike);
constructor(
url: string,
credentialOrPipeline?:
| StorageSharedKeyCredential
| AnonymousCredential
| TokenCredential
| PipelineLike,
// Legacy, no fix for eslint error without breaking. Disable it for this interface.
/* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/
options?: StoragePipelineOptions
) {
let pipeline: PipelineLike;
if (isPipelineLike(credentialOrPipeline)) {
pipeline = credentialOrPipeline;
} else if (
(isNode && credentialOrPipeline instanceof StorageSharedKeyCredential) ||
credentialOrPipeline instanceof AnonymousCredential ||
isTokenCredential(credentialOrPipeline)
) {
pipeline = newPipeline(credentialOrPipeline, options);
} else {
// The second parameter is undefined. Use anonymous credential
pipeline = newPipeline(new AnonymousCredential(), options);
}
super(url, pipeline);
this.serviceContext = new Service(this.storageClientContext);
}
/**
* Creates a {@link ContainerClient} object
*
* @param containerName - A container name
* @returns A new ContainerClient object for the given container name.
*
* Example usage:
*
* ```js
* const containerClient = blobServiceClient.getContainerClient("<container name>");
* ```
*/
public getContainerClient(containerName: string): ContainerClient {
return new ContainerClient(
appendToURLPath(this.url, encodeURIComponent(containerName)),
this.pipeline
);
}
/**
* Create a Blob container.
*
* @param containerName - Name of the container to create.
* @param options - Options to configure Container Create operation.
* @returns Container creation response and the corresponding container client.
*/
public async createContainer(
containerName: string,
options: ContainerCreateOptions = {}
): Promise<{
containerClient: ContainerClient;
containerCreateResponse: ContainerCreateResponse;
}> {
const { span, updatedOptions } = createSpan("BlobServiceClient-createContainer", options);
try {
const containerClient = this.getContainerClient(containerName);
const containerCreateResponse = await containerClient.create(updatedOptions);
return {
containerClient,
containerCreateResponse,
};
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Deletes a Blob container.
*
* @param containerName - Name of the container to delete.
* @param options - Options to configure Container Delete operation.
* @returns Container deletion response.
*/
public async deleteContainer(
containerName: string,
options: ContainerDeleteMethodOptions = {}
): Promise<ContainerDeleteResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-deleteContainer", options);
try {
const containerClient = this.getContainerClient(containerName);
return await containerClient.delete(updatedOptions);
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Restore a previously deleted Blob container.
* This API is only functional if Container Soft Delete is enabled for the storage account associated with the container.
*
* @param deletedContainerName - Name of the previously deleted container.
* @param deletedContainerVersion - Version of the previously deleted container, used to uniquely identify the deleted container.
* @param options - Options to configure Container Restore operation.
* @returns Container deletion response.
*/
public async undeleteContainer(
deletedContainerName: string,
deletedContainerVersion: string,
options: ServiceUndeleteContainerOptions = {}
): Promise<{
containerClient: ContainerClient;
containerUndeleteResponse: ContainerUndeleteResponse;
}> {
const { span, updatedOptions } = createSpan("BlobServiceClient-undeleteContainer", options);
try {
const containerClient = this.getContainerClient(
options.destinationContainerName || deletedContainerName
);
// Hack to access a protected member.
const containerContext = new Container(containerClient["storageClientContext"]);
const containerUndeleteResponse = await containerContext.restore({
deletedContainerName,
deletedContainerVersion,
...updatedOptions,
});
return { containerClient, containerUndeleteResponse };
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Rename an existing Blob Container.
*
* @param sourceContainerName - The name of the source container.
* @param destinationContainerName - The new name of the container.
* @param options - Options to configure Container Rename operation.
*/
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
// @ts-ignore Need to hide this interface for now. Make it public and turn on the live tests for it when the service is ready.
private async renameContainer(
sourceContainerName: string,
destinationContainerName: string,
options: ServiceRenameContainerOptions = {}
): Promise<{
containerClient: ContainerClient;
containerRenameResponse: ContainerRenameResponse;
}> {
const { span, updatedOptions } = createSpan("BlobServiceClient-renameContainer", options);
try {
const containerClient = this.getContainerClient(destinationContainerName);
// Hack to access a protected member.
const containerContext = new Container(containerClient["storageClientContext"]);
const containerRenameResponse = await containerContext.rename(sourceContainerName, {
...updatedOptions,
sourceLeaseId: options.sourceCondition?.leaseId,
});
return { containerClient, containerRenameResponse };
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Gets the properties of a storage account’s Blob service, including properties
* for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties
*
* @param options - Options to the Service Get Properties operation.
* @returns Response data for the Service Get Properties operation.
*/
public async getProperties(
options: ServiceGetPropertiesOptions = {}
): Promise<ServiceGetPropertiesResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-getProperties", options);
try {
return await this.serviceContext.getProperties({
abortSignal: options.abortSignal,
...convertTracingToRequestOptionsBase(updatedOptions),
});
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Sets properties for a storage account’s Blob service endpoint, including properties
* for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties
*
* @param properties -
* @param options - Options to the Service Set Properties operation.
* @returns Response data for the Service Set Properties operation.
*/
public async setProperties(
properties: BlobServiceProperties,
options: ServiceSetPropertiesOptions = {}
): Promise<ServiceSetPropertiesResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-setProperties", options);
try {
return await this.serviceContext.setProperties(properties, {
abortSignal: options.abortSignal,
...convertTracingToRequestOptionsBase(updatedOptions),
});
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Retrieves statistics related to replication for the Blob service. It is only
* available on the secondary location endpoint when read-access geo-redundant
* replication is enabled for the storage account.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats
*
* @param options - Options to the Service Get Statistics operation.
* @returns Response data for the Service Get Statistics operation.
*/
public async getStatistics(
options: ServiceGetStatisticsOptions = {}
): Promise<ServiceGetStatisticsResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-getStatistics", options);
try {
return await this.serviceContext.getStatistics({
abortSignal: options.abortSignal,
...convertTracingToRequestOptionsBase(updatedOptions),
});
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* The Get Account Information operation returns the sku name and account kind
* for the specified account.
* The Get Account Information operation is available on service versions beginning
* with version 2018-03-28.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-account-information
*
* @param options - Options to the Service Get Account Info operation.
* @returns Response data for the Service Get Account Info operation.
*/
public async getAccountInfo(
options: ServiceGetAccountInfoOptions = {}
): Promise<ServiceGetAccountInfoResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-getAccountInfo", options);
try {
return await this.serviceContext.getAccountInfo({
abortSignal: options.abortSignal,
...convertTracingToRequestOptionsBase(updatedOptions),
});
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Returns a list of the containers under the specified account.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-containers2
*
* @param 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 continuationToken value within the response body if the
* listing operation did not return all containers remaining to be listed
* with the current page. The continuationToken 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 options - Options to the Service List Container Segment operation.
* @returns Response data for the Service List Container Segment operation.
*/
private async listContainersSegment(
marker?: string,
options: ServiceListContainersSegmentOptions = {}
): Promise<ServiceListContainersSegmentResponse> {
const { span, updatedOptions } = createSpan("BlobServiceClient-listContainersSegment", options);
try {
return await this.serviceContext.listContainersSegment({
abortSignal: options.abortSignal,
marker,
...options,
include: typeof options.include === "string" ? [options.include] : options.include,
...convertTracingToRequestOptionsBase(updatedOptions),
});
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* The Filter Blobs operation enables callers to list blobs across all containers whose tags
* match a given search expression. Filter blobs searches across all containers within a
* storage account but can be scoped within the expression to a single container.
*
* @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
* The given expression must evaluate to true for a blob to be returned in the results.
* The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
* however, only a subset of the OData filter syntax is supported in the Blob service.
* @param marker - A string value that identifies the portion of
* the list of blobs to be returned with the next listing operation. The
* operation returns the continuationToken value within the response body if the
* listing operation did not return all blobs remaining to be listed
* with the current page. The continuationToken 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 options - Options to find blobs by tags.
*/
private async findBlobsByTagsSegment(
tagFilterSqlExpression: string,
marker?: string,
options: ServiceFindBlobsByTagsSegmentOptions = {}
): Promise<ServiceFindBlobsByTagsSegmentResponse> {
const { span, updatedOptions } = createSpan(
"BlobServiceClient-findBlobsByTagsSegment",
options
);
try {
const response = await this.serviceContext.filterBlobs({
abortSignal: options.abortSignal,
where: tagFilterSqlExpression,
marker,
maxPageSize: options.maxPageSize,
...convertTracingToRequestOptionsBase(updatedOptions),
});
const wrappedResponse: ServiceFindBlobsByTagsSegmentResponse = {
...response,
_response: response._response, // _response is made non-enumerable
blobs: response.blobs.map((blob) => {
let tagValue = "";
if (blob.tags?.blobTagSet.length === 1) {
tagValue = blob.tags.blobTagSet[0].value;
}
return { ...blob, tags: toTags(blob.tags), tagValue };
}),
};
return wrappedResponse;
} catch (e: any) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message,
});
throw e;
} finally {
span.end();
}
}
/**
* Returns an AsyncIterableIterator for ServiceFindBlobsByTagsSegmentResponse.
*
* @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
* The given expression must evaluate to true for a blob to be returned in the results.
* The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
* however, only a subset of the OData filter syntax is supported in the Blob service.
* @param marker - A string value that identifies the portion of
* the list of blobs to be returned with the next listing operation. The
* operation returns the continuationToken value within the response body if the
* listing operation did not return all blobs remaining to be listed
* with the current page. The continuationToken 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 options - Options to find blobs by tags.
*/
private async *findBlobsByTagsSegments(
tagFilterSqlExpression: string,
marker?: string,
options: ServiceFindBlobsByTagsSegmentOptions = {}
): AsyncIterableIterator<ServiceFindBlobsByTagsSegmentResponse> {
let response;
if (!!marker || marker === undefined) {
do {
response = await this.findBlobsByTagsSegment(tagFilterSqlExpression, marker, options);
response.blobs = response.blobs || [];
marker = response.continuationToken;
yield response;
} while (marker);
}
}
/**
* Returns an AsyncIterableIterator for blobs.
*
* @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
* The given expression must evaluate to true for a blob to be returned in the results.
* The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
* however, only a subset of the OData filter syntax is supported in the Blob service.
* @param options - Options to findBlobsByTagsItems.
*/
private async *findBlobsByTagsItems(
tagFilterSqlExpression: string,
options: ServiceFindBlobsByTagsSegmentOptions = {}
): AsyncIterableIterator<FilterBlobItem> {
let marker: string | undefined;
for await (const segment of this.findBlobsByTagsSegments(
tagFilterSqlExpression,
marker,
options
)) {
yield* segment.blobs;
}
}
/**
* Returns an async iterable iterator to find all blobs with specified tag
* under the specified account.
*
* .byPage() returns an async iterable iterator to list the blobs in pages.
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-properties
*
* Example using `for await` syntax:
*
* ```js
* let i = 1;
* for await (const blob of blobServiceClient.findBlobsByTags("tagkey='tagvalue'")) {
* console.log(`Blob ${i++}: ${container.name}`);
* }
* ```
*
* Example using `iter.next()`:
*
* ```js
* let i = 1;
* const iter = blobServiceClient.findBlobsByTags("tagkey='tagvalue'");
* let blobItem = await iter.next();
* while (!blobItem.done) {
* console.log(`Blob ${i++}: ${blobItem.value.name}`);
* blobItem = await iter.next();
* }
* ```
*
* Example using `byPage()`:
*
* ```js
* // passing optional maxPageSize in the page settings
* let i = 1;
* for await (const response of blobServiceClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 20 })) {
* if (response.blobs) {
* for (const blob of response.blobs) {
* console.log(`Blob ${i++}: ${blob.name}`);
* }
* }
* }
* ```
*
* Example using paging with a marker:
*
* ```js
* let i = 1;
* let iterator = blobServiceClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 2 });
* let response = (await iterator.next()).value;
*
* // Prints 2 blob names
* if (response.blobs) {
* for (const blob of response.blobs) {
* console.log(`Blob ${i++}: ${blob.name}`);
* }
* }
*
* // Gets next marker
* let marker = response.continuationToken;
* // Passing next marker as continuationToken
* iterator = blobServiceClient
* .findBlobsByTags("tagkey='tagvalue'")
* .byPage({ continuationToken: marker, maxPageSize: 10 });
* response = (await iterator.next()).value;
*
* // Prints blob names
* if (response.blobs) {
* for (const blob of response.blobs) {
* console.log(`Blob ${i++}: ${blob.name}`);
* }
* }
* ```
*
* @param tagFilterSqlExpression - The where parameter enables the caller to query blobs whose tags match a given expression.
* The given expression must evaluate to true for a blob to be returned in the results.
* The[OData - ABNF] filter syntax rule defines the formal grammar for the value of the where query parameter;
* however, only a subset of the OData filter syntax is supported in the Blob service.
* @param options - Options to find blobs by tags.
*/
public findBlobsByTags(
tagFilterSqlExpression: string,