diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java index 82d2c10b8a..0ba721a7aa 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java @@ -1716,9 +1716,12 @@ public class AslExecutor { } else if ("$$".equals(path)) { resolved.set(realKey, context); } else { - resolved.set(realKey, resolvePath(path, input)); + // Pass the Context Object through so a $$. reference nested inside an + // intrinsic (e.g. States.Format(..., $$.Map.Item.Value.x)) can resolve it; + // for a plain $. or States.* input reference, context is simply ignored. + resolved.set(realKey, resolvePath(path, input, context)); } - } else if (val.isObject()) { + } else if (val.isObject() || val.isArray()) { resolved.set(key, resolveParameters(val, input, context)); } else { resolved.set(key, val); @@ -1726,27 +1729,53 @@ public class AslExecutor { } return resolved; } + if (parameters.isArray()) { + // Payload templates resolve .$ references at any depth, including inside arrays + // (e.g. an ECS Overrides.ContainerOverrides[].Environment[].Value.$). + ArrayNode resolvedArray = objectMapper.createArrayNode(); + for (JsonNode element : parameters) { + resolvedArray.add(resolveParameters(element, input, context)); + } + return resolvedArray; + } return parameters; } JsonNode resolvePath(String path, JsonNode root) { - JsonNode node = resolvePathNode(path, root); - // Most callers do not distinguish an absent path from an explicit null; collapse both to null. + return resolvePath(path, root, null); + } + + /** + * Resolve a JSONPath reference or {@code States.*} intrinsic. When {@code context} is + * non-null it is the Context Object ({@code $$}), letting intrinsic arguments reference it + * (e.g. a {@code $$.Map.Item.Value.x} argument nested inside {@code States.Format(...)}). + * It is null for ordinary input-only resolution, which preserves existing behavior. + * + *
Most callers do not distinguish an absent path from an explicit null, so both collapse
+ * to null; callers that care about presence (e.g. {@code IsPresent}) use {@link #resolvePathNode}.
+ */
+ JsonNode resolvePath(String path, JsonNode root, JsonNode context) {
+ JsonNode node = resolvePathNode(path, root, context);
return node.isMissingNode() ? NullNode.getInstance() : node;
}
+ JsonNode resolvePathNode(String path, JsonNode root) {
+ return resolvePathNode(path, root, null);
+ }
+
/**
* Resolves a reference path while preserving the distinction between an explicit null value
* (returns a {@link NullNode}) and a missing/absent path (returns a {@link MissingNode}).
* {@link #resolvePath} collapses both to null; only callers that care about presence
- * (e.g. {@code IsPresent}) should use this variant.
+ * (e.g. {@code IsPresent}) should use this variant. When {@code context} is non-null it is the
+ * Context Object ({@code $$}) available to {@code States.*} intrinsic arguments.
*/
- JsonNode resolvePathNode(String path, JsonNode root) {
+ JsonNode resolvePathNode(String path, JsonNode root, JsonNode context) {
if (path == null || "$".equals(path)) {
return root;
}
if (path.startsWith("States.")) {
- return evaluateIntrinsic(path, root);
+ return evaluateIntrinsic(path, root, context);
}
// Support dotted ($.a.b) and root-bracket ($[*], $[0]) forms; anything else is unsupported.
if (!path.startsWith("$.") && !path.startsWith("$[")) {
@@ -1842,7 +1871,7 @@ public class AslExecutor {
* States.Array, States.ArrayLength, States.ArrayContains, States.MathAdd, States.UUID.
* Throws FailStateException("States.Runtime") for unrecognized functions.
*/
- private JsonNode evaluateIntrinsic(String expr, JsonNode root) {
+ private JsonNode evaluateIntrinsic(String expr, JsonNode root, JsonNode context) {
int parenOpen = expr.indexOf('(');
int parenClose = expr.lastIndexOf(')');
if (parenOpen < 0 || parenClose < 0) {
@@ -1853,7 +1882,7 @@ public class AslExecutor {
return switch (fnName) {
case "States.StringToJson" -> {
- JsonNode arg = resolveIntrinsicArg(argsStr, root);
+ JsonNode arg = resolveIntrinsicArg(argsStr, root, context);
try {
yield objectMapper.readTree(arg.asText());
} catch (Exception e) {
@@ -1862,7 +1891,7 @@ public class AslExecutor {
}
}
case "States.JsonToString" -> {
- JsonNode arg = resolveIntrinsicArg(argsStr, root);
+ JsonNode arg = resolveIntrinsicArg(argsStr, root, context);
try {
yield objectMapper.getNodeFactory().textNode(objectMapper.writeValueAsString(arg));
} catch (Exception e) {
@@ -1882,7 +1911,7 @@ public class AslExecutor {
if (argIdx >= parts.size()) {
throw new FailStateException("States.Runtime", "States.Format: not enough arguments");
}
- JsonNode argVal = resolveIntrinsicArg(parts.get(argIdx++).trim(), root);
+ JsonNode argVal = resolveIntrinsicArg(parts.get(argIdx++).trim(), root, context);
sb.append(argVal.isTextual() ? argVal.asText() : argVal.toString());
i++; // skip '}'
} else {
@@ -1895,12 +1924,12 @@ public class AslExecutor {
List A whole-value {@code "x.$": "$$.Map.Item.Value"} Parameters field already resolved against
+ * the Context Object, but a {@code $$.} reference nested inside an intrinsic argument — e.g.
+ * {@code States.Format('.../{}', $$.Map.Item.Value.solutionId)} — used to fall through to an
+ * input-only lookup and resolve to null, because the context was never threaded from
+ * {@code resolveParameters} into {@code evaluateIntrinsic}/{@code resolveIntrinsicArg}. These
+ * tests pin the fix and guard the no-context (input-only) path against regression.
+ */
+class AslExecutorIntrinsicContextTest {
+
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ /** Only ObjectMapper is exercised by the path/intrinsic resolution methods under test. */
+ private AslExecutor newExecutor() {
+ return new AslExecutor(null, null, null, null, null, null, null, null,
+ null, null, mapper, null, null);
+ }
+
+ @Test
+ void statesFormat_resolvesContextArgInsideParameters() throws Exception {
+ AslExecutor executor = newExecutor();
+ // Shaped like a Map ItemSelector: $. args come from the Map state's effective input,
+ // $$.Map.Item.Value.* comes from the per-iteration Context Object.
+ JsonNode parameters = mapper.readTree("""
+ {
+ "provisionerFolder.$": "States.Format('/mnt/efs/{}/{}/{}/provisioner', $.systemId, $.systemConfigVersion, $$.Map.Item.Value.solutionId)"
+ }
+ """);
+ JsonNode input = mapper.readTree("""
+ { "systemId": "SYS1", "systemConfigVersion": "v3" }
+ """);
+ JsonNode context = mapper.readTree("""
+ { "Map": { "Item": { "Index": 0, "Value": { "solutionId": "SOLUTION_A" } } } }
+ """);
+
+ JsonNode resolved = executor.resolveParameters(parameters, input, context);
+
+ assertEquals("/mnt/efs/SYS1/v3/SOLUTION_A/provisioner",
+ resolved.path("provisionerFolder").asText());
+ }
+
+ @Test
+ void statesFormat_resolvesContextArgViaResolvePath() {
+ AslExecutor executor = newExecutor();
+ JsonNode input = mapper.createObjectNode();
+ JsonNode context = mapper.createObjectNode();
+ ((com.fasterxml.jackson.databind.node.ObjectNode) context).putObject("Map")
+ .putObject("Item").putObject("Value").put("solutionId", "SOLUTION_B");
+
+ JsonNode result = executor.resolvePath(
+ "States.Format('id={}', $$.Map.Item.Value.solutionId)", input, context);
+
+ assertEquals("id=SOLUTION_B", result.asText());
+ }
+
+ @Test
+ void wholeContext_resolvesInsideIntrinsic() {
+ AslExecutor executor = newExecutor();
+ JsonNode input = mapper.createObjectNode();
+ JsonNode context = mapper.createObjectNode();
+ ((com.fasterxml.jackson.databind.node.ObjectNode) context).put("token", "abc");
+
+ // States.JsonToString($$) serializes the whole Context Object.
+ JsonNode result = executor.resolvePath("States.JsonToString($$)", input, context);
+
+ assertEquals("{\"token\":\"abc\"}", result.asText());
+ }
+
+ @Test
+ void inputArgsStillResolveWithContextPresent() {
+ AslExecutor executor = newExecutor();
+ JsonNode input = mapper.createObjectNode();
+ ((com.fasterxml.jackson.databind.node.ObjectNode) input).put("a", "X").put("b", "Y");
+ JsonNode context = mapper.createObjectNode();
+
+ JsonNode result = executor.resolvePath("States.Format('{}-{}', $.a, $.b)", input, context);
+
+ assertEquals("X-Y", result.asText());
+ }
+
+ @Test
+ void noContext_intrinsicResolutionUnchanged() {
+ AslExecutor executor = newExecutor();
+ JsonNode input = mapper.createObjectNode();
+ ((com.fasterxml.jackson.databind.node.ObjectNode) input).put("name", "widget");
+
+ // The 2-arg form (context == null) must behave exactly as before: $. args resolve,
+ // and a stray $$. arg — which has no context to resolve against — yields "null".
+ // The "null" here pins Floci-internal transitional behavior, NOT AWS semantics (on real
+ // AWS the Context Object always exists); see resolveIntrinsicArg. It only holds until
+ // context is threaded into the remaining resolvePath callers, at which point this
+ // assertion should be updated rather than treated as a contract.
+ assertEquals("widget", executor.resolvePath("States.Format('{}', $.name)", input).asText());
+ assertEquals("null", executor.resolvePath(
+ "States.Format('{}', $$.Map.Item.Value.solutionId)", input).asText());
+ }
+}