Enhancement : Ec2 - Add describe-vpc-endpoint-services method support. (#3108)
* Enhancement : Ec2 - Add describe-vpc-endpoint-services method support. * Fix:EC2-describe_vpc_endPoint_services changed the template * Fixed comments * Linting Co-authored-by: usmankb <usman@krazybee.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
a7ddcd7da3
commit
9894e1785a
@ -3074,6 +3074,21 @@ class VPCBackend(object):
|
||||
|
||||
return vpc_end_point
|
||||
|
||||
def get_vpc_end_point_services(self):
|
||||
vpc_end_point_services = self.vpc_end_points.values()
|
||||
|
||||
services = []
|
||||
for value in vpc_end_point_services:
|
||||
services.append(value.service_name)
|
||||
|
||||
availability_zones = EC2Backend.describe_availability_zones(self)
|
||||
|
||||
return {
|
||||
"servicesDetails": vpc_end_point_services,
|
||||
"services": services,
|
||||
"availability_zones": availability_zones,
|
||||
}
|
||||
|
||||
|
||||
class VPCPeeringConnectionStatus(object):
|
||||
def __init__(self, code="initiating-request", message=""):
|
||||
|
@ -191,6 +191,11 @@ class VPCs(BaseResponse):
|
||||
template = self.response_template(CREATE_VPC_END_POINT)
|
||||
return template.render(vpc_end_point=vpc_end_point)
|
||||
|
||||
def describe_vpc_endpoint_services(self):
|
||||
vpc_end_point_services = self.ec2_backend.get_vpc_end_point_services()
|
||||
template = self.response_template(DESCRIBE_VPC_ENDPOINT_RESPONSE)
|
||||
return template.render(vpc_end_points=vpc_end_point_services)
|
||||
|
||||
|
||||
CREATE_VPC_RESPONSE = """
|
||||
<CreateVpcResponse xmlns="http://ec2.amazonaws.com/doc/{{doc_date}}/">
|
||||
@ -449,3 +454,35 @@ CREATE_VPC_END_POINT = """ <CreateVpcEndpointResponse xmlns="http://monitoring.a
|
||||
<creationTimestamp>{{ vpc_end_point.created_at }}</creationTimestamp>
|
||||
</vpcEndpoint>
|
||||
</CreateVpcEndpointResponse>"""
|
||||
|
||||
DESCRIBE_VPC_ENDPOINT_RESPONSE = """<DescribeVpcEndpointServicesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
|
||||
<requestId>19a9ff46-7df6-49b8-9726-3df27527089d</requestId>
|
||||
<serviceNameSet>
|
||||
{% for serviceName in vpc_end_points.services %}
|
||||
<item>{{ serviceName }}</item>
|
||||
{% endfor %}
|
||||
</serviceNameSet>
|
||||
<serviceDetailSet>
|
||||
<item>
|
||||
{% for service in vpc_end_points.servicesDetails %}
|
||||
<owner>amazon</owner>
|
||||
<serviceType>
|
||||
<item>
|
||||
<serviceType>{{ service.type }}</serviceType>
|
||||
</item>
|
||||
</serviceType>
|
||||
<baseEndpointDnsNameSet>
|
||||
<item>{{ ".".join((service.service_name.split(".")[::-1])) }}</item>
|
||||
</baseEndpointDnsNameSet>
|
||||
<acceptanceRequired>false</acceptanceRequired>
|
||||
<availabilityZoneSet>
|
||||
{% for zone in vpc_end_points.availability_zones %}
|
||||
<item>{{ zone.name }}</item>
|
||||
{% endfor %}
|
||||
</availabilityZoneSet>
|
||||
<serviceName>{{ service.service_name }}</serviceName>
|
||||
<vpcEndpointPolicySupported>true</vpcEndpointPolicySupported>
|
||||
{% endfor %}
|
||||
</item>
|
||||
</serviceDetailSet>
|
||||
</DescribeVpcEndpointServicesResponse>"""
|
||||
|
@ -825,3 +825,34 @@ def test_describe_classic_link_dns_support_multiple():
|
||||
assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort(
|
||||
key=lambda x: x["VpcId"]
|
||||
)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_describe_vpc_end_point_services():
|
||||
ec2 = boto3.client("ec2", region_name="us-west-1")
|
||||
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
|
||||
|
||||
route_table = ec2.create_route_table(VpcId=vpc["Vpc"]["VpcId"])
|
||||
|
||||
ec2.create_vpc_endpoint(
|
||||
VpcId=vpc["Vpc"]["VpcId"],
|
||||
ServiceName="com.amazonaws.us-east-1.s3",
|
||||
RouteTableIds=[route_table["RouteTable"]["RouteTableId"]],
|
||||
VpcEndpointType="gateway",
|
||||
)
|
||||
|
||||
vpc_end_point_services = ec2.describe_vpc_endpoint_services()
|
||||
|
||||
assert vpc_end_point_services.get("ServiceDetails").should.be.true
|
||||
assert vpc_end_point_services.get("ServiceNames").should.be.true
|
||||
assert vpc_end_point_services.get("ServiceNames") == ["com.amazonaws.us-east-1.s3"]
|
||||
assert (
|
||||
vpc_end_point_services.get("ServiceDetails")[0]
|
||||
.get("ServiceType", [])[0]
|
||||
.get("ServiceType")
|
||||
== "gateway"
|
||||
)
|
||||
assert vpc_end_point_services.get("ServiceDetails")[0].get("AvailabilityZones") == [
|
||||
"us-west-1a",
|
||||
"us-west-1b",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user