/
QueueServiceClient.ts
790 lines (758 loc) · 26.9 KB
/
QueueServiceClient.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {
TokenCredential,
isTokenCredential,
isNode,
getDefaultProxySettings
} from "@azure/core-http";
import { CanonicalCode } from "@opentelemetry/api";
import {
ListQueuesIncludeType,
QueueCreateResponse,
QueueDeleteResponse,
QueueItem,
QueueServiceProperties,
ServiceGetPropertiesResponse,
ServiceGetStatisticsResponse,
ServiceListQueuesSegmentResponse,
ServiceSetPropertiesResponse
} from "./generatedModels";
import { AbortSignalLike } from "@azure/abort-controller";
import { Service } from "./generated/src/operations";
import { newPipeline, StoragePipelineOptions, Pipeline } from "./Pipeline";
import { StorageClient, CommonOptions } from "./StorageClient";
import "@azure/core-paging";
import { PageSettings, PagedAsyncIterableIterator } from "@azure/core-paging";
import {
appendToURLPath,
appendToURLQuery,
extractConnectionStringParts
} from "./utils/utils.common";
import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
import { AnonymousCredential } from "./credentials/AnonymousCredential";
import { createSpan } from "./utils/tracing";
import { QueueClient, QueueCreateOptions, QueueDeleteOptions } from "./QueueClient";
import { AccountSASPermissions } from "./AccountSASPermissions";
import { generateAccountSASQueryParameters } from "./AccountSASSignatureValues";
import { AccountSASServices } from "./AccountSASServices";
import { SASProtocol } from "./SASQueryParameters";
import { SasIPRange } from "./SasIPRange";
/**
* Options to configure {@link QueueServiceClient.getProperties} operation
*
* @export
* @interface ServiceGetPropertiesOptions
*/
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`.
*
* @type {AbortSignalLike}
* @memberof ServiceGetPropertiesOptions
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure {@link QueueServiceClient.setProperties} operation
*
* @export
* @interface ServiceSetPropertiesOptions
*/
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`.
*
* @type {AbortSignalLike}
* @memberof ServiceSetPropertiesOptions
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure {@link QueueServiceClient.getStatistics} operation
*
* @export
* @interface ServiceGetStatisticsOptions
*/
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`.
*
* @type {AbortSignalLike}
* @memberof ServiceGetStatisticsOptions
*/
abortSignal?: AbortSignalLike;
}
/**
* Options to configure Queue Service - List Queues Segment operation
*
* See:
* - {@link QueueServiceClient.listSegments}
* - {@link QueueServiceClient.listQueuesSegment}
* - {@link QueueServiceClient.listItems}
*
* @interface ServiceListQueuesSegmentOptions
*/
interface ServiceListQueuesSegmentOptions 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`.
*
* @type {AbortSignalLike}
* @memberof ServiceListQueuesSegmentOptions
*/
abortSignal?: AbortSignalLike;
/**
* Filters the results to return only queues
* whose name begins with the specified prefix.
*/
prefix?: string;
/**
* Specifies the maximum number of queues
* 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 queue's metadata be returned as part of the response
* body. Possible values include: 'metadata'
*/
include?: ListQueuesIncludeType;
}
/**
* Options to configure {@link QueueServiceClient.listQueues} operation
*
* @export
* @interface ServiceListQueuesOptions
*/
export interface ServiceListQueuesOptions 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`.
*
* @type {AbortSignalLike}
* @memberof ServiceListQueuesOptions
*/
abortSignal?: AbortSignalLike;
/**
* Filters the results to return only queues
* whose name begins with the specified prefix.
*/
prefix?: string;
/**
* Specifies whether the queue's metadata be returned as part of the response
* body.
*/
includeMetadata?: boolean;
}
/**
* Options to configure {@link QueueServiceClient.generateAccountSasUrl} operation.
*
* @export
* @interface ServiceGenerateAccountSasUrlOptions
*/
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.
*
* @type {string}
* @memberof ServiceGenerateAccountSasUrlOptions
*/
version?: string;
/**
* Optional. SAS protocols allowed.
*
* @type {SASProtocol}
* @memberof ServiceGenerateAccountSasUrlOptions
*/
protocol?: SASProtocol;
/**
* Optional. When the SAS will take effect.
*
* @type {Date}
* @memberof ServiceGenerateAccountSasUrlOptions
*/
startsOn?: Date;
/**
* Optional. IP range allowed.
*
* @type {SasIPRange}
* @memberof ServiceGenerateAccountSasUrlOptions
*/
ipRange?: SasIPRange;
}
/**
* A QueueServiceClient represents a URL to the Azure Storage Queue service allowing you
* to manipulate queues.
*
* @export
* @class QueueServiceClient
*/
export class QueueServiceClient extends StorageClient {
/**
* Creates an instance of QueueServiceClient.
*
* @param {string} 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 {StoragePipelineOptions} [options] Options to configure the HTTP pipeline.
* @returns {QueueServiceClient} A new QueueServiceClient object from the given connection string.
* @memberof QueueServiceClient
*/
public static fromConnectionString(
connectionString: string,
options?: StoragePipelineOptions
): QueueServiceClient {
options = options || {};
const extractedCreds = extractConnectionStringParts(connectionString);
if (extractedCreds.kind === "AccountConnString") {
if (isNode) {
const sharedKeyCredential = new StorageSharedKeyCredential(
extractedCreds.accountName!,
extractedCreds.accountKey
);
options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
const pipeline = newPipeline(sharedKeyCredential, options);
return new QueueServiceClient(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 QueueServiceClient(extractedCreds.url + "?" + extractedCreds.accountSas, pipeline);
} else {
throw new Error(
"Connection string must be either an Account connection string or a SAS connection string"
);
}
}
/**
* serviceContext provided by protocol layer.
*
* @private
* @type {Service}
* @memberof QueueServiceClient
*/
private serviceContext: Service;
/**
* Creates an instance of QueueServiceClient.
*
* @param {string} url A URL string pointing to Azure Storage queue service, such as
* "https://myaccount.queue.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.queue.core.windows.net?sasString".
* @param {StorageSharedKeyCredential | AnonymousCredential | TokenCredential} 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 {StoragePipelineOptions} [options] Options to configure the HTTP pipeline.
* @memberof QueueServiceClient
*
* Example using DefaultAzureCredential from `@azure/identity`:
*
* ```js
* const account = "<account>";
*
* const credential = new DefaultAzureCredential();
*
* const queueServiceClient = new QueueServiceClient(
* `https://${account}.queue.core.windows.net`,
* credential
* }
* ```
*
* Example using an account name/key:
*
* ```js
* const account = "<account>";
*
* const sharedKeyCredential = new StorageSharedKeyCredential(account, "<account key>");
*
* const queueServiceClient = new QueueServiceClient(
* `https://${account}.queue.core.windows.net`,
* sharedKeyCredential,
* {
* retryOptions: { maxTries: 4 }, // Retry options
* telemetry: { value: "BasicSample/V11.0.0" } // Customized telemetry string
* }
* );
* ```
*/
constructor(
url: string,
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential,
options?: StoragePipelineOptions
);
/**
* Creates an instance of QueueServiceClient.
*
* @param {string} url A URL string pointing to Azure Storage queue service, such as
* "https://myaccount.queue.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.queue.core.windows.net?sasString".
* @param {Pipeline} pipeline Call newPipeline() to create a default
* pipeline, or provide a customized pipeline.
* @memberof QueueServiceClient
*/
constructor(url: string, pipeline: Pipeline);
constructor(
url: string,
credentialOrPipeline?:
| StorageSharedKeyCredential
| AnonymousCredential
| TokenCredential
| Pipeline,
options?: StoragePipelineOptions
) {
let pipeline: Pipeline;
if (credentialOrPipeline instanceof Pipeline) {
pipeline = credentialOrPipeline;
} else if (
(isNode && credentialOrPipeline instanceof StorageSharedKeyCredential) ||
credentialOrPipeline instanceof AnonymousCredential ||
isTokenCredential(credentialOrPipeline)
) {
pipeline = newPipeline(credentialOrPipeline, options);
} else {
// The second paramter is undefined. Use anonymous credential.
pipeline = newPipeline(new AnonymousCredential(), options);
}
super(url, pipeline);
this.serviceContext = new Service(this.storageClientContext);
}
/**
* Creates a {@link QueueClient} object.
*
* @param {string} queueName
* @returns {QueueClient} a new QueueClient
* @memberof QueueServiceClient
*
* Example usage:
*
* ```js
* const queueClient = queueServiceClient.getQueueClient("<new queue name>");
* const createQueueResponse = await queueClient.create();
* ```
*/
public getQueueClient(queueName: string): QueueClient {
return new QueueClient(appendToURLPath(this.url, queueName), this.pipeline);
}
/**
* Returns a list of the queues under the specified account.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-queues1
*
* @param {string} [marker] A string value that identifies the portion of
* the list of queues 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 queues 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 {ServiceListQueuesSegmentOptions} [options] Options to list queues operation.
* @returns {Promise<ServiceListQueuesSegmentResponse>} Response data for the list queues segment operation.
* @memberof QueueServiceClient
*/
private async listQueuesSegment(
marker?: string,
options: ServiceListQueuesSegmentOptions = {}
): Promise<ServiceListQueuesSegmentResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-listQueuesSegment",
options.tracingOptions
);
if (options.prefix === "") {
options.prefix = undefined;
}
try {
return await this.serviceContext.listQueuesSegment({
abortSignal: options.abortSignal,
marker: marker,
maxPageSize: options.maxPageSize,
prefix: options.prefix,
include: options.include === undefined ? undefined : [options.include],
spanOptions
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Returns an AsyncIterableIterator for {@link ServiceListQueuesSegmentResponse} objects
*
* @private
* @param {string} [marker] A string value that identifies the portion of
* the list of queues 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 queues 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 {ServiceListQueuesSegmentOptions} [options] Options to list queues operation.
* @returns {AsyncIterableIterator<ServiceListQueuesSegmentResponse>}
* @memberof QueueServiceClient
*/
private async *listSegments(
marker?: string,
options: ServiceListQueuesSegmentOptions = {}
): AsyncIterableIterator<ServiceListQueuesSegmentResponse> {
if (options.prefix === "") {
options.prefix = undefined;
}
let listQueuesResponse;
do {
listQueuesResponse = await this.listQueuesSegment(marker, options);
marker = listQueuesResponse.continuationToken;
yield await listQueuesResponse;
} while (marker);
}
/**
* Returns an AsyncIterableIterator for {@link QueueItem} objects
*
* @private
* @param {ServiceListQueuesSegmentOptions} [options] Options to list queues operation.
* @returns {AsyncIterableIterator<QueueItem>}
* @memberof QueueServiceClient
*/
private async *listItems(
options: ServiceListQueuesSegmentOptions = {}
): AsyncIterableIterator<QueueItem> {
if (options.prefix === "") {
options.prefix = undefined;
}
let marker: string | undefined;
for await (const segment of this.listSegments(marker, options)) {
if (segment.queueItems) {
yield* segment.queueItems;
}
}
}
/**
* Returns an async iterable iterator to list all the queues
* under the specified account.
*
* .byPage() returns an async iterable iterator to list the queues in pages.
*
* Example using `for await` syntax:
*
* ```js
* let i = 1;
* for await (const item of queueServiceClient.listQueues()) {
* console.log(`Queue${i}: ${item.name}`);
* i++;
* }
* ```
*
* Example using `iter.next()`:
*
* ```js
* let i = 1;
* let iterator = queueServiceClient.listQueues();
* let item = await iterator.next();
* while (!item.done) {
* console.log(`Queue${i}: ${iterator.value.name}`);
* i++;
* item = await iterator.next();
* }
* ```
*
* Example using `byPage()`:
*
* ```js
* // passing optional maxPageSize in the page settings
* let i = 1;
* for await (const item2 of queueServiceClient.listQueues().byPage({ maxPageSize: 20 })) {
* if (item2.queueItems) {
* for (const queueItem of item2.queueItems) {
* console.log(`Queue${i}: ${queueItem.name}`);
* i++;
* }
* }
* }
* ```
*
* Example using paging with a marker:
*
* ```js
* let i = 1;
* let iterator = queueServiceClient.listQueues().byPage({ maxPageSize: 2 });
* let item = (await iterator.next()).value;
*
* // Prints 2 queue names
* if (item.queueItems) {
* for (const queueItem of item.queueItems) {
* console.log(`Queue${i}: ${queueItem.name}`);
* i++;
* }
* }
* // Gets next marker
* let marker = item.continuationToken;
*
* // Passing next marker as continuationToken
* iterator = queueServiceClient.listQueues().byPage({ continuationToken: marker, maxPageSize: 10 });
* item = (await iterator.next()).value;
*
* // Prints 10 queue names
* if (item.queueItems) {
* for (const queueItem of item.queueItems) {
* console.log(`Queue${i}: ${queueItem.name}`);
* i++;
* }
* }
* ```
*
* @param {ServiceListQueuesOptions} [options] Options to list queues operation.
* @memberof QueueServiceClient
* @returns {PagedAsyncIterableIterator<QueueItem, ServiceListQueuesSegmentResponse>} An asyncIterableIterator that supports paging.
*/
public listQueues(
options: ServiceListQueuesOptions = {}
): PagedAsyncIterableIterator<QueueItem, ServiceListQueuesSegmentResponse> {
if (options.prefix === "") {
options.prefix = undefined;
}
const updatedOptions: ServiceListQueuesSegmentOptions = {
...options,
...(options.includeMetadata ? { include: "metadata" } : {})
};
// AsyncIterableIterator to iterate over queues
const iter = this.listItems(updatedOptions);
return {
/**
* @member {Promise} [next] The next method, part of the iteration protocol
*/
next() {
return iter.next();
},
/**
* @member {Symbol} [asyncIterator] The connection to the async iterator, part of the iteration protocol
*/
[Symbol.asyncIterator]() {
return this;
},
/**
* @member {Function} [byPage] Return an AsyncIterableIterator that works a page at a time
*/
byPage: (settings: PageSettings = {}) => {
return this.listSegments(settings.continuationToken, {
maxPageSize: settings.maxPageSize,
...updatedOptions
});
}
};
}
/**
* Gets the properties of a storage account’s Queue service, including properties
* for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-queue-service-properties
*
* @param {ServiceGetPropertiesOptions} [options] Options to get properties operation.
* @returns {Promise<ServiceGetPropertiesResponse>} Response data including the queue service properties.
* @memberof QueueServiceClient
*/
public async getProperties(
options: ServiceGetPropertiesOptions = {}
): Promise<ServiceGetPropertiesResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-getProperties",
options.tracingOptions
);
try {
return await this.serviceContext.getProperties({
abortSignal: options.abortSignal,
spanOptions
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Sets properties for a storage account’s Queue 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-queue-service-properties
*
* @param {QueueServiceProperties} properties
* @param {ServiceGetPropertiesOptions} [options] Options to set properties operation.
* @returns {Promise<ServiceSetPropertiesResponse>} Response data for the Set Properties operation.
* @memberof QueueServiceClient
*/
public async setProperties(
properties: QueueServiceProperties,
options: ServiceGetPropertiesOptions = {}
): Promise<ServiceSetPropertiesResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-setProperties",
options.tracingOptions
);
try {
return await this.serviceContext.setProperties(properties, {
abortSignal: options.abortSignal,
spanOptions
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Retrieves statistics related to replication for the Queue 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-queue-service-stats
*
* @param {ServiceGetStatisticsOptions} [options] Options to get statistics operation.
* @returns {Promise<ServiceGetStatisticsResponse>} Response data for get statistics the operation.
* @memberof QueueServiceClient
*/
public async getStatistics(
options: ServiceGetStatisticsOptions = {}
): Promise<ServiceGetStatisticsResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-getStatistics",
options.tracingOptions
);
try {
return await this.serviceContext.getStatistics({
abortSignal: options.abortSignal,
spanOptions
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Creates a new queue under the specified account.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-queue4
*
* @param {string} queueName name of the queue to create
* @param {QueueCreateOptions} [options] Options to Queue create operation.
* @returns {Promise<QueueCreateResponse>} Response data for the Queue create operation.
* @memberof QueueServiceClient
*/
public async createQueue(
queueName: string,
options: QueueCreateOptions = {}
): Promise<QueueCreateResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-createQueue",
options.tracingOptions
);
try {
return await this.getQueueClient(queueName).create({
...options,
tracingOptions: { ...options!.tracingOptions, spanOptions }
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Deletes the specified queue permanently.
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-queue3
*
* @param {string} queueName name of the queue to delete.
* @param {QueueDeleteOptions} [options] Options to Queue delete operation.
* @returns {Promise<QueueDeleteResponse>} Response data for the Queue delete operation.
* @memberof QueueServiceClient
*/
public async deleteQueue(
queueName: string,
options: QueueDeleteOptions = {}
): Promise<QueueDeleteResponse> {
const { span, spanOptions } = createSpan(
"QueueServiceClient-deleteQueue",
options.tracingOptions
);
try {
return await this.getQueueClient(queueName).delete({
...options,
tracingOptions: { ...options!.tracingOptions, spanOptions }
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
/**
* Only available for QueueServiceClient constructed with a shared key credential.
*
* Generates an account Shared Access Signature (SAS) URI based on the client properties
* and parameters passed in. The SAS is signed by the shared key credential of the client.
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas
*
* @param {Date} expiresOn Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not specified.
* @param {AccountSASPermissions} [permissions=AccountSASPermissions.parse("r")] Specifies the list of permissions to be associated with the SAS.
* @param {string} [resourceTypes="sco"] Specifies the resource types associated with the shared access signature.
* @param {ServiceGenerateAccountSasUrlOptions} [options={}] Optional parameters.
* @returns {string} An account SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
* @memberof QueueServiceClient
*/
public generateAccountSasUrl(
expiresOn?: Date,
permissions: AccountSASPermissions = AccountSASPermissions.parse("r"),
resourceTypes: string = "sco",
options: ServiceGenerateAccountSasUrlOptions = {}
): string {
if (!(this.credential instanceof StorageSharedKeyCredential)) {
throw RangeError(
"Can only generate the account SAS when the client is initialized with a shared key credential"
);
}
if (expiresOn === undefined) {
const now = new Date();
expiresOn = new Date(now.getTime() + 3600 * 1000);
}
const sas = generateAccountSASQueryParameters(
{
permissions,
expiresOn,
resourceTypes,
services: AccountSASServices.parse("q").toString(),
...options
},
this.credential
).toString();
return appendToURLQuery(this.url, sas);
}
}