This commit is contained in:
Bert Blommers 2020-04-29 16:29:25 +01:00
parent f4888da334
commit 2d0087d500
4 changed files with 60 additions and 58 deletions

View File

@ -2881,7 +2881,8 @@ class VPCBackend(object):
vpc = self.get_vpc(vpc_id) vpc = self.get_vpc(vpc_id)
return vpc.associate_vpc_cidr_block(cidr_block, amazon_provided_ipv6_cidr_block) return vpc.associate_vpc_cidr_block(cidr_block, amazon_provided_ipv6_cidr_block)
def create_vpc_endpoint(self, def create_vpc_endpoint(
self,
vpc_id, vpc_id,
service_name, service_name,
type=None, type=None,
@ -2893,12 +2894,12 @@ class VPCBackend(object):
client_token=None, client_token=None,
security_group=None, security_group=None,
tag_specifications=None, tag_specifications=None,
private_dns_enabled=None private_dns_enabled=None,
): ):
vpc_endpoint_id = generate_vpc_end_point_id(vpc_id) vpc_endpoint_id = generate_vpc_end_point_id(vpc_id)
#validates if vpc is present or not. # validates if vpc is present or not.
self.get_vpc(vpc_id) self.get_vpc(vpc_id)
if type and type.lower() == "interface": if type and type.lower() == "interface":
@ -2911,15 +2912,12 @@ class VPCBackend(object):
dns_entries = create_dns_entries(service_name, vpc_endpoint_id) dns_entries = create_dns_entries(service_name, vpc_endpoint_id)
else : else:
# considering gateway if type is not mentioned. # considering gateway if type is not mentioned.
service_destination_cidr = randor_ipv4_cidr() service_destination_cidr = randor_ipv4_cidr()
for route_table_id in route_table_ids: for route_table_id in route_table_ids:
self.create_route( self.create_route(route_table_id, service_destination_cidr)
route_table_id,
service_destination_cidr
)
if dns_entries: if dns_entries:
dns_entries = [dns_entries] dns_entries = [dns_entries]
@ -2936,7 +2934,7 @@ class VPCBackend(object):
client_token, client_token,
security_group, security_group,
tag_specifications, tag_specifications,
private_dns_enabled private_dns_enabled,
) )
self.vpc_end_points[vpc_endpoint_id] = vpc_end_point self.vpc_end_points[vpc_endpoint_id] = vpc_end_point
@ -3560,7 +3558,7 @@ class VPCEndPoint(TaggedEC2Resource):
type=None, type=None,
policy_document=False, policy_document=False,
route_table_ids=None, route_table_ids=None,
subnet_ids =None, subnet_ids=None,
network_interface_ids=None, network_interface_ids=None,
dns_entries=None, dns_entries=None,
client_token=None, client_token=None,

View File

@ -185,13 +185,11 @@ class VPCs(BaseResponse):
client_token=client_token, client_token=client_token,
security_group=security_group, security_group=security_group,
tag_specifications=tag_specifications, tag_specifications=tag_specifications,
private_dns_enabled=private_dns_enabled private_dns_enabled=private_dns_enabled,
) )
template = self.response_template(CREATE_VPC_END_POINT) template = self.response_template(CREATE_VPC_END_POINT)
return template.render( return template.render(vpc_end_point=vpc_end_point)
vpc_end_point=vpc_end_point
)
CREATE_VPC_RESPONSE = """ CREATE_VPC_RESPONSE = """

View File

@ -194,13 +194,14 @@ def generate_route_id(route_table_id, cidr_block):
def generate_vpc_end_point_id(vpc_id): def generate_vpc_end_point_id(vpc_id):
return "%s-%s" % ('vpce', vpc_id[4:]) return "%s-%s" % ("vpce", vpc_id[4:])
def create_dns_entries(service_name, vpc_endpoint_id): def create_dns_entries(service_name, vpc_endpoint_id):
dns_entries = {} dns_entries = {}
dns_entries["dns_name"] = "{}-{}.{}".format(vpc_endpoint_id, dns_entries["dns_name"] = "{}-{}.{}".format(
random_resource_id(8), service_name) vpc_endpoint_id, random_resource_id(8), service_name
)
dns_entries["hosted_zone_id"] = random_resource_id(13).upper() dns_entries["hosted_zone_id"] = random_resource_id(13).upper()
return dns_entries return dns_entries

