EC2: describe_vpc_endpoint_services() now returns user-defined ones (#6578)
This commit is contained in:
parent
95dfa04691
commit
58a981a002
@ -41,6 +41,21 @@ class VPCServiceConfiguration(TaggedEC2Resource, CloudFormationModel):
|
||||
self.principals: List[str] = []
|
||||
self.ec2_backend = ec2_backend
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"AcceptanceRequired": self.acceptance_required,
|
||||
"AvailabilityZones": self.availability_zones,
|
||||
"BaseEndpointDnsNames": [self.endpoint_dns_name],
|
||||
"ManagesVpcEndpoints": self.manages_vpc_endpoints,
|
||||
"Owner": self.ec2_backend.account_id,
|
||||
"PrivateDnsName": self.private_dns_name,
|
||||
"PrivateDnsNames": [{"PrivateDnsName": self.private_dns_name}],
|
||||
"ServiceId": self.id,
|
||||
"ServiceName": self.service_name,
|
||||
"ServiceType": [{"ServiceType": self.service_type}],
|
||||
"VpcEndpointPolicySupported": True,
|
||||
}
|
||||
|
||||
|
||||
class VPCServiceConfigurationBackend:
|
||||
def __init__(self) -> None:
|
||||
|
@ -845,13 +845,16 @@ class VPCBackend:
|
||||
default_services = self._collect_default_endpoint_services(
|
||||
self.account_id, region # type: ignore[attr-defined]
|
||||
)
|
||||
custom_services = [x.to_dict() for x in self.configurations.values()] # type: ignore
|
||||
all_services = default_services + custom_services
|
||||
|
||||
for service_name in service_names:
|
||||
if service_name not in [x["ServiceName"] for x in default_services]:
|
||||
if service_name not in [x["ServiceName"] for x in all_services]:
|
||||
raise InvalidServiceName(service_name)
|
||||
|
||||
# Apply filters specified in the service_names and filters arguments.
|
||||
filtered_services = sorted(
|
||||
self._filter_endpoint_services(service_names, filters, default_services),
|
||||
self._filter_endpoint_services(service_names, filters, all_services),
|
||||
key=itemgetter("ServiceName"),
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ import pytest
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_ec2, mock_elbv2
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
from moto.moto_api._internal import mock_random
|
||||
|
||||
# See our Development Tips on writing tests for hints on how to write good tests:
|
||||
@ -101,13 +102,11 @@ def test_create_vpc_endpoint_service_configuration_with_options():
|
||||
region_name="us-east-2", lb_type="gateway", zone="us-east-1c"
|
||||
)
|
||||
|
||||
resp = client.create_vpc_endpoint_service_configuration(
|
||||
config = client.create_vpc_endpoint_service_configuration(
|
||||
GatewayLoadBalancerArns=[lb_arn],
|
||||
AcceptanceRequired=False,
|
||||
PrivateDnsName="example.com",
|
||||
)
|
||||
assert "ServiceConfiguration" in resp
|
||||
config = resp["ServiceConfiguration"]
|
||||
)["ServiceConfiguration"]
|
||||
|
||||
assert config["AcceptanceRequired"] is False
|
||||
assert config["PrivateDnsName"] == "example.com"
|
||||
@ -118,6 +117,13 @@ def test_create_vpc_endpoint_service_configuration_with_options():
|
||||
"Value": "val",
|
||||
}
|
||||
|
||||
service_name = config["ServiceName"]
|
||||
detail = client.describe_vpc_endpoint_services(ServiceNames=[service_name])[
|
||||
"ServiceDetails"
|
||||
][0]
|
||||
assert detail["ServiceName"] == service_name
|
||||
assert detail["Owner"] == DEFAULT_ACCOUNT_ID
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_elbv2
|
||||
|
Loading…
Reference in New Issue
Block a user