mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(elbv2): add listener attribute and capacity reservation actions (#1021)
@pulumi/aws 6.66+ calls DescribeListenerAttributes and DescribeCapacityReservation when refreshing Listener and LoadBalancer resources. Floci returned UnsupportedOperation for both, which crashes the AWS provider. Implement DescribeListenerAttributes and ModifyListenerAttributes (mirroring the existing load balancer / target group attribute handlers, backed by the Listener.attributes map) and DescribeCapacityReservation (reports an empty reservation, since Floci does not reserve load balancer capacity). Add integration coverage for all three actions and their not-found error paths.
This commit is contained in:
1 parent
8af3611d7a
commit
1dfa7bfcab
3 files changed
+167
No files matched your search
@@ -69,6 +69,7 @@ public class ElbV2QueryHandler {
|
||||
case "DeleteLoadBalancer" -> handleDeleteLoadBalancer(params, region);
|
||||
case "ModifyLoadBalancerAttributes" -> handleModifyLoadBalancerAttributes(params, region);
|
||||
case "DescribeLoadBalancerAttributes"-> handleDescribeLoadBalancerAttributes(params, region);
|
||||
case "DescribeCapacityReservation" -> handleDescribeCapacityReservation(params, region);
|
||||
case "SetSecurityGroups" -> handleSetSecurityGroups(params, region);
|
||||
case "SetSubnets" -> handleSetSubnets(params, region);
|
||||
case "SetIpAddressType" -> handleSetIpAddressType(params, region);
|
||||
@@ -84,6 +85,8 @@ public class ElbV2QueryHandler {
|
||||
case "DescribeListeners" -> handleDescribeListeners(params, region);
|
||||
case "DeleteListener" -> handleDeleteListener(params, region);
|
||||
case "ModifyListener" -> handleModifyListener(params, region);
|
||||
case "ModifyListenerAttributes" -> handleModifyListenerAttributes(params, region);
|
||||
case "DescribeListenerAttributes" -> handleDescribeListenerAttributes(params, region);
|
||||
// Rules
|
||||
case "CreateRule" -> handleCreateRule(params, region);
|
||||
case "DescribeRules" -> handleDescribeRules(params, region);
|
||||
@@ -208,6 +211,31 @@ public class ElbV2QueryHandler {
|
||||
return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeCapacityReservation(MultivaluedMap<String, String> p, String region) {
|
||||
String arn = p.getFirst("LoadBalancerArn");
|
||||
ElbV2Service.CapacityReservation cr = service.describeCapacityReservation(region, arn);
|
||||
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeCapacityReservationResponse", AwsNamespaces.ELB_V2)
|
||||
.start("DescribeCapacityReservationResult");
|
||||
if (cr.lastModifiedTime() != null) {
|
||||
xml.elem("LastModifiedTime", ISO_FMT.format(cr.lastModifiedTime()));
|
||||
}
|
||||
if (cr.decreaseRequestsRemaining() != null) {
|
||||
xml.elem("DecreaseRequestsRemaining", cr.decreaseRequestsRemaining());
|
||||
}
|
||||
if (cr.minimumCapacityUnits() != null) {
|
||||
xml.start("MinimumLoadBalancerCapacity")
|
||||
.elem("CapacityUnits", cr.minimumCapacityUnits())
|
||||
.end("MinimumLoadBalancerCapacity");
|
||||
}
|
||||
xml.start("CapacityReservationState").end("CapacityReservationState")
|
||||
.end("DescribeCapacityReservationResult")
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("DescribeCapacityReservationResponse");
|
||||
return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
|
||||
private Response handleSetSecurityGroups(MultivaluedMap<String, String> p, String region) {
|
||||
String arn = p.getFirst("LoadBalancerArn");
|
||||
List<String> sgs = memberList(p, "SecurityGroups");
|
||||
@@ -462,6 +490,43 @@ public class ElbV2QueryHandler {
|
||||
return Response.ok(xml).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
|
||||
private Response handleModifyListenerAttributes(MultivaluedMap<String, String> p, String region) {
|
||||
String arn = p.getFirst("ListenerArn");
|
||||
Map<String, String> attrs = parseAttributes(p, "Attributes");
|
||||
service.modifyListenerAttributes(region, arn, attrs);
|
||||
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("ModifyListenerAttributesResponse", AwsNamespaces.ELB_V2)
|
||||
.start("ModifyListenerAttributesResult")
|
||||
.start("Attributes");
|
||||
for (Map.Entry<String, String> e : attrs.entrySet()) {
|
||||
xml.start("member").elem("Key", e.getKey()).elem("Value", e.getValue()).end("member");
|
||||
}
|
||||
xml.end("Attributes")
|
||||
.end("ModifyListenerAttributesResult")
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("ModifyListenerAttributesResponse");
|
||||
return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeListenerAttributes(MultivaluedMap<String, String> p, String region) {
|
||||
String arn = p.getFirst("ListenerArn");
|
||||
Map<String, String> attrs = service.describeListenerAttributes(region, arn);
|
||||
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeListenerAttributesResponse", AwsNamespaces.ELB_V2)
|
||||
.start("DescribeListenerAttributesResult")
|
||||
.start("Attributes");
|
||||
for (Map.Entry<String, String> e : attrs.entrySet()) {
|
||||
xml.start("member").elem("Key", e.getKey()).elem("Value", e.getValue()).end("member");
|
||||
}
|
||||
xml.end("Attributes")
|
||||
.end("DescribeListenerAttributesResult")
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("DescribeListenerAttributesResponse");
|
||||
return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
|
||||
// ── Rules ─────────────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateRule(MultivaluedMap<String, String> p, String region) {
|
||||
|
||||
@@ -145,6 +145,18 @@ public class ElbV2Service {
|
||||
lb.getAttributes().putAll(newAttrs);
|
||||
}
|
||||
|
||||
/** Capacity reservation status for a load balancer. All fields are {@code null} when no
|
||||
* capacity is reserved, which is always the case in Floci (capacity cannot be reserved). */
|
||||
public record CapacityReservation(Integer decreaseRequestsRemaining,
|
||||
Integer minimumCapacityUnits,
|
||||
Instant lastModifiedTime) {}
|
||||
|
||||
public CapacityReservation describeCapacityReservation(String region, String arn) {
|
||||
requireLoadBalancer(region, arn);
|
||||
// Floci does not reserve load balancer capacity, so there is never a reservation to report.
|
||||
return new CapacityReservation(null, null, null);
|
||||
}
|
||||
|
||||
public void setSecurityGroups(String region, String arn, List<String> sgIds) {
|
||||
LoadBalancer lb = requireLoadBalancer(region, arn);
|
||||
lb.setSecurityGroups(new ArrayList<>(sgIds));
|
||||
@@ -347,6 +359,16 @@ public class ElbV2Service {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<String, String> describeListenerAttributes(String region, String arn) {
|
||||
Listener listener = requireListener(region, arn);
|
||||
return new LinkedHashMap<>(listener.getAttributes());
|
||||
}
|
||||
|
||||
public void modifyListenerAttributes(String region, String arn, Map<String, String> newAttrs) {
|
||||
Listener listener = requireListener(region, arn);
|
||||
listener.getAttributes().putAll(newAttrs);
|
||||
}
|
||||
|
||||
public void deleteListener(String region, String listenerArn) {
|
||||
Map<String, Listener> regionListeners = listeners.getOrDefault(region, Map.of());
|
||||
Listener listener = regionListeners.remove(listenerArn);
|
||||
|
||||
Reference in new issue
Block a user