feat(cloudformation): expose RegionalEndpoints of a web function endpoint to Fn::GetAtt (#6907)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-29 08:25:24 -04:00
1 parent 5f89a70095
commit c4ae11c414
11 files changed
+232 -18

No files matched your search

@@ -1,6 +1,8 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.TextNode;
import io.github.hectorvent.floci.services.cloudformation.model.StackEvent;
@@ -29,11 +31,23 @@ public interface CfnResourceProvisioner {
return Map.of();
}
/** GetAtt attributes the registry schema types as objects or arrays, stored as JSON text, by resource type. */
default Map<String, Set<String>> jsonAttributes() {
return Map.of();
}
/** The JSON type of a stored GetAtt value; most resource attributes are strings. */
default JsonNode attributeValue(String resourceType, String attributeName, String value) {
if (integerAttributes().getOrDefault(resourceType, Set.of()).contains(attributeName)) {
return LongNode.valueOf(Long.parseLong(value));
}
if (jsonAttributes().getOrDefault(resourceType, Set.of()).contains(attributeName)) {
try {
return StoredJson.MAPPER.readTree(value);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Invalid stored " + resourceType + " attribute " + attributeName, e);
}
}
return TextNode.valueOf(value);
}
@@ -177,4 +191,12 @@ public interface CfnResourceProvisioner {
// no-op by default: only a provisioner with tracking of its own to carry (generated
// sub-resources, cleanup entries, an undo snapshot) needs this
}
/** Keeps the mapper private, which an interface field cannot be. */
final class StoredJson {
private static final ObjectMapper MAPPER = new ObjectMapper();
private StoredJson() {
}
}
}
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebResponses;
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebService;
import io.github.hectorvent.floci.services.lambdaweb.model.WebFunction;
import io.github.hectorvent.floci.services.lambdaweb.model.WebFunctionEndpoint;
@@ -120,7 +121,9 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner {
String region = snapshot.path("region").asText();
String functionArn = snapshot.path("functionArn").asText();
if ("endpoint".equals(snapshot.path("type").asText())) {
service.updateEndpoint(region, functionArn, snapshot.path("endpointName").asText(), snapshot.get("patch"));
WebFunctionEndpoint restored = service.updateEndpoint(region, functionArn,
snapshot.path("endpointName").asText(), snapshot.get("patch")).after();
resource.getAttributes().put("RegionalEndpoints", regionalEndpoints(restored));
} else {
service.replaceTags(region, functionArn,
MAPPER.convertValue(snapshot.get("tags"), new TypeReference<Map<String, String>>() {}));
@@ -219,6 +222,7 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner {
r.getAttributes().put("FunctionArn", endpoint.functionArn);
r.getAttributes().put("EndpointArn", endpoint.endpointArn);
r.getAttributes().put("DomainName", endpoint.domainName);
r.getAttributes().put("RegionalEndpoints", regionalEndpoints(endpoint));
r.getAttributes().put("State", "Active");
r.getAttributes().put("StateReason", "The endpoint is active and invokable.");
if (endpoint.updateStatus != null) {
@@ -344,6 +348,32 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner {
return out;
}
@Override
public Map<String, Set<String>> jsonAttributes() {
return Map.of(ENDPOINT, Set.of("RegionalEndpoints"));
}
private static String regionalEndpoints(WebFunctionEndpoint endpoint) {
return upperKeys(MAPPER.valueToTree(LambdaWebResponses.regionalEndpoints(endpoint)), false).toString();
}
/** The API's members in PascalCase. The region names that key RegionalEndpoints stay as they are. */
private static JsonNode upperKeys(JsonNode node, boolean member) {
if (node.isObject()) {
ObjectNode out = MAPPER.createObjectNode();
node.properties().forEach(entry -> out.set(member
? Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1)
: entry.getKey(), upperKeys(entry.getValue(), true)));
return out;
}
if (node.isArray()) {
ArrayNode out = MAPPER.createArrayNode();
node.forEach(item -> out.add(upperKeys(item, true)));
return out;
}
return node;
}
private static JsonNode lowerKeys(JsonNode node) {
if (node.isObject()) {
return toCamelCase(node, Set.of());
@@ -71,15 +71,8 @@ public class RedshiftEventSubscriptionCfnProvisioner implements CfnResourceProvi
}
@Override
public JsonNode attributeValue(String resourceType, String attributeName, String value) {
if ("SourceIdsList".equals(attributeName) || "EventCategoriesList".equals(attributeName)) {
try {
return MAPPER.readTree(value);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Invalid stored Redshift event subscription attribute " + attributeName, e);
}
}
return CfnResourceProvisioner.super.attributeValue(resourceType, attributeName, value);
public Map<String, Set<String>> jsonAttributes() {
return Map.of(TYPE, Set.of("SourceIdsList", "EventCategoriesList"));
}
@Override
@@ -13,7 +13,7 @@ import java.util.Map;
import java.util.TreeMap;
/** The wire shapes of Lambda Web responses. AWS emits members in alphabetical order with microsecond timestamps. */
final class LambdaWebResponses {
public final class LambdaWebResponses {
private static final DateTimeFormatter TIMESTAMP =
DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSS'Z'").withZone(ZoneOffset.UTC);
@@ -123,6 +123,17 @@ final class LambdaWebResponses {
static Map<String, Object> endpoint(WebFunctionEndpoint endpoint, WebFunctionEndpoint regionalSource, View view) {
Map<String, Object> out = endpointSummary(endpoint, view);
out.put("functionArn", endpoint.functionArn);
out.put("regionalEndpoints", regionalEndpoints(endpoint, regionalSource, view));
return out;
}
/** The per-region block of a stored endpoint, which CloudFormation's RegionalEndpoints gives too. */
public static Map<String, Object> regionalEndpoints(WebFunctionEndpoint endpoint) {
return regionalEndpoints(endpoint, endpoint, View.STORED);
}
private static Map<String, Object> regionalEndpoints(WebFunctionEndpoint endpoint, WebFunctionEndpoint regionalSource,
View view) {
Map<String, Object> regional = node();
for (String region : endpoint.regions) {
Map<String, Object> entry = node();
@@ -136,8 +147,7 @@ final class LambdaWebResponses {
putEndpointState(entry, regionalSource, view, true);
regional.put(region, entry);
}
out.put("regionalEndpoints", regional);
return out;
return regional;
}
private static void putConfigs(Map<String, Object> out, WebFunctionEndpoint endpoint) {