Skip to content

Commit bf12702

Browse files
authored
Merge pull request #4 from codyzhao2770/tenant
done distribution tenant, other small changes
2 parents 2817964 + 7a33e74 commit bf12702

File tree

5 files changed

+166
-28
lines changed

5 files changed

+166
-28
lines changed

packages/aws-cdk-lib/aws-cloudfront/lib/connection-group.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface IConnectionGroup extends IResource {
2222
/**
2323
* The unique identifier for the connection group.
2424
*/
25-
readonly groupId: string;
25+
readonly id: string;
2626

2727
}
2828

@@ -48,7 +48,7 @@ export interface ConnectionGroupAttributes {
4848
/**
4949
* The unique identifier for the connection group.
5050
*/
51-
readonly groupId: string;
51+
readonly id: string;
5252
}
5353

5454
export interface ConnectionGroupProps {
@@ -65,15 +65,15 @@ export interface ConnectionGroupProps {
6565

6666
/**
6767
* Whether IPv6 is enabled for the connection group
68-
* @default false
68+
* @default true
6969
*/
7070
readonly ipv6Enabled?: boolean;
7171

7272
/**
7373
* The ID of the Anycast static IP list.
7474
* @default - none
7575
*/
76-
readonly anycastIpListID?: string;
76+
readonly anycastIpListId?: string;
7777

7878
/**
7979
* The ID of the Anycast static IP list.
@@ -91,22 +91,22 @@ export class ConnectionGroup extends Resource implements IConnectionGroup {
9191
public readonly name: string;
9292
public readonly routingEndpoint: string;
9393
public readonly arn: string;
94-
public readonly groupId: string;
94+
public readonly id: string;
9595

9696
constructor() {
9797
super(scope, id);
9898
this.name = attrs.name;
9999
this.routingEndpoint = attrs.routingEndpoint;
100100
this.arn = attrs.arn;
101-
this.groupId = attrs.groupId;
101+
this.id = attrs.id;
102102
}
103103
}();
104104
}
105105

106106
public readonly name: string;
107107
public readonly routingEndpoint: string;
108108
public readonly arn: string;
109-
public readonly groupId: string;
109+
public readonly id: string;
110110

111111
constructor(scope: Construct, id: string, props: ConnectionGroupProps) {
112112
super(scope, id);
@@ -117,14 +117,14 @@ export class ConnectionGroup extends Resource implements IConnectionGroup {
117117

118118
const connectionGroup = new CfnConnectionGroup(this, 'Resource', {
119119
name: this.name,
120-
anycastIpListId: props.anycastIpListID,
120+
anycastIpListId: props.anycastIpListId,
121121
enabled: props.enabled ?? true,
122-
ipv6Enabled: props.ipv6Enabled ?? false,
122+
ipv6Enabled: props.ipv6Enabled ?? true,
123123
tags: props.tags,
124124
});
125125

126126
this.routingEndpoint = connectionGroup.attrRoutingEndpoint;
127127
this.arn = connectionGroup.attrArn;
128-
this.groupId = connectionGroup.ref;
128+
this.id = connectionGroup.ref;
129129
}
130130
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { Construct } from 'constructs';
2+
import { CfnDistributionTenant } from './cloudfront.generated';
3+
import { CfnTag, IResource, Resource } from '../../core';
4+
import { addConstructMetadata } from '../../core/lib/metadata-resource';
5+
6+
export interface IDistributionTenant extends IResource {
7+
8+
readonly distributionId: string;
9+
10+
readonly name: string;
11+
12+
readonly domains: string[];
13+
14+
readonly connectionGroupId: string | undefined;
15+
16+
}
17+
18+
/**
19+
* Attributes for importing an existing distribution tenant
20+
*/
21+
export interface DistributionTenantAttributes {
22+
/**
23+
* The distribution ID for this tenant.
24+
*/
25+
readonly distributionId: string;
26+
27+
/**
28+
* The name of the distribution tenant.
29+
*/
30+
readonly name: string;
31+
32+
/**
33+
* The domains associated with this tenant.
34+
*/
35+
readonly domains: string[];
36+
37+
/**
38+
* The connection group ID associated with this tenant.
39+
*/
40+
readonly connectionGroupId: string;
41+
}
42+
43+
export interface CustomizationProps extends CfnDistributionTenant.CustomizationsProperty {
44+
45+
}
46+
47+
export interface ManagedCertificateRequestProps extends CfnDistributionTenant.ManagedCertificateRequestProperty{
48+
49+
}
50+
51+
export interface ParameterProps extends CfnDistributionTenant.ParameterProperty{
52+
53+
}
54+
55+
export interface DistributionTenantProps {
56+
57+
readonly distributionId: string;
58+
59+
readonly name: string;
60+
61+
readonly domains: string[];
62+
63+
readonly connectionGroupId?: string;
64+
65+
readonly customizations?: CustomizationProps;
66+
67+
readonly enabled?: boolean;
68+
69+
readonly managedCertificateRequest?: ManagedCertificateRequestProps;
70+
71+
readonly parameters?: ParameterProps[];
72+
73+
readonly tags?: CfnTag [];
74+
}
75+
76+
export class DistributionTenant extends Resource implements IDistributionTenant {
77+
/**
78+
* Import an existing distribution tenant
79+
*/
80+
public static fromDistributionTenantAttributes(scope: Construct, id: string, attrs: DistributionTenantAttributes): IDistributionTenant {
81+
return new class extends Resource implements IDistributionTenant {
82+
public readonly distributionId: string;
83+
public readonly name: string;
84+
public readonly domains: string[];
85+
public readonly connectionGroupId: string;
86+
87+
constructor() {
88+
super(scope, id);
89+
this.distributionId = attrs.distributionId;
90+
this.name = attrs.name;
91+
this.domains = attrs.domains;
92+
this.connectionGroupId = attrs.connectionGroupId;
93+
}
94+
}();
95+
}
96+
97+
public readonly distributionId: string;
98+
public readonly name: string;
99+
public readonly domains: string[];
100+
public readonly connectionGroupId: string | undefined;
101+
102+
constructor(scope: Construct, id: string, props: DistributionTenantProps) {
103+
super(scope, id);
104+
105+
addConstructMetadata(this, props);
106+
107+
this.name = props.name;
108+
this.domains = props.domains;
109+
this.distributionId = props.distributionId;
110+
111+
const distributionTenant = new CfnDistributionTenant(this, 'Resource', {
112+
distributionId: props.distributionId,
113+
domains: props.domains,
114+
name: props.name,
115+
connectionGroupId: props.connectionGroupId,
116+
customizations: props.customizations,
117+
enabled: props.enabled ?? true,
118+
managedCertificateRequest: props.managedCertificateRequest,
119+
parameters: props.parameters,
120+
tags: props.tags,
121+
});
122+
123+
this.connectionGroupId = distributionTenant.connectionGroupId;
124+
}
125+
}

packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ export interface DistributionProps {
283283
*
284284
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront-readme.html#cloudfront-saas-manager-resources
285285
*
286-
* @default false
286+
* @default DIRECT
287287
*/
288-
readonly multiTenant?: boolean;
288+
readonly connectionMode?: ConnectionMode;
289289

290290
/**
291291
* Configuration for a distribution tenant.
@@ -294,7 +294,11 @@ export interface DistributionProps {
294294
*
295295
* @default - No special tenant configurations (undefined).
296296
*/
297-
readonly tenantConfig?: CfnDistribution.TenantConfigProperty;
297+
readonly tenantConfig?: TenantConfigProps;
298+
}
299+
300+
export interface TenantConfigProps extends CfnDistribution.TenantConfigProperty {
301+
298302
}
299303

300304
/**
@@ -413,7 +417,7 @@ export class Distribution extends Resource implements IDistribution {
413417
viewerCertificate: this.certificate ? this.renderViewerCertificate(this.certificate,
414418
props.minimumProtocolVersion, props.sslSupportMethod) : undefined,
415419
webAclId: Lazy.string({ produce: () => this.webAclId }),
416-
connectionMode: props.multiTenant ? 'tenant-only' : 'direct',
420+
connectionMode: props.connectionMode ?? 'direct',
417421
tenantConfig: props.tenantConfig ?? undefined,
418422
},
419423
});
@@ -870,22 +874,24 @@ export class Distribution extends Resource implements IDistribution {
870874
}
871875

872876
private validateMultiTenantConfig(props: DistributionProps) {
873-
if (!props.multiTenant) {
877+
if (props.connectionMode == ConnectionMode.DIRECT) {
874878
if (props.tenantConfig) {
875879
throw new ValidationError('tenantConfig is not supported for direct distributions', this);
876880
}
877881
} else {
878-
if (props.domainNames) {
879-
throw new ValidationError('domainNames may not be configured for multi-tenant distributions', this);
880-
} if (props.enableIpv6) {
881-
throw new ValidationError('enableIpv6 field is not supported for multi-tenant distributions, please use a connection group to configure IPV6 options', this);
882-
} if (props.priceClass) {
883-
throw new ValidationError('priceClass may not be configured for multi-tenant distributions', this);
884-
} if (props.sslSupportMethod && props.sslSupportMethod == SSLMethod.VIP) {
885-
throw new ValidationError( 'invalid SSL Method', this);
886-
} if (props.defaultBehavior.smoothStreaming) {
887-
throw new ValidationError( 'smoothStreaming not supported by multi-tenant distributions', this);
888-
}
882+
const validations = [
883+
{ condition: props.domainNames, message: 'domainNames may not be configured for multi-tenant distributions' },
884+
{ condition: props.enableIpv6, message: 'enableIpv6 field is not supported for multi-tenant distributions, please use a connection group to configure IPV6 options' },
885+
{ condition: props.priceClass, message: 'priceClass may not be configured for multi-tenant distributions' },
886+
{ condition: props.sslSupportMethod && props.sslSupportMethod == SSLMethod.VIP, message: 'invalid SSL Method' },
887+
{ condition: props.defaultBehavior.smoothStreaming, message: 'smoothStreaming not supported by multi-tenant distributions' },
888+
];
889+
890+
validations.forEach(({ condition, message }) => {
891+
if (condition) {
892+
throw new ValidationError(message, this);
893+
}
894+
});
889895
}
890896
}
891897
}
@@ -915,6 +921,11 @@ export enum PriceClass {
915921
PRICE_CLASS_ALL = 'PriceClass_All',
916922
}
917923

924+
export enum ConnectionMode {
925+
TENANT_ONLY = 'tenant-only',
926+
DIRECT = 'direct',
927+
}
928+
918929
/**
919930
* How HTTPs should be handled with your distribution.
920931
*/

packages/aws-cdk-lib/aws-cloudfront/lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from './cache-policy';
2+
export * from './connection-group';
23
export * from './distribution';
4+
export * from './distribution-tenant';
35
export * from './endpoint';
46
export * from './function';
57
export * from './geo-restriction';

packages/aws-cdk-lib/aws-cloudfront/lib/multi-tenant-distribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Construct } from 'constructs';
22
import { ICachePolicy } from './cache-policy';
33
import { CfnDistribution, CfnMonitoringSubscription } from './cloudfront.generated';
4-
import { HttpVersion, ViewerProtocolPolicy, SSLMethod, SecurityPolicyProtocol, AllowedMethods, CachedMethods, ErrorResponse, EdgeLambda } from './distribution';
4+
import { HttpVersion, ViewerProtocolPolicy, SSLMethod, SecurityPolicyProtocol, AllowedMethods, CachedMethods, ErrorResponse, EdgeLambda, TenantConfigProps } from './distribution';
55
import { FunctionAssociation } from './function';
66
import { GeoRestriction } from './geo-restriction';
77
import { IKeyGroup } from './key-group';
@@ -250,7 +250,7 @@ export interface MTDProps {
250250
*
251251
* @default - No special tenant configurations (undefined).
252252
*/
253-
readonly tenantConfig?: CfnDistribution.TenantConfigProperty;
253+
readonly tenantConfig?: TenantConfigProps;
254254
}
255255

256256
/**

0 commit comments

Comments
 (0)