11import { Construct } from 'constructs' ;
2+ import { HostedZoneGrants } from './hosted-zone-grants' ;
23import { HostedZoneProviderProps } from './hosted-zone-provider' ;
34import { GrantDelegationOptions , HostedZoneAttributes , IHostedZone , PublicHostedZoneAttributes , PrivateHostedZoneAttributes } from './hosted-zone-ref' ;
45import { IKeySigningKey , KeySigningKey } from './key-signing-key' ;
56import { CaaAmazonRecord , ZoneDelegationRecord } from './record-set' ;
6- import { CfnHostedZone , CfnDNSSEC , CfnKeySigningKey } from './route53.generated' ;
7- import { makeGrantDelegation , makeHostedZoneArn , validateZoneName } from './util' ;
7+ import { CfnHostedZone , CfnDNSSEC , CfnKeySigningKey , HostedZoneReference } from './route53.generated' ;
8+ import { makeHostedZoneArn , validateZoneName } from './util' ;
89import * as ec2 from '../../aws-ec2' ;
910import * as iam from '../../aws-iam' ;
1011import * as kms from '../../aws-kms' ;
@@ -98,6 +99,13 @@ export class HostedZone extends Resource implements IHostedZone {
9899 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
99100 }
100101
102+ /**
103+ * FQDN of this hosted zone
104+ */
105+ public get name ( ) : string {
106+ return this . zoneName ;
107+ }
108+
101109 /**
102110 * Import a Route 53 hosted zone defined either outside the CDK, or in a different CDK stack
103111 *
@@ -111,14 +119,20 @@ export class HostedZone extends Resource implements IHostedZone {
111119 public static fromHostedZoneId ( scope : Construct , id : string , hostedZoneId : string ) : IHostedZone {
112120 class Import extends Resource implements IHostedZone {
113121 public readonly hostedZoneId = hostedZoneId ;
122+ public get name ( ) : string { return this . zoneName ; }
114123 public get zoneName ( ) : string {
115124 throw new ValidationError ( 'Cannot reference `zoneName` when using `HostedZone.fromHostedZoneId()`. A construct consuming this hosted zone may be trying to reference its `zoneName`. If this is the case, use `fromHostedZoneAttributes()` or `fromLookup()` instead.' , this ) ;
116125 }
117126 public get hostedZoneArn ( ) : string {
118127 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
119128 }
120129 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
121- return makeGrantDelegation ( grantee , this , options ) ;
130+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
131+ }
132+ public get hostedZoneRef ( ) : HostedZoneReference {
133+ return {
134+ hostedZoneId : this . hostedZoneId ,
135+ } ;
122136 }
123137 }
124138
@@ -138,11 +152,17 @@ export class HostedZone extends Resource implements IHostedZone {
138152 class Import extends Resource implements IHostedZone {
139153 public readonly hostedZoneId = attrs . hostedZoneId ;
140154 public readonly zoneName = attrs . zoneName ;
155+ public readonly name = attrs . zoneName ;
141156 public get hostedZoneArn ( ) : string {
142157 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
143158 }
144159 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
145- return makeGrantDelegation ( grantee , this , options ) ;
160+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
161+ }
162+ public get hostedZoneRef ( ) : HostedZoneReference {
163+ return {
164+ hostedZoneId : this . hostedZoneId ,
165+ } ;
146166 }
147167 }
148168
@@ -204,6 +224,11 @@ export class HostedZone extends Resource implements IHostedZone {
204224 */
205225 private keySigningKey ?: IKeySigningKey ;
206226
227+ /**
228+ * Grants helper for this hosted zone
229+ */
230+ public readonly grants = HostedZoneGrants . fromHostedZone ( this ) ;
231+
207232 constructor ( scope : Construct , id : string , props : HostedZoneProps ) {
208233 super ( scope , id ) ;
209234 // Enhanced CDK Analytics Telemetry
@@ -230,6 +255,12 @@ export class HostedZone extends Resource implements IHostedZone {
230255 }
231256 }
232257
258+ public get hostedZoneRef ( ) : HostedZoneReference {
259+ return {
260+ hostedZoneId : this . hostedZoneId ,
261+ } ;
262+ }
263+
233264 /**
234265 * Add another VPC to this private hosted zone.
235266 *
@@ -242,7 +273,7 @@ export class HostedZone extends Resource implements IHostedZone {
242273
243274 @MethodMetadata ( )
244275 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
245- return makeGrantDelegation ( grantee , this , options ) ;
276+ return this . grants . delegation ( grantee , options ) ;
246277 }
247278
248279 /**
@@ -341,12 +372,18 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone {
341372 public static fromPublicHostedZoneId ( scope : Construct , id : string , publicHostedZoneId : string ) : IPublicHostedZone {
342373 class Import extends Resource implements IPublicHostedZone {
343374 public readonly hostedZoneId = publicHostedZoneId ;
375+ public get name ( ) : string { return this . zoneName ; }
344376 public get zoneName ( ) : string { throw new ValidationError ( 'Cannot reference `zoneName` when using `PublicHostedZone.fromPublicHostedZoneId()`. A construct consuming this hosted zone may be trying to reference its `zoneName`. If this is the case, use `fromPublicHostedZoneAttributes()` instead' , this ) ; }
345377 public get hostedZoneArn ( ) : string {
346378 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
347379 }
348380 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
349- return makeGrantDelegation ( grantee , this , options ) ;
381+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
382+ }
383+ public get hostedZoneRef ( ) : HostedZoneReference {
384+ return {
385+ hostedZoneId : this . hostedZoneId ,
386+ } ;
350387 }
351388 }
352389 return new Import ( scope , id ) ;
@@ -365,11 +402,17 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone {
365402 class Import extends Resource implements IPublicHostedZone {
366403 public readonly hostedZoneId = attrs . hostedZoneId ;
367404 public readonly zoneName = attrs . zoneName ;
405+ public readonly name = attrs . zoneName ;
368406 public get hostedZoneArn ( ) : string {
369407 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
370408 }
371409 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
372- return makeGrantDelegation ( grantee , this , options ) ;
410+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
411+ }
412+ public get hostedZoneRef ( ) : HostedZoneReference {
413+ return {
414+ hostedZoneId : this . zoneName ,
415+ } ;
373416 }
374417 }
375418 return new Import ( scope , id ) ;
@@ -509,12 +552,18 @@ export class PrivateHostedZone extends HostedZone implements IPrivateHostedZone
509552 public static fromPrivateHostedZoneId ( scope : Construct , id : string , privateHostedZoneId : string ) : IPrivateHostedZone {
510553 class Import extends Resource implements IPrivateHostedZone {
511554 public readonly hostedZoneId = privateHostedZoneId ;
555+ public get name ( ) : string { return this . zoneName ; }
512556 public get zoneName ( ) : string { throw new ValidationError ( 'Cannot reference `zoneName` when using `PrivateHostedZone.fromPrivateHostedZoneId()`. A construct consuming this hosted zone may be trying to reference its `zoneName`' , this ) ; }
513557 public get hostedZoneArn ( ) : string {
514558 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
515559 }
516560 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
517- return makeGrantDelegation ( grantee , this , options ) ;
561+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
562+ }
563+ public get hostedZoneRef ( ) : HostedZoneReference {
564+ return {
565+ hostedZoneId : this . hostedZoneId ,
566+ } ;
518567 }
519568 }
520569 return new Import ( scope , id ) ;
@@ -533,11 +582,17 @@ export class PrivateHostedZone extends HostedZone implements IPrivateHostedZone
533582 class Import extends Resource implements IPrivateHostedZone {
534583 public readonly hostedZoneId = attrs . hostedZoneId ;
535584 public readonly zoneName = attrs . zoneName ;
585+ public get name ( ) : string { return this . zoneName ; }
536586 public get hostedZoneArn ( ) : string {
537587 return makeHostedZoneArn ( this , this . hostedZoneId ) ;
538588 }
539589 public grantDelegation ( grantee : iam . IGrantable , options ?: GrantDelegationOptions ) : iam . Grant {
540- return makeGrantDelegation ( grantee , this , options ) ;
590+ return HostedZoneGrants . fromHostedZone ( this ) . delegation ( grantee , options ) ;
591+ }
592+ public get hostedZoneRef ( ) : HostedZoneReference {
593+ return {
594+ hostedZoneId : this . hostedZoneId ,
595+ } ;
541596 }
542597 }
543598 return new Import ( scope , id ) ;
0 commit comments