View File

@ -625,8 +625,7 @@ def test_create_vpc_end_point():
ec2 = boto3.client("ec2", region_name="us-west-1") ec2 = boto3.client("ec2", region_name="us-west-1")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16") vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
subnet = ec2.create_subnet(VpcId=vpc["Vpc"]["VpcId"], subnet = ec2.create_subnet(VpcId=vpc["Vpc"]["VpcId"], CidrBlock="10.0.0.0/24")
CidrBlock="10.0.0.0/24")
route_table = ec2.create_route_table(VpcId=vpc["Vpc"]["VpcId"]) route_table = ec2.create_route_table(VpcId=vpc["Vpc"]["VpcId"])
@ -634,13 +633,15 @@ def test_create_vpc_end_point():
vpc_end_point = ec2.create_vpc_endpoint( vpc_end_point = ec2.create_vpc_endpoint(
VpcId=vpc["Vpc"]["VpcId"], VpcId=vpc["Vpc"]["VpcId"],
ServiceName="com.amazonaws.us-east-1.s3", ServiceName="com.amazonaws.us-east-1.s3",
RouteTableIds=[route_table["RouteTable"]["RouteTableId"]] RouteTableIds=[route_table["RouteTable"]["RouteTableId"]],
) )
vpc_end_point["VpcEndpoint"]["ServiceName"].\ vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal(
should.equal("com.amazonaws.us-east-1.s3") "com.amazonaws.us-east-1.s3"
vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].\ )
should.equal(route_table["RouteTable"]["RouteTableId"]) vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].should.equal(
route_table["RouteTable"]["RouteTableId"]
)
vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"])
vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0) vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0)
@ -649,13 +650,15 @@ def test_create_vpc_end_point():
VpcId=vpc["Vpc"]["VpcId"], VpcId=vpc["Vpc"]["VpcId"],
ServiceName="com.amazonaws.us-east-1.s3", ServiceName="com.amazonaws.us-east-1.s3",
RouteTableIds=[route_table["RouteTable"]["RouteTableId"]], RouteTableIds=[route_table["RouteTable"]["RouteTableId"]],
VpcEndpointType="gateway" VpcEndpointType="gateway",
) )
vpc_end_point["VpcEndpoint"]["ServiceName"]. \ vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal(
should.equal("com.amazonaws.us-east-1.s3") "com.amazonaws.us-east-1.s3"
vpc_end_point["VpcEndpoint"]["RouteTableIds"][0]. \ )
should.equal(route_table["RouteTable"]["RouteTableId"]) vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].should.equal(
route_table["RouteTable"]["RouteTableId"]
)
vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"])
vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0) vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0)
@ -664,12 +667,14 @@ def test_create_vpc_end_point():
VpcId=vpc["Vpc"]["VpcId"], VpcId=vpc["Vpc"]["VpcId"],
ServiceName="com.amazonaws.us-east-1.s3", ServiceName="com.amazonaws.us-east-1.s3",
SubnetIds=[subnet["Subnet"]["SubnetId"]], SubnetIds=[subnet["Subnet"]["SubnetId"]],
VpcEndpointType="interface" VpcEndpointType="interface",
) )
vpc_end_point["VpcEndpoint"]["ServiceName"].\ vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal(
should.equal("com.amazonaws.us-east-1.s3") "com.amazonaws.us-east-1.s3"
vpc_end_point["VpcEndpoint"]["SubnetIds"][0].\ )
should.equal(subnet["Subnet"]["SubnetId"]) vpc_end_point["VpcEndpoint"]["SubnetIds"][0].should.equal(
subnet["Subnet"]["SubnetId"]
)
vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"])
len(vpc_end_point["VpcEndpoint"]["DnsEntries"]).should.be.greater_than(0) len(vpc_end_point["VpcEndpoint"]["DnsEntries"]).should.be.greater_than(0)