mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 14:57:54 -05:00
feat(ec2): validate DescribeVpnGateways and add DescribeEgressOnlyInternetGateways (#3879)
* feat(ec2): validate DescribeVpnGateways and add DescribeEgressOnlyInternetGateways * refactor(ec2): drop unused region parameter from empty gateway discovery * fix(ec2): return an empty set for an unknown egress-only gateway ID --------- Co-authored-by: Jason van Zyl <jason@vanzyl.ca>
This commit is contained in:
1 parent
b782530cd2
commit
a154470172
7 files changed
+339
-9
No files matched your search
@@ -148,6 +148,8 @@ public class Ec2QueryHandler {
|
||||
case "ReplaceTransitGatewayRoute" -> handleReplaceTransitGatewayRoute(params, region);
|
||||
case "SearchTransitGatewayRoutes" -> handleSearchTransitGatewayRoutes(params, region);
|
||||
case "ExportTransitGatewayRoutes" -> handleExportTransitGatewayRoutes(params, region);
|
||||
case "DescribeEgressOnlyInternetGateways" ->
|
||||
handleDescribeEgressOnlyInternetGateways(params);
|
||||
case "CreateDefaultVpc" -> handleCreateDefaultVpc(params, region);
|
||||
case "AssociateVpcCidrBlock" -> handleAssociateVpcCidrBlock(params, region);
|
||||
case "DisassociateVpcCidrBlock" -> handleDisassociateVpcCidrBlock(params, region);
|
||||
@@ -196,7 +198,7 @@ public class Ec2QueryHandler {
|
||||
// VPN Gateways. There is no VPN gateway model; an empty set is
|
||||
// AWS-accurate for an account without VPN gateways and unblocks the
|
||||
// CDK VPC context provider, which always issues this describe.
|
||||
case "DescribeVpnGateways" -> handleDescribeVpnGateways();
|
||||
case "DescribeVpnGateways" -> handleDescribeVpnGateways(params);
|
||||
|
||||
// Route Tables
|
||||
case "CreateRouteTable" -> handleCreateRouteTable(params, region);
|
||||
@@ -2743,6 +2745,38 @@ public class Ec2QueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleDescribeEgressOnlyInternetGateways(MultivaluedMap<String, String> p) {
|
||||
validateEmptyDiscoveryPagination(p, 255);
|
||||
service.describeEgressOnlyInternetGatewayIds(getFilters(p));
|
||||
return emptyDescribeResponse(
|
||||
"DescribeEgressOnlyInternetGateways", "egressOnlyInternetGatewaySet");
|
||||
}
|
||||
|
||||
private void validateEmptyDiscoveryPagination(MultivaluedMap<String, String> p, int maximum) {
|
||||
String rawMaxResults = p.getFirst("MaxResults");
|
||||
if (rawMaxResults != null) {
|
||||
int maxResults = parseIntParam(p, "MaxResults", 0);
|
||||
if (maxResults < 5 || maxResults > maximum) {
|
||||
throw new AwsException("InvalidMaxResults",
|
||||
"The specified value for MaxResults is not valid.", 400);
|
||||
}
|
||||
}
|
||||
if (p.getFirst("NextToken") != null) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid NextToken", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Response emptyDescribeResponse(String action, String resultSet) {
|
||||
String response = action + "Response";
|
||||
String xml = new XmlBuilder()
|
||||
.start(response, AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start(resultSet).end(resultSet)
|
||||
.end(response)
|
||||
.build();
|
||||
return xmlResponse(xml);
|
||||
}
|
||||
|
||||
private Response handleDeleteVpcEndpoints(MultivaluedMap<String, String> p, String region) {
|
||||
List<String> endpointIds = getList(p, "VpcEndpointId");
|
||||
service.deleteVpcEndpoints(region, endpointIds);
|
||||
@@ -3474,14 +3508,9 @@ public class Ec2QueryHandler {
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private Response handleDescribeVpnGateways() {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeVpnGatewaysResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start("vpnGatewaySet")
|
||||
.end("vpnGatewaySet")
|
||||
.end("DescribeVpnGatewaysResponse");
|
||||
return xmlResponse(xml.build());
|
||||
private Response handleDescribeVpnGateways(MultivaluedMap<String, String> p) {
|
||||
service.describeVpnGatewayIds(getList(p, "VpnGatewayId"), getFilters(p));
|
||||
return emptyDescribeResponse("DescribeVpnGateways", "vpnGatewaySet");
|
||||
}
|
||||
|
||||
private Response handleDescribeRouteTables(MultivaluedMap<String, String> p, String region) {
|
||||
|
||||
@@ -147,6 +147,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
// bound, but allow enough time for that legitimate cold-start path before cancellation.
|
||||
private static final Duration CONTAINER_LAUNCH_TIMEOUT = Duration.ofMinutes(5);
|
||||
private static final long CONTAINER_LAUNCH_POLL_MILLIS = 50;
|
||||
private static final Set<String> VPN_GATEWAY_FILTERS = Set.of(
|
||||
"amazon-side-asn", "attachment.state", "attachment.vpc-id", "availability-zone",
|
||||
"state", "tag-key", "tag-value", "type", "vpn-gateway-id");
|
||||
private static final Set<String> EGRESS_ONLY_INTERNET_GATEWAY_FILTERS = Set.of(
|
||||
"attachment.state", "attachment.vpc-id",
|
||||
"egress-only-internet-gateway-id", "tag-key", "tag-value");
|
||||
|
||||
private final String defaultAccountId;
|
||||
private final jakarta.enterprise.inject.Instance<RequestContext> requestContextInstance;
|
||||
@@ -3563,6 +3569,33 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> describeVpnGatewayIds(
|
||||
List<String> gatewayIds, Map<String, List<String>> filters) {
|
||||
requireSupportedFilters(filters, VPN_GATEWAY_FILTERS);
|
||||
if (!gatewayIds.isEmpty()) {
|
||||
throw new AwsException("InvalidVpnGatewayID.NotFound",
|
||||
"The vpnGateway ID '" + gatewayIds.getFirst() + "' does not exist", 400);
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// AWS answers an unknown egress-only gateway ID with an empty set, not an error; callers such as
|
||||
// the Terraform provider treat the empty result as "not found".
|
||||
public List<String> describeEgressOnlyInternetGatewayIds(Map<String, List<String>> filters) {
|
||||
requireSupportedFilters(filters, EGRESS_ONLY_INTERNET_GATEWAY_FILTERS);
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private void requireSupportedFilters(Map<String, List<String>> filters, Set<String> supportedFilters) {
|
||||
filters.keySet().stream()
|
||||
.filter(name -> !supportedFilters.contains(name)
|
||||
&& !(supportedFilters.contains("tag-key") && name.startsWith("tag:")))
|
||||
.findFirst()
|
||||
.ifPresent(name -> {
|
||||
throw new AwsException("InvalidParameterValue", "The filter '" + name + "' is invalid", 400);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteVpc(String region, String vpcId) {
|
||||
ensureDefaultResources(region);
|
||||
getRequiredVpc(region, vpcId);
|
||||
|
||||
Reference in new issue
Block a user