-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_bind()
method for IIpv6Addresses
#8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,18 +139,20 @@ export interface AllocateCidrRequest { | |
} | ||
|
||
/** | ||
* Request for allocation of the VPC IPv6 CIDR. | ||
* Internal interface to get VPC context to IpAddresses. | ||
* | ||
* @internal | ||
*/ | ||
export interface AllocateVpcIpv6CidrRequest { | ||
export interface _VpcContext { | ||
/** | ||
* The VPC construct to attach to. | ||
* VPC construct. | ||
*/ | ||
readonly scope: Construct; | ||
scope: Construct; | ||
|
||
/** | ||
* The id of the VPC. | ||
* Id of the VPC. | ||
*/ | ||
readonly vpcId: string; | ||
vpcId: string; | ||
} | ||
|
||
/** | ||
|
@@ -446,18 +448,18 @@ export class Ipv6Addresses { | |
*/ | ||
export interface IIpv6Addresses { | ||
/** | ||
* Whether the IPv6 CIDR is Amazon provided or not. | ||
* Internal function to get scope and context from VPC. | ||
* | ||
* Note this is specific to the IPv6 CIDR. | ||
* @internal | ||
*/ | ||
amazonProvided: boolean, | ||
_bind(context: _VpcContext): void; | ||
|
||
/** | ||
* Called by VPC to allocate IPv6 CIDR. | ||
* | ||
* Note this is specific to the IPv6 CIDR. | ||
*/ | ||
allocateVpcIpv6Cidr(input: AllocateVpcIpv6CidrRequest): CfnVPCCidrBlock; | ||
allocateVpcIpv6Cidr(): CfnVPCCidrBlock; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exposing L1 types at the L2 layer. Contributing guidelines say we don't do that. Don't return the In our case, that probably translates to returning vpcCidrBlock.attrIpv6CidrBlock. And wrap it in a return object ( |
||
|
||
/** | ||
* Split IPv6 CIDR block up for subnets. | ||
|
@@ -483,22 +485,45 @@ class AmazonProvided implements IIpv6Addresses { | |
/** | ||
* Whether the IPv6 CIDR is Amazon provided or not. | ||
*/ | ||
amazonProvided: boolean; | ||
private readonly amazonProvided: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property is not necessary. It is always |
||
|
||
/** | ||
* Internal VPC construct. | ||
*/ | ||
private scope?: Construct; | ||
|
||
/** | ||
* Internal id of the VPC. | ||
*/ | ||
private vpcId?: string; | ||
|
||
constructor() { | ||
this.amazonProvided = true; | ||
} | ||
|
||
/** | ||
* Internal function to get scope and context from VPC. | ||
* | ||
* @internal | ||
*/ | ||
_bind(context: _VpcContext): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is possible, but I don't think this is better than what you used to have. Either:
There is no rule that says BackgroundIn general, I don't like the use of self-mutating
Yes, probably in this case it will work correctly because state will be set and immediately used without the opportunity for caller code to do something else that would inappropriately reuse that state. But you can imagine a scenario in which users would do the following, and we would reuse the state, and it would break: const ips = IpAddresses.amazonProvided();
const vpc1 = new Vpc(this, 'Vpc1', { ips: ips });
const vpc2 = new Vpc(this, 'Vpc2', { ips: ips });
vpc1.allocateOneMoreSubnet(); // Probably calls `this.ips.allocate()`; the last _bind() call was done by vpc2 so this might create objects in the wrong scope All in all, I know we have this pattern of mutating What to do?I would prefer one of the following: 1. Just keep the
|
||
this.scope = context.scope; | ||
this.vpcId = context.vpcId; | ||
} | ||
|
||
/** | ||
* Called by VPC to allocate IPv6 CIDR. | ||
* | ||
* Creates an Amazon provided CIDR block. | ||
* | ||
* Note this is specific to the IPv6 CIDR. | ||
*/ | ||
allocateVpcIpv6Cidr(input: AllocateVpcIpv6CidrRequest): CfnVPCCidrBlock { | ||
//throw new Error(`vpcId not found, got ${(scope as any).vpcId}`); | ||
return new CfnVPCCidrBlock(input.scope, 'ipv6cidr', { | ||
vpcId: input.vpcId, | ||
allocateVpcIpv6Cidr(): CfnVPCCidrBlock { | ||
if (this.scope === undefined || this.vpcId === undefined) { | ||
throw new Error('Context is unset when trying to allocate VPC IPv6 CIDR block'); | ||
} | ||
return new CfnVPCCidrBlock(this.scope, 'ipv6cidr', { | ||
vpcId: this.vpcId, | ||
amazonProvidedIpv6CidrBlock: this.amazonProvided, | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must not be internal, otherwise external users can never substitute their own implementation of
IIpv6Addresses
.