mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): route ProvisionContext.resolveStringList through the list-aware engine (#2937)
ProvisionContext.resolveStringList was a scalar-only copy of the monolith helper that CloudFormationResourceProvisioner already reroutes, and it is the one the extracted per-service provisioners call (IamRoleCfnProvisioner ManagedPolicyArns, OrganizationsCfnProvisioner ParentIds and TargetIds). Delegate to engine.resolveStringList so a list-valued intrinsic (Fn::Split / Fn::GetAZs / Fn::Cidr, including one selected by Fn::If) expands to its real values instead of collapsing to one comma-joined string, keeping "every list property" true and stopping the two helpers from drifting. The mock engines in IamRoleCfnProvisionerTest and OrganizationsCfnProvisionerTest now delegate resolveStringList to the real method (literal arrays still resolve each element through the existing resolve(...) stub).
This commit is contained in:
1 parent
26592e7115
commit
2cea55bda5
4 files changed
+52
-10
No files matched your search
+12
-10
@@ -80,18 +80,20 @@ public record ProvisionContext(CloudFormationTemplateEngine engine, String regio
|
||||
return engine.resolve(props.get(name));
|
||||
}
|
||||
|
||||
/** Resolves an array property to its non-blank elements, or an empty list when absent. */
|
||||
/**
|
||||
* Resolves a list property to its non-blank elements, or an empty list when absent.
|
||||
*
|
||||
* <p>Routes through {@code engine.resolveStringList} so a list-valued intrinsic
|
||||
* ({@code Fn::Split} / {@code Fn::GetAZs} / {@code Fn::Cidr}, including one selected by an
|
||||
* {@code Fn::If}) expands to its real values instead of collapsing to a single comma-joined
|
||||
* string — the shape CDK emits for cross-stack references (issue #2937). Kept in lockstep
|
||||
* with the monolith helper the per-service provisioners were split from.
|
||||
*/
|
||||
public List<String> resolveStringList(JsonNode props, String name) {
|
||||
List<String> values = new ArrayList<>();
|
||||
if (props != null && props.has(name) && props.get(name).isArray()) {
|
||||
for (JsonNode element : props.get(name)) {
|
||||
String resolved = engine.resolve(element);
|
||||
if (resolved != null && !resolved.isBlank()) {
|
||||
values.add(resolved);
|
||||
}
|
||||
}
|
||||
if (props == null || !props.has(name)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return values;
|
||||
return new ArrayList<>(engine.resolveStringList(props.get(name)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
@@ -53,6 +53,10 @@ class IamRoleCfnProvisionerTest {
|
||||
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
// resolveStringList delegates to the real engine method; for the literal arrays these
|
||||
// tests use it just walks the array and calls resolve(...) per element, stubbed above.
|
||||
when(engine.resolveStringList(any())).thenCallRealMethod();
|
||||
|
||||
when(engine.resolveJsonAttribute(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node != null && node.isTextual() ? node.asText() : node.toString();
|
||||
|
||||
+3
@@ -62,6 +62,9 @@ class OrganizationsCfnProvisionerTest {
|
||||
return node == null ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
// resolveStringList delegates to the real engine method; for the literal arrays these
|
||||
// tests use it just walks the array and calls resolve(...) per element, stubbed above.
|
||||
when(engine.resolveStringList(any())).thenCallRealMethod();
|
||||
when(engine.resolveJsonAttribute(any())).thenAnswer(inv -> {
|
||||
JsonNode node = inv.getArgument(0);
|
||||
return node.isTextual() ? node.asText() : node.toString();
|
||||
|
||||
+33
@@ -15,6 +15,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The shared helpers on {@link ProvisionContext} that extracted provisioners build on. */
|
||||
@@ -177,4 +179,35 @@ class ProvisionContextTest {
|
||||
"a replacing update derives a different name and must still create");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The whole property node is handed to {@code engine.resolveStringList}, so a list-valued
|
||||
* intrinsic ({@code Fn::Split} over a cross-stack {@code Fn::ImportValue}) expands to its real
|
||||
* values instead of collapsing to one comma-joined string (issue #2937). Resolving each element
|
||||
* in isolation, as the old copy did, would have yielded a single unusable entry.
|
||||
*/
|
||||
@Test
|
||||
void resolveStringListRoutesListValuedIntrinsicsThroughTheEngine() {
|
||||
JsonNode props = props("""
|
||||
{
|
||||
"SubnetIds": {
|
||||
"Fn::Split": [",", {"Fn::ImportValue": "vpc-stack:PrivateSubnetIds"}]
|
||||
}
|
||||
}
|
||||
""");
|
||||
when(engine.resolveStringList(props.get("SubnetIds")))
|
||||
.thenReturn(List.of("subnet-a", "subnet-b", "subnet-c"));
|
||||
|
||||
assertEquals(List.of("subnet-a", "subnet-b", "subnet-c"),
|
||||
context(null).resolveStringList(props, "SubnetIds"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveStringListReturnsAMutableEmptyListForAnAbsentPropertyWithoutCallingTheEngine() {
|
||||
List<String> values = context(null).resolveStringList(props("{}"), "ManagedPolicyArns");
|
||||
|
||||
assertEquals(List.of(), values);
|
||||
values.add("still-mutable");
|
||||
verify(engine, never()).resolveStringList(any());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user