/
application-listener.ts
798 lines (713 loc) · 24.3 KB
/
application-listener.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
import * as ec2 from '@aws-cdk/aws-ec2';
import { Construct, Duration, IResource, Lazy, Resource, Token } from '@aws-cdk/core';
import { BaseListener } from '../shared/base-listener';
import { HealthCheck } from '../shared/base-target-group';
import { ApplicationProtocol, IpAddressType, SslPolicy } from '../shared/enums';
import { IListenerCertificate, ListenerCertificate } from '../shared/listener-certificate';
import { determineProtocolAndPort } from '../shared/util';
import { ListenerAction } from './application-listener-action';
import { ApplicationListenerCertificate } from './application-listener-certificate';
import { ApplicationListenerRule, FixedResponse, RedirectResponse, validateFixedResponse, validateRedirectResponse } from './application-listener-rule';
import { IApplicationLoadBalancer } from './application-load-balancer';
import { ApplicationTargetGroup, IApplicationLoadBalancerTarget, IApplicationTargetGroup } from './application-target-group';
import { ListenerCondition } from './conditions';
/**
* Basic properties for an ApplicationListener
*/
export interface BaseApplicationListenerProps {
/**
* The protocol to use
*
* @default - Determined from port if known.
*/
readonly protocol?: ApplicationProtocol;
/**
* The port on which the listener listens for requests.
*
* @default - Determined from protocol if known.
*/
readonly port?: number;
/**
* The certificates to use on this listener
*
* @default - No certificates.
* @deprecated Use the `certificates` property instead
*/
readonly certificateArns?: string[];
/**
* Certificate list of ACM cert ARNs
*
* @default - No certificates.
*/
readonly certificates?: IListenerCertificate[];
/**
* The security policy that defines which ciphers and protocols are supported.
*
* @default - The current predefined security policy.
*/
readonly sslPolicy?: SslPolicy;
/**
* Default target groups to load balance to
*
* All target groups will be load balanced to with equal weight and without
* stickiness. For a more complex configuration than that, use
* either `defaultAction` or `addAction()`.
*
* Cannot be specified together with `defaultAction`.
*
* @default - None.
*/
readonly defaultTargetGroups?: IApplicationTargetGroup[];
/**
* Default action to take for requests to this listener
*
* This allows full control of the default action of the load balancer,
* including Action chaining, fixed responses and redirect responses.
*
* See the `ListenerAction` class for all options.
*
* Cannot be specified together with `defaultTargetGroups`.
*
* @default - None.
*/
readonly defaultAction?: ListenerAction;
/**
* Allow anyone to connect to this listener
*
* If this is specified, the listener will be opened up to anyone who can reach it.
* For internal load balancers this is anyone in the same VPC. For public load
* balancers, this is anyone on the internet.
*
* If you want to be more selective about who can access this load
* balancer, set this to `false` and use the listener's `connections`
* object to selectively grant access to the listener.
*
* @default true
*/
readonly open?: boolean;
}
/**
* Properties for defining a standalone ApplicationListener
*/
export interface ApplicationListenerProps extends BaseApplicationListenerProps {
/**
* The load balancer to attach this listener to
*/
readonly loadBalancer: IApplicationLoadBalancer;
}
/**
* Define an ApplicationListener
*
* @resource AWS::ElasticLoadBalancingV2::Listener
*/
export class ApplicationListener extends BaseListener implements IApplicationListener {
/**
* Import an existing listener
*/
public static fromApplicationListenerAttributes(scope: Construct, id: string, attrs: ApplicationListenerAttributes): IApplicationListener {
return new ImportedApplicationListener(scope, id, attrs);
}
/**
* Manage connections to this ApplicationListener
*/
public readonly connections: ec2.Connections;
/**
* Load balancer this listener is associated with
*/
public readonly loadBalancer: IApplicationLoadBalancer;
/**
* ARNs of certificates added to this listener
*/
private readonly certificateArns: string[];
/**
* Listener protocol for this listener.
*/
private readonly protocol: ApplicationProtocol;
constructor(scope: Construct, id: string, props: ApplicationListenerProps) {
const [protocol, port] = determineProtocolAndPort(props.protocol, props.port);
if (protocol === undefined || port === undefined) {
throw new Error('At least one of \'port\' or \'protocol\' is required');
}
super(scope, id, {
loadBalancerArn: props.loadBalancer.loadBalancerArn,
certificates: Lazy.anyValue({ produce: () => this.certificateArns.map(certificateArn => ({ certificateArn })) }, { omitEmptyArray: true }),
protocol,
port,
sslPolicy: props.sslPolicy,
});
this.loadBalancer = props.loadBalancer;
this.protocol = protocol;
this.certificateArns = [];
// Attach certificates
if (props.certificateArns && props.certificateArns.length > 0) {
this.addCertificateArns('ListenerCertificate', props.certificateArns);
}
if (props.certificates && props.certificates.length > 0) {
this.addCertificates('DefaultCertificates', props.certificates);
}
// This listener edits the securitygroup of the load balancer,
// but adds its own default port.
this.connections = new ec2.Connections({
securityGroups: props.loadBalancer.connections.securityGroups,
defaultPort: ec2.Port.tcp(port),
});
if (props.defaultAction && props.defaultTargetGroups) {
throw new Error('Specify at most one of \'defaultAction\' and \'defaultTargetGroups\'');
}
if (props.defaultAction) {
this.setDefaultAction(props.defaultAction);
}
if (props.defaultTargetGroups) {
this.setDefaultAction(ListenerAction.forward(props.defaultTargetGroups));
}
if (props.open !== false) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv4(), `Allow from anyone on port ${port}`);
if (this.loadBalancer.ipAddressType === IpAddressType.DUAL_STACK) {
this.connections.allowDefaultPortFrom(ec2.Peer.anyIpv6(), `Allow from anyone on port ${port}`);
}
}
}
/**
* Add one or more certificates to this listener.
*
* After the first certificate, this creates ApplicationListenerCertificates
* resources since cloudformation requires the certificates array on the
* listener resource to have a length of 1.
*
* @deprecated Use `addCertificates` instead.
*/
public addCertificateArns(id: string, arns: string[]): void {
this.addCertificates(id, arns.map(ListenerCertificate.fromArn));
}
/**
* Add one or more certificates to this listener.
*
* After the first certificate, this creates ApplicationListenerCertificates
* resources since cloudformation requires the certificates array on the
* listener resource to have a length of 1.
*/
public addCertificates(id: string, certificates: IListenerCertificate[]): void {
const additionalCerts = [...certificates];
if (this.certificateArns.length === 0 && additionalCerts.length > 0) {
const first = additionalCerts.splice(0, 1)[0];
this.certificateArns.push(first.certificateArn);
}
if (additionalCerts.length > 0) {
new ApplicationListenerCertificate(this, id, {
listener: this,
certificates: additionalCerts,
});
}
}
/**
* Perform the given default action on incoming requests
*
* This allows full control of the default action of the load balancer,
* including Action chaining, fixed responses and redirect responses. See
* the `ListenerAction` class for all options.
*
* It's possible to add routing conditions to the Action added in this way.
* At least one Action must be added without conditions (which becomes the
* default Action).
*/
public addAction(id: string, props: AddApplicationActionProps): void {
checkAddRuleProps(props);
if (props.priority !== undefined) {
// New rule
//
// TargetGroup.registerListener is called inside ApplicationListenerRule.
new ApplicationListenerRule(this, id + 'Rule', {
listener: this,
conditions: props.conditions,
hostHeader: props.hostHeader,
pathPattern: props.pathPattern,
pathPatterns: props.pathPatterns,
priority: props.priority,
action: props.action,
});
} else {
// New default target with these targetgroups
this.setDefaultAction(props.action);
}
}
/**
* Load balance incoming requests to the given target groups.
*
* All target groups will be load balanced to with equal weight and without
* stickiness. For a more complex configuration than that, use `addAction()`.
*
* It's possible to add routing conditions to the TargetGroups added in this
* way. At least one TargetGroup must be added without conditions (which will
* become the default Action for this listener).
*/
public addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void {
checkAddRuleProps(props);
if (props.priority !== undefined) {
// New rule
//
// TargetGroup.registerListener is called inside ApplicationListenerRule.
new ApplicationListenerRule(this, id + 'Rule', {
listener: this,
conditions: props.conditions,
hostHeader: props.hostHeader,
pathPattern: props.pathPattern,
pathPatterns: props.pathPatterns,
priority: props.priority,
targetGroups: props.targetGroups,
});
} else {
// New default target with these targetgroups
this.setDefaultAction(ListenerAction.forward(props.targetGroups));
}
}
/**
* Load balance incoming requests to the given load balancing targets.
*
* This method implicitly creates an ApplicationTargetGroup for the targets
* involved, and a 'forward' action to route traffic to the given TargetGroup.
*
* If you want more control over the precise setup, create the TargetGroup
* and use `addAction` yourself.
*
* It's possible to add conditions to the targets added in this way. At least
* one set of targets must be added without conditions.
*
* @returns The newly created target group
*/
public addTargets(id: string, props: AddApplicationTargetsProps): ApplicationTargetGroup {
if (!this.loadBalancer.vpc) {
// tslint:disable-next-line:max-line-length
throw new Error('Can only call addTargets() when using a constructed Load Balancer or an imported Load Balancer with specified vpc; construct a new TargetGroup and use addTargetGroup');
}
const group = new ApplicationTargetGroup(this, id + 'Group', {
deregistrationDelay: props.deregistrationDelay,
healthCheck: props.healthCheck,
port: props.port,
protocol: props.protocol,
slowStart: props.slowStart,
stickinessCookieDuration: props.stickinessCookieDuration,
targetGroupName: props.targetGroupName,
targets: props.targets,
vpc: this.loadBalancer.vpc,
});
this.addTargetGroups(id, {
conditions: props.conditions,
hostHeader: props.hostHeader,
pathPattern: props.pathPattern,
pathPatterns: props.pathPatterns,
priority: props.priority,
targetGroups: [group],
});
return group;
}
/**
* Add a fixed response
*
* @deprecated Use `addAction()` instead
*/
public addFixedResponse(id: string, props: AddFixedResponseProps) {
checkAddRuleProps(props);
const fixedResponse: FixedResponse = {
statusCode: props.statusCode,
contentType: props.contentType,
messageBody: props.messageBody,
};
validateFixedResponse(fixedResponse);
if (props.priority) {
new ApplicationListenerRule(this, id + 'Rule', {
listener: this,
priority: props.priority,
fixedResponse,
...props,
});
} else {
this.setDefaultAction(ListenerAction.fixedResponse(Token.asNumber(props.statusCode), {
contentType: props.contentType,
messageBody: props.messageBody,
}));
}
}
/**
* Add a redirect response
*
* @deprecated Use `addAction()` instead
*/
public addRedirectResponse(id: string, props: AddRedirectResponseProps) {
checkAddRuleProps(props);
const redirectResponse = {
host: props.host,
path: props.path,
port: props.port,
protocol: props.protocol,
query: props.query,
statusCode: props.statusCode,
};
validateRedirectResponse(redirectResponse);
if (props.priority) {
new ApplicationListenerRule(this, id + 'Rule', {
listener: this,
priority: props.priority,
redirectResponse,
...props,
});
} else {
this.setDefaultAction(ListenerAction.redirect({
host: props.host,
path: props.path,
port: props.port,
protocol: props.protocol,
query: props.query,
permanent: props.statusCode === 'HTTP_301',
}));
}
}
/**
* Register that a connectable that has been added to this load balancer.
*
* Don't call this directly. It is called by ApplicationTargetGroup.
*/
public registerConnectable(connectable: ec2.IConnectable, portRange: ec2.Port): void {
connectable.connections.allowFrom(this.loadBalancer, portRange, 'Load balancer to target');
}
/**
* Validate this listener.
*/
protected validate(): string[] {
const errors = super.validate();
if (this.protocol === ApplicationProtocol.HTTPS && this.certificateArns.length === 0) {
errors.push('HTTPS Listener needs at least one certificate (call addCertificates)');
}
return errors;
}
/**
* Wrapper for _setDefaultAction which does a type-safe bind
*/
private setDefaultAction(action: ListenerAction) {
action.bind(this, this);
this._setDefaultAction(action);
}
}
/**
* Properties to reference an existing listener
*/
export interface IApplicationListener extends IResource, ec2.IConnectable {
/**
* ARN of the listener
* @attribute
*/
readonly listenerArn: string;
/**
* Add one or more certificates to this listener.
*/
addCertificateArns(id: string, arns: string[]): void;
/**
* Load balance incoming requests to the given target groups.
*
* It's possible to add conditions to the TargetGroups added in this way.
* At least one TargetGroup must be added without conditions.
*/
addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void;
/**
* Load balance incoming requests to the given load balancing targets.
*
* This method implicitly creates an ApplicationTargetGroup for the targets
* involved.
*
* It's possible to add conditions to the targets added in this way. At least
* one set of targets must be added without conditions.
*
* @returns The newly created target group
*/
addTargets(id: string, props: AddApplicationTargetsProps): ApplicationTargetGroup;
/**
* Register that a connectable that has been added to this load balancer.
*
* Don't call this directly. It is called by ApplicationTargetGroup.
*/
registerConnectable(connectable: ec2.IConnectable, portRange: ec2.Port): void;
}
/**
* Properties to reference an existing listener
*/
export interface ApplicationListenerAttributes {
/**
* ARN of the listener
*/
readonly listenerArn: string;
/**
* Security group ID of the load balancer this listener is associated with
*
* @deprecated use `securityGroup` instead
*/
readonly securityGroupId?: string;
/**
* Security group of the load balancer this listener is associated with
*/
readonly securityGroup?: ec2.ISecurityGroup;
/**
* The default port on which this listener is listening
*/
readonly defaultPort?: number;
/**
* Whether the imported security group allows all outbound traffic or not when
* imported using `securityGroupId`
*
* Unless set to `false`, no egress rules will be added to the security group.
*
* @default true
*
* @deprecated use `securityGroup` instead
*/
readonly securityGroupAllowsAllOutbound?: boolean;
}
class ImportedApplicationListener extends Resource implements IApplicationListener {
public readonly connections: ec2.Connections;
/**
* ARN of the listener
*/
public readonly listenerArn: string;
constructor(scope: Construct, id: string, props: ApplicationListenerAttributes) {
super(scope, id);
this.listenerArn = props.listenerArn;
const defaultPort = props.defaultPort !== undefined ? ec2.Port.tcp(props.defaultPort) : undefined;
let securityGroup: ec2.ISecurityGroup;
if (props.securityGroup) {
securityGroup = props.securityGroup;
} else if (props.securityGroupId) {
securityGroup = ec2.SecurityGroup.fromSecurityGroupId(scope, 'SecurityGroup', props.securityGroupId, {
allowAllOutbound: props.securityGroupAllowsAllOutbound,
});
} else {
throw new Error('Either `securityGroup` or `securityGroupId` must be specified to import an application listener.');
}
this.connections = new ec2.Connections({
securityGroups: [securityGroup],
defaultPort,
});
}
/**
* Add one or more certificates to this listener.
*/
public addCertificateArns(id: string, arns: string[]): void {
new ApplicationListenerCertificate(this, id, {
listener: this,
certificateArns: arns,
});
}
/**
* Load balance incoming requests to the given target groups.
*
* It's possible to add conditions to the TargetGroups added in this way.
* At least one TargetGroup must be added without conditions.
*/
public addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void {
checkAddRuleProps(props);
if (props.priority !== undefined) {
// New rule
new ApplicationListenerRule(this, id, {
listener: this,
hostHeader: props.hostHeader,
pathPattern: props.pathPattern,
pathPatterns: props.pathPatterns,
priority: props.priority,
targetGroups: props.targetGroups,
});
} else {
throw new Error('Cannot add default Target Groups to imported ApplicationListener');
}
}
/**
* Load balance incoming requests to the given load balancing targets.
*
* This method implicitly creates an ApplicationTargetGroup for the targets
* involved.
*
* It's possible to add conditions to the targets added in this way. At least
* one set of targets must be added without conditions.
*
* @returns The newly created target group
*/
public addTargets(_id: string, _props: AddApplicationTargetsProps): ApplicationTargetGroup {
// tslint:disable-next-line:max-line-length
throw new Error('Can only call addTargets() when using a constructed ApplicationListener; construct a new TargetGroup and use addTargetGroup.');
}
/**
* Register that a connectable that has been added to this load balancer.
*
* Don't call this directly. It is called by ApplicationTargetGroup.
*/
public registerConnectable(connectable: ec2.IConnectable, portRange: ec2.Port): void {
this.connections.allowTo(connectable, portRange, 'Load balancer to target');
}
}
/**
* Properties for adding a conditional load balancing rule
*/
export interface AddRuleProps {
/**
* Priority of this target group
*
* The rule with the lowest priority will be used for every request.
* If priority is not given, these target groups will be added as
* defaults, and must not have conditions.
*
* Priorities must be unique.
*
* @default Target groups are used as defaults
*/
readonly priority?: number;
/**
* Rule applies if matches the conditions.
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html
*
* @default - No conditions.
*/
readonly conditions?: ListenerCondition[];
/**
* Rule applies if the requested host matches the indicated host
*
* May contain up to three '*' wildcards.
*
* Requires that priority is set.
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#host-conditions
*
* @default No host condition
* @deprecated Use `conditions` instead.
*/
readonly hostHeader?: string;
/**
* Rule applies if the requested path matches the given path pattern
*
* May contain up to three '*' wildcards.
*
* Requires that priority is set.
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#path-conditions
* @default No path condition
* @deprecated Use `conditions` instead.
*/
readonly pathPattern?: string;
/**
* Rule applies if the requested path matches any of the given patterns.
*
* May contain up to three '*' wildcards.
*
* Requires that priority is set.
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#path-conditions
* @default - No path condition.
* @deprecated Use `conditions` instead.
*/
readonly pathPatterns?: string[];
}
/**
* Properties for adding a new target group to a listener
*/
export interface AddApplicationTargetGroupsProps extends AddRuleProps {
/**
* Target groups to forward requests to
*/
readonly targetGroups: IApplicationTargetGroup[];
}
/**
* Properties for adding a new action to a listener
*/
export interface AddApplicationActionProps extends AddRuleProps {
/**
* Action to perform
*/
readonly action: ListenerAction;
}
/**
* Properties for adding new targets to a listener
*/
export interface AddApplicationTargetsProps extends AddRuleProps {
/**
* The protocol to use
*
* @default Determined from port if known
*/
readonly protocol?: ApplicationProtocol;
/**
* The port on which the listener listens for requests.
*
* @default Determined from protocol if known
*/
readonly port?: number;
/**
* The time period during which the load balancer sends a newly registered
* target a linearly increasing share of the traffic to the target group.
*
* The range is 30-900 seconds (15 minutes).
*
* @default 0
*/
readonly slowStart?: Duration;
/**
* The stickiness cookie expiration period.
*
* Setting this value enables load balancer stickiness.
*
* After this period, the cookie is considered stale. The minimum value is
* 1 second and the maximum value is 7 days (604800 seconds).
*
* @default Stickiness disabled
*/
readonly stickinessCookieDuration?: Duration;
/**
* The targets to add to this target group.
*
* Can be `Instance`, `IPAddress`, or any self-registering load balancing
* target. All target must be of the same type.
*/
readonly targets?: IApplicationLoadBalancerTarget[];
/**
* The name of the target group.
*
* This name must be unique per region per account, can have a maximum of
* 32 characters, must contain only alphanumeric characters or hyphens, and
* must not begin or end with a hyphen.
*
* @default Automatically generated
*/
readonly targetGroupName?: string;
/**
* The amount of time for Elastic Load Balancing to wait before deregistering a target.
*
* The range is 0-3600 seconds.
*
* @default Duration.minutes(5)
*/
readonly deregistrationDelay?: Duration;
/**
* Health check configuration
*
* @default No health check
*/
readonly healthCheck?: HealthCheck;
}
/**
* Properties for adding a fixed response to a listener
*
* @deprecated Use `ApplicationListener.addAction` instead.
*/
export interface AddFixedResponseProps extends AddRuleProps, FixedResponse {
}
/**
* Properties for adding a redirect response to a listener
*
* @deprecated Use `ApplicationListener.addAction` instead.
*/
export interface AddRedirectResponseProps extends AddRuleProps, RedirectResponse {
}
function checkAddRuleProps(props: AddRuleProps) {
const conditionsCount = props.conditions?.length || 0;
const hasAnyConditions = conditionsCount !== 0 ||
props.hostHeader !== undefined || props.pathPattern !== undefined || props.pathPatterns !== undefined;
const hasPriority = props.priority !== undefined;
if (hasAnyConditions !== hasPriority) {
throw new Error('Setting \'conditions\', \'pathPattern\' or \'hostHeader\' also requires \'priority\', and vice versa');
}
}