mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(stepfunctions): accept SDK Uuid for mapping updates (#7720)
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
856970a24f
commit
cab81a268b
4 files changed
+40
-10
No files matched your search
@@ -699,6 +699,9 @@ timestamps. Opaque dictionary keys, including secret version IDs and ECS log
|
||||
options, retain their original spelling. `describeSecret` returns metadata without
|
||||
the secret value. Disabled services fail with a catchable service exception.
|
||||
|
||||
The Lambda `updateEventSourceMapping` SDK task takes `Uuid` in JSONPath
|
||||
`Parameters` or JSONata `Arguments`. The direct Lambda REST API still uses `UUID`.
|
||||
|
||||
ECS `listServices` supports the same `MaxResults` and opaque `NextToken` as the
|
||||
direct ECS API. Lambda mapping tasks currently return an unpaginated list;
|
||||
`Marker` and `MaxItems` are rejected with `Lambda.InvalidParameterValueException`
|
||||
|
||||
@@ -104,12 +104,12 @@ public class SdkManagementTaskInvoker {
|
||||
input.path("EventSourceArn").asText(null));
|
||||
}
|
||||
case "updateEventSourceMapping" -> {
|
||||
String uuid = input.path("UUID").asText(null);
|
||||
String uuid = input.path("Uuid").asText(null);
|
||||
if (uuid == null || uuid.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValueException", "UUID is required.", 400);
|
||||
throw new AwsException("InvalidParameterValueException", "Uuid is required.", 400);
|
||||
}
|
||||
ObjectNode request = input.deepCopy();
|
||||
request.remove("UUID");
|
||||
request.remove("Uuid");
|
||||
yield lambda.updateEventSourceMapping(uuid, request.toString());
|
||||
}
|
||||
default -> throw new IllegalStateException("Unsupported Lambda management action");
|
||||
|
||||
+19
-1
@@ -19,9 +19,27 @@ class SdkManagementTaskInvokerTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final EcsJsonHandler ecs = mock(EcsJsonHandler.class);
|
||||
private final LambdaController lambda = mock(LambdaController.class);
|
||||
private final ServiceRegistry registry = mock(ServiceRegistry.class);
|
||||
private final SdkManagementTaskInvoker invoker = new SdkManagementTaskInvoker(ecs,
|
||||
mock(LambdaController.class), mock(SecretsManagerJsonHandler.class), registry, mapper);
|
||||
lambda, mock(SecretsManagerJsonHandler.class), registry, mapper);
|
||||
|
||||
@Test
|
||||
void usesSdkUuidWithoutChangingTheLambdaRequestBodyOrInput() throws Exception {
|
||||
when(registry.isServiceEnabled("lambda")).thenReturn(true);
|
||||
when(lambda.updateEventSourceMapping(eq("mapping-id"), anyString()))
|
||||
.thenReturn(Response.ok(mapper.readTree("{\"UUID\":\"mapping-id\",\"State\":\"Disabled\"}")).build());
|
||||
JsonNode input = mapper.readTree("{\"Uuid\":\"mapping-id\",\"Enabled\":false,\"BatchSize\":3}");
|
||||
|
||||
JsonNode result = invoker.invoke(StatesIntegration.parse(
|
||||
"arn:aws:states:::aws-sdk:lambda:updateEventSourceMapping").orElseThrow(), input, "eu-west-2");
|
||||
|
||||
ArgumentCaptor<String> body = ArgumentCaptor.forClass(String.class);
|
||||
verify(lambda).updateEventSourceMapping(eq("mapping-id"), body.capture());
|
||||
assertEquals(mapper.readTree("{\"Enabled\":false,\"BatchSize\":3}"), mapper.readTree(body.getValue()));
|
||||
assertEquals("mapping-id", input.path("Uuid").asText());
|
||||
assertEquals("mapping-id", result.path("UUID").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recasesModeledEcsMembersWithoutChangingLogOptionKeysOrValues() throws Exception {
|
||||
|
||||
+15
-6
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
|
||||
@@ -109,8 +110,9 @@ class StepFunctionsSdkManagementIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void lambdaMappingTasksUpdateAnActualMappingAndPreserveItsUuid() throws Exception {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"JSONPath", "JSONata"})
|
||||
void lambdaMappingTasksUpdateAnActualMappingAndPreserveItsUuid(String queryLanguage) throws Exception {
|
||||
String region = "eu-west-2";
|
||||
String name = "sdk-mapping-" + UUID.randomUUID();
|
||||
// An empty ZIP is a valid deployment archive; no invocation is needed for this management fixture.
|
||||
@@ -124,8 +126,8 @@ class StepFunctionsSdkManagementIntegrationTest {
|
||||
try {
|
||||
JsonNode listed = task("lambda", "listEventSourceMappings", Map.of("FunctionName", function), region, "aws");
|
||||
assertEquals(uuid, listed.path("EventSourceMappings").get(0).path("UUID").asText());
|
||||
JsonNode updated = task("lambda", "updateEventSourceMapping", Map.of("UUID", uuid,
|
||||
"Enabled", false, "BatchSize", 3), region, "aws");
|
||||
JsonNode updated = runTask("lambda", "updateEventSourceMapping", Map.of("Uuid", uuid,
|
||||
"Enabled", false, "BatchSize", 3), region, "aws", ACCOUNT, false, queryLanguage);
|
||||
assertEquals(uuid, updated.path("UUID").asText());
|
||||
assertEquals(3, updated.path("BatchSize").asInt());
|
||||
assertEquals("Disabled", updated.path("State").asText());
|
||||
@@ -135,7 +137,7 @@ class StepFunctionsSdkManagementIntegrationTest {
|
||||
JsonNode pagination = runTask("lambda", "listEventSourceMappings", Map.of("FunctionName", function,
|
||||
"MaxItems", 1), region, "aws", ACCOUNT, true);
|
||||
assertEquals("Lambda.InvalidParameterValueException", pagination.path("Error").asText());
|
||||
JsonNode error = runTask("lambda", "updateEventSourceMapping", Map.of("UUID", uuid,
|
||||
JsonNode error = runTask("lambda", "updateEventSourceMapping", Map.of("Uuid", uuid,
|
||||
"Enabled", true), region, "aws", "771661200002", true);
|
||||
assertEquals("Lambda.ResourceNotFoundException", error.path("Error").asText());
|
||||
} finally {
|
||||
@@ -151,9 +153,15 @@ class StepFunctionsSdkManagementIntegrationTest {
|
||||
|
||||
private static JsonNode runTask(String service, String action, Map<String, Object> parameters,
|
||||
String region, String partition, String account, boolean catchError) throws Exception {
|
||||
return runTask(service, action, parameters, region, partition, account, catchError, "JSONPath");
|
||||
}
|
||||
|
||||
private static JsonNode runTask(String service, String action, Map<String, Object> parameters,
|
||||
String region, String partition, String account, boolean catchError,
|
||||
String queryLanguage) throws Exception {
|
||||
ObjectNode task = MAPPER.createObjectNode().put("Type", "Task").put("End", true)
|
||||
.put("Resource", "arn:" + partition + ":states:::aws-sdk:" + service + ":" + action);
|
||||
task.set("Parameters", MAPPER.valueToTree(parameters));
|
||||
task.set("JSONata".equals(queryLanguage) ? "Arguments" : "Parameters", MAPPER.valueToTree(parameters));
|
||||
ObjectNode states = MAPPER.createObjectNode();
|
||||
states.set("Call", task);
|
||||
if (catchError) {
|
||||
@@ -163,6 +171,7 @@ class StepFunctionsSdkManagementIntegrationTest {
|
||||
states.set("Caught", MAPPER.valueToTree(Map.of("Type", "Pass", "End", true)));
|
||||
}
|
||||
ObjectNode definition = MAPPER.createObjectNode().put("StartAt", "Call");
|
||||
definition.put("QueryLanguage", queryLanguage);
|
||||
definition.set("States", states);
|
||||
try (SfnClient client = SfnClient.builder()
|
||||
.endpointOverride(URI.create("http://localhost:" + RestAssured.port))
|
||||
|
||||
Reference in new issue
Block a user