-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
serviceBusAtomManagementClient.ts
1377 lines (1258 loc) · 53.3 KB
/
serviceBusAtomManagementClient.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. All rights reserved.
// Licensed under the MIT License.
import {
WebResource,
ServiceClient,
ServiceClientOptions,
HttpOperationResponse,
signingPolicy,
proxyPolicy,
RequestPolicyFactory,
URLBuilder,
ProxySettings,
stripRequest,
stripResponse,
RestError
} from "@azure/core-http";
import { parseConnectionString, SharedKeyCredential } from "@azure/core-amqp";
import { AtomXmlSerializer, executeAtomXmlOperation } from "./util/atomXmlHelper";
import * as log from "./log";
import { SasServiceClientCredentials } from "./util/sasServiceClientCredentials";
import * as Constants from "./util/constants";
import {
QueueResourceSerializer,
InternalQueueOptions,
QueueOptions,
buildQueueOptions,
QueueDetails,
buildQueue
} from "./serializers/queueResourceSerializer";
import {
TopicResourceSerializer,
InternalTopicOptions,
TopicOptions,
buildTopicOptions,
TopicDetails,
buildTopic
} from "./serializers/topicResourceSerializer";
import {
SubscriptionResourceSerializer,
InternalSubscriptionOptions,
SubscriptionOptions,
buildSubscriptionOptions,
SubscriptionDetails,
buildSubscription
} from "./serializers/subscriptionResourceSerializer";
import {
RuleResourceSerializer,
InternalRuleOptions,
RuleOptions,
buildRuleOptions,
RuleDetails,
buildRule
} from "./serializers/ruleResourceSerializer";
import { isJSONLikeObject, isAbsoluteUrl } from "./util/utils";
/**
* Options to use with ServiceBusAtomManagementClient creation
*/
export interface ServiceBusAtomManagementClientOptions {
/**
* Proxy related settings
*/
proxySettings?: ProxySettings;
}
/**
* Request options for list<entity-type>() operations
*/
export interface ListRequestOptions {
/**
* Count of entities to fetch.
*/
top?: number;
/**
* Count of entities to skip from being fetched.
*/
skip?: number;
}
/**
* Represents result of create, get, update and delete operations on queue.
*/
export interface QueueResponse extends QueueDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Create Queue response
*/
export interface CreateQueueResponse extends QueueDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Get Queue response
*/
export interface GetQueueResponse extends QueueDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Update Queue response
*/
export interface UpdateQueueResponse extends QueueDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Delete Queue response
*/
export interface DeleteQueueResponse {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of list operation on queues.
*/
export interface ListQueuesResponse extends Array<QueueDetails> {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of create, get, update and delete operations on topic.
*/
export interface TopicResponse extends TopicDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Create Topic response
*/
export interface CreateTopicResponse extends TopicDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Get Topic response
*/
export interface GetTopicResponse extends TopicDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Update Topic response
*/
export interface UpdateTopicResponse extends TopicDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Delete Topic response
*/
export interface DeleteTopicResponse {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of list operation on topics.
*/
export interface ListTopicsResponse extends Array<TopicDetails> {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of create, get, update and delete operations on subscription.
*/
export interface SubscriptionResponse extends SubscriptionDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Create Subscription response
*/
export interface CreateSubscriptionResponse extends SubscriptionDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Get Subscription response
*/
export interface GetSubscriptionResponse extends SubscriptionDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Update Subscription response
*/
export interface UpdateSubscriptionResponse extends SubscriptionDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Delete Subscription response
*/
export interface DeleteSubscriptionResponse {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of list operation on subscriptions.
*/
export interface ListSubscriptionsResponse extends Array<SubscriptionDetails> {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of create, get, update and delete operations on rule.
*/
export interface RuleResponse extends RuleDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Create Rule response
*/
export interface CreateRuleResponse extends RuleDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Get Rule response
*/
export interface GetRuleResponse extends RuleDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Update Rule response
*/
export interface UpdateRuleResponse extends RuleDetails {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Delete Rule response
*/
export interface DeleteRuleResponse {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* Represents result of list operation on rules.
*/
export interface ListRulesResponse extends Array<RuleDetails> {
/**
* The underlying HTTP response.
*/
_response: HttpOperationResponse;
}
/**
* All operations return promises that resolve to an object that has the relevant output.
* These objects also have a property called `_response` that you can use if you want to
* access the direct response from the service.
*/
export class ServiceBusAtomManagementClient extends ServiceClient {
/**
* Reference to the endpoint as extracted from input connection string.
*/
private endpoint: string;
/**
* Reference to the endpoint with protocol prefix as extracted from input connection string.
*/
private endpointWithProtocol: string;
/**
* Singleton instances of serializers used across the various operations.
*/
private queueResourceSerializer: AtomXmlSerializer;
private topicResourceSerializer: AtomXmlSerializer;
private subscriptionResourceSerializer: AtomXmlSerializer;
private ruleResourceSerializer: AtomXmlSerializer;
/**
* SAS token provider used to generate tokens as required for the various operations.
*/
private sasTokenProvider: SharedKeyCredential;
/**
* Initializes a new instance of the ServiceBusManagementClient class.
* @param connectionString The connection string needed for the client to connect to Azure.
* @param options ServiceBusAtomManagementClientOptions
*/
constructor(connectionString: string, options?: ServiceBusAtomManagementClientOptions) {
const connectionStringObj: any = parseConnectionString(connectionString);
if (connectionStringObj.Endpoint == undefined) {
throw new Error("Missing Endpoint in connection string.");
}
const credentials = new SasServiceClientCredentials(
connectionStringObj.SharedAccessKeyName,
connectionStringObj.SharedAccessKey
);
const requestPolicyFactories: RequestPolicyFactory[] = [];
requestPolicyFactories.push(signingPolicy(credentials));
if (options && options.proxySettings) {
requestPolicyFactories.push(proxyPolicy(options.proxySettings));
}
const serviceClientOptions: ServiceClientOptions = {
requestPolicyFactories: requestPolicyFactories
};
super(credentials, serviceClientOptions);
this.queueResourceSerializer = new QueueResourceSerializer();
this.topicResourceSerializer = new TopicResourceSerializer();
this.subscriptionResourceSerializer = new SubscriptionResourceSerializer();
this.ruleResourceSerializer = new RuleResourceSerializer();
this.endpoint = (connectionString.match("Endpoint=sb://(.*)/;") || "")[1];
this.endpointWithProtocol = connectionStringObj.Endpoint;
this.sasTokenProvider = new SharedKeyCredential(
connectionStringObj.SharedAccessKeyName,
connectionStringObj.SharedAccessKey
);
}
/**
* Creates a queue with given name, configured using the given options
* @param queueName
* @param queueOptions Options to configure the Queue being created.
* For example, you can configure a queue to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async createQueue(queueName: string, queueOptions?: QueueOptions): Promise<CreateQueueResponse> {
log.httpAtomXml(
`Performing management operation - createQueue() for "${queueName}" with options: ${queueOptions}`
);
const response: HttpOperationResponse = await this.putResource(
queueName,
buildQueueOptions(queueOptions || {}),
this.queueResourceSerializer,
false
);
return this.buildQueueResponse(response);
}
/**
* Returns an object representing the Queue with the given name along with all its properties
* @param queueName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async getQueueDetails(queueName: string): Promise<GetQueueResponse> {
log.httpAtomXml(`Performing management operation - getQueue() for "${queueName}"`);
const response: HttpOperationResponse = await this.getResource(
queueName,
this.queueResourceSerializer
);
return this.buildQueueResponse(response);
}
/**
* Lists existing queues.
* @param listRequestOptions
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async listQueues(listRequestOptions?: ListRequestOptions): Promise<ListQueuesResponse> {
log.httpAtomXml(
`Performing management operation - listQueues() with options: ${listRequestOptions}`
);
const response: HttpOperationResponse = await this.listResources(
"$Resources/Queues",
listRequestOptions,
this.queueResourceSerializer
);
return this.buildListQueuesResponse(response);
}
/**
* Updates properties on the Queue by the given name based on the given options
* @param queueName
* @param queueOptions Options to configure the Queue being updated.
* For example, you can configure a queue to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async updateQueue(queueName: string, queueOptions: QueueOptions): Promise<UpdateQueueResponse> {
log.httpAtomXml(
`Performing management operation - updateQueue() for "${queueName}" with options: ${queueOptions}`
);
if (!isJSONLikeObject(queueOptions) || queueOptions === null) {
throw new TypeError(
`Parameter "queueOptions" must be an object of type "QueueOptions" and cannot be undefined or null.`
);
}
const finalQueueOptions: QueueOptions = {};
const getQueueResult = await this.getQueueDetails(queueName);
Object.assign(finalQueueOptions, getQueueResult, queueOptions);
const response: HttpOperationResponse = await this.putResource(
queueName,
buildQueueOptions(finalQueueOptions),
this.queueResourceSerializer,
true
);
return this.buildQueueResponse(response);
}
/**
* Deletes a queue.
* @param queueName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async deleteQueue(queueName: string): Promise<DeleteQueueResponse> {
log.httpAtomXml(`Performing management operation - deleteQueue() for "${queueName}"`);
const response: HttpOperationResponse = await this.deleteResource(
queueName,
this.queueResourceSerializer
);
return { _response: response };
}
/**
* Creates a topic with given name, configured using the given options
* @param topicName
* @param topicOptions Options to configure the Topic being created.
* For example, you can configure a topic to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async createTopic(topicName: string, topicOptions?: TopicOptions): Promise<CreateTopicResponse> {
log.httpAtomXml(
`Performing management operation - createTopic() for "${topicName}" with options: ${topicOptions}`
);
const response: HttpOperationResponse = await this.putResource(
topicName,
buildTopicOptions(topicOptions || {}),
this.topicResourceSerializer,
false
);
return this.buildTopicResponse(response);
}
/**
* Returns an object representing the Topic with the given name along with all its properties
* @param topicName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async getTopicDetails(topicName: string): Promise<GetTopicResponse> {
log.httpAtomXml(`Performing management operation - getTopic() for "${topicName}"`);
const response: HttpOperationResponse = await this.getResource(
topicName,
this.topicResourceSerializer
);
return this.buildTopicResponse(response);
}
/**
* Lists existing topics.
* @param listRequestOptions
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async listTopics(listRequestOptions?: ListRequestOptions): Promise<ListTopicsResponse> {
log.httpAtomXml(
`Performing management operation - listTopics() with options: ${listRequestOptions}`
);
const response: HttpOperationResponse = await this.listResources(
"$Resources/Topics",
listRequestOptions,
this.topicResourceSerializer
);
return this.buildListTopicsResponse(response);
}
/**
* Updates properties on the Topic by the given name based on the given options
* @param topicName
* @param topicOptions Options to configure the Topic being updated.
* For example, you can configure a topic to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async updateTopic(topicName: string, topicOptions: TopicOptions): Promise<UpdateTopicResponse> {
log.httpAtomXml(
`Performing management operation - updateTopic() for "${topicName}" with options: ${topicOptions}`
);
if (!isJSONLikeObject(topicOptions) || topicOptions === null) {
throw new TypeError(
`Parameter "topicOptions" must be an object of type "TopicOptions" and cannot be undefined or null.`
);
}
const finalTopicOptions: TopicOptions = {};
const getTopicResult = await this.getTopicDetails(topicName);
Object.assign(finalTopicOptions, getTopicResult, topicOptions);
const response: HttpOperationResponse = await this.putResource(
topicName,
buildTopicOptions(finalTopicOptions),
this.topicResourceSerializer,
true
);
return this.buildTopicResponse(response);
}
/**
* Deletes a topic.
* @param topicName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async deleteTopic(topicName: string): Promise<DeleteTopicResponse> {
log.httpAtomXml(`Performing management operation - deleteTopic() for "${topicName}"`);
const response: HttpOperationResponse = await this.deleteResource(
topicName,
this.topicResourceSerializer
);
return { _response: response };
}
/**
* Creates a subscription with given name, configured using the given options
* @param topicName
* @param subscriptionName
* @param subscriptionOptions Options to configure the Subscription being created.
* For example, you can configure a Subscription to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async createSubscription(
topicName: string,
subscriptionName: string,
subscriptionOptions?: SubscriptionOptions
): Promise<CreateSubscriptionResponse> {
log.httpAtomXml(
`Performing management operation - createSubscription() for "${subscriptionName}" with options: ${subscriptionOptions}`
);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response: HttpOperationResponse = await this.putResource(
fullPath,
buildSubscriptionOptions(subscriptionOptions || {}),
this.subscriptionResourceSerializer,
false
);
return this.buildSubscriptionResponse(response);
}
/**
* Returns an object representing the Subscription with the given name along with all its properties
* @param topicName
* @param subscriptionName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async getSubscriptionDetails(
topicName: string,
subscriptionName: string
): Promise<GetSubscriptionResponse> {
log.httpAtomXml(
`Performing management operation - getSubscription() for "${subscriptionName}"`
);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response: HttpOperationResponse = await this.getResource(
fullPath,
this.subscriptionResourceSerializer
);
return this.buildSubscriptionResponse(response);
}
/**
* Lists existing subscriptions.
* @param topicName
* @param listRequestOptions
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async listSubscriptions(
topicName: string,
listRequestOptions?: ListRequestOptions
): Promise<ListSubscriptionsResponse> {
log.httpAtomXml(
`Performing management operation - listSubscriptions() with options: ${listRequestOptions}`
);
const response: HttpOperationResponse = await this.listResources(
topicName + "/Subscriptions/",
listRequestOptions,
this.subscriptionResourceSerializer
);
return this.buildListSubscriptionsResponse(response);
}
/**
* Updates properties on the Subscription by the given name based on the given options
* @param topicName
* @param subscriptionName
* @param subscriptionOptions Options to configure the Subscription being updated.
* For example, you can configure a Subscription to support partitions or sessions.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async updateSubscription(
topicName: string,
subscriptionName: string,
subscriptionOptions: SubscriptionOptions
): Promise<UpdateSubscriptionResponse> {
log.httpAtomXml(
`Performing management operation - updateSubscription() for "${subscriptionName}" with options: ${subscriptionOptions}`
);
if (!isJSONLikeObject(subscriptionOptions) || subscriptionOptions === null) {
throw new TypeError(
`Parameter "subscriptionOptions" must be an object of type "SubscriptionOptions" and cannot be undefined or null.`
);
}
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const finalSubscriptionOptions: SubscriptionOptions = {};
const getSubscriptionResult = await this.getSubscriptionDetails(topicName, subscriptionName);
Object.assign(finalSubscriptionOptions, getSubscriptionResult, subscriptionOptions);
const response: HttpOperationResponse = await this.putResource(
fullPath,
buildSubscriptionOptions(finalSubscriptionOptions),
this.subscriptionResourceSerializer,
true
);
return this.buildSubscriptionResponse(response);
}
/**
* Deletes a subscription.
* @param topicName
* @param subscriptionName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async deleteSubscription(
topicName: string,
subscriptionName: string
): Promise<DeleteSubscriptionResponse> {
log.httpAtomXml(
`Performing management operation - deleteSubscription() for "${subscriptionName}"`
);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName);
const response: HttpOperationResponse = await this.deleteResource(
fullPath,
this.subscriptionResourceSerializer
);
return { _response: response };
}
/**
* Creates a rule with given name, configured using the given options.
* @param topicName
* @param subscriptionName
* @param ruleName
* @param ruleOptions
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityAlreadyExistsError` when requested messaging entity already exists,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `QuotaExceededError` when requested operation fails due to quote limits exceeding from service side,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async createRule(
topicName: string,
subscriptionName: string,
ruleName: string,
ruleOptions?: RuleOptions
): Promise<CreateRuleResponse> {
log.httpAtomXml(
`Performing management operation - createRule() for "${ruleName}" with options: "${ruleOptions}"`
);
const fullPath = this.getRulePath(topicName, subscriptionName, ruleName);
const response: HttpOperationResponse = await this.putResource(
fullPath,
buildRuleOptions(ruleName, ruleOptions),
this.ruleResourceSerializer,
false
);
return this.buildRuleResponse(response);
}
/**
* Returns an object representing the Rule with the given name along with all its properties.
* @param topicName
* @param subscriptioName
* @param ruleName
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async getRuleDetails(
topicName: string,
subscriptioName: string,
ruleName: string
): Promise<GetRuleResponse> {
log.httpAtomXml(`Performing management operation - getRule() for "${ruleName}"`);
const fullPath = this.getRulePath(topicName, subscriptioName, ruleName);
const response: HttpOperationResponse = await this.getResource(
fullPath,
this.ruleResourceSerializer
);
return this.buildRuleResponse(response);
}
/**
* Lists existing rules.
* @param topicName
* @param subscriptionName
* @param listRequestOptions
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async listRules(
topicName: string,
subscriptionName: string,
listRequestOptions?: ListRequestOptions
): Promise<ListRulesResponse> {
log.httpAtomXml(
`Performing management operation - listRules() with options: ${listRequestOptions}`
);
const fullPath = this.getSubscriptionPath(topicName, subscriptionName) + "/Rules/";
const response: HttpOperationResponse = await this.listResources(
fullPath,
listRequestOptions,
this.ruleResourceSerializer
);
return this.buildListRulesResponse(response);
}
/**
* Updates properties on the Rule by the given name based on the given options.
* @param topicName
* @param subscriptionName
* @param ruleName
* @param ruleOptions Options to configure the Rule being updated.
* For example, you can configure the filter to apply on associated Topic/Subscription.
*
* Following are errors that can be expected from this operation
* @throws `RestError` with code `UnauthorizedRequestError` when given request fails due to authorization problems,
* @throws `RestError` with code `MessageEntityNotFoundError` when requested messaging entity does not exist,
* @throws `RestError` with code `InvalidOperationError` when requested operation is invalid and we encounter a 403 HTTP status code,
* @throws `RestError` with code `ServerBusyError` when the request fails due to server being busy,
* @throws `RestError` with code `ServiceError` when receiving unrecognized HTTP status or for a scenarios such as
* bad requests or requests resulting in conflicting operation on the server,
* @throws `RestError` with code that is a value from the standard set of HTTP status codes as documented at
* https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netframework-4.8
*/
async updateRule(
topicName: string,
subscriptionName: string,
ruleName: string,
ruleOptions: RuleOptions
): Promise<UpdateRuleResponse> {
log.httpAtomXml(
`Performing management operation - updateRule() for "${ruleName}" with options: ${ruleOptions}`
);
if (!isJSONLikeObject(ruleOptions) || ruleOptions === null) {
throw new TypeError(
`Parameter "ruleOptions" must be an object of type "RuleOptions" and cannot be undefined or null.`
);
}
const fullPath = this.getRulePath(topicName, subscriptionName, ruleName);