diff --git a/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributes.java b/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributes.java index da201f7d04..110852f1e3 100644 --- a/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributes.java +++ b/src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributes.java @@ -29,14 +29,21 @@ final class ElbV2DefaultAttributes { static Map forLoadBalancer(LoadBalancer lb) { String type = lb.getType() == null ? "application" : lb.getType().toLowerCase(); Map defaults = new LinkedHashMap<>(); + // Supported by every type: deletion protection and cross-zone load balancing, and nothing + // else. Cross-zone is on for an ALB and off for the others, which is the one default that + // differs by type rather than the key simply not existing. defaults.put("deletion_protection.enabled", "false"); - defaults.put("access_logs.s3.enabled", "false"); - defaults.put("access_logs.s3.bucket", ""); - defaults.put("access_logs.s3.prefix", ""); - // Cross-zone load balancing is on for an ALB and off for the others, which is the one - // default that differs by type rather than the key simply not existing. defaults.put("load_balancing.cross_zone.enabled", "application".equals(type) ? "true" : "false"); + // Access logs are an Application and Network Load Balancer attribute. A Gateway Load + // Balancer does not have them, and reporting them for one would hand a client a schema + // AWS never returns. + if ("application".equals(type) || "network".equals(type)) { + defaults.put("access_logs.s3.enabled", "false"); + defaults.put("access_logs.s3.bucket", ""); + defaults.put("access_logs.s3.prefix", ""); + } + if ("application".equals(type)) { defaults.put("idle_timeout.timeout_seconds", "60"); defaults.put("client_keep_alive.seconds", "3600"); diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java index f9856411e7..30cda7d5b2 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2DefaultAttributesIntegrationTest.java @@ -106,6 +106,32 @@ class ElbV2DefaultAttributesIntegrationTest { not(hasItem("idle_timeout.timeout_seconds"))); } + /** + * Access logs are an Application and Network Load Balancer attribute. A Gateway Load Balancer + * has only the two every type shares, and reporting more would hand a client a schema AWS + * never returns for it. + */ + @Test + void aGatewayLoadBalancerGetsOnlyTheAttributesEveryTypeShares() { + String arn = createLoadBalancer("attrs-gwlb", "gateway", "10.100."); + + given() + .formParam("Action", "DescribeLoadBalancerAttributes") + .formParam("LoadBalancerArn", arn) + .header("Authorization", AUTH) + .when().post("/") + .then() + .statusCode(200) + .body("DescribeLoadBalancerAttributesResponse.DescribeLoadBalancerAttributesResult.Attributes.member.Key", + hasItem("deletion_protection.enabled")) + .body("DescribeLoadBalancerAttributesResponse.DescribeLoadBalancerAttributesResult.Attributes.member.find { it.Key == 'load_balancing.cross_zone.enabled' }.Value", + equalTo("false")) + .body("DescribeLoadBalancerAttributesResponse.DescribeLoadBalancerAttributesResult.Attributes.member.Key", + not(hasItem("access_logs.s3.enabled"))) + .body("DescribeLoadBalancerAttributesResponse.DescribeLoadBalancerAttributesResult.Attributes.member.Key", + not(hasItem("idle_timeout.timeout_seconds"))); + } + @Test void aModifiedAttributeWinsOverItsDefaultAndTheRestStillReport() { String arn = createLoadBalancer("attrs-modified", "application", "10.99.");