mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(eventbridge): paginate ListConnections results (#6709)
This commit is contained in:
1 parent
258994c1b9
commit
ed77a1d4ee
5 files changed
+272
-6
No files matched your search
+8
-2
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsJson11Controller;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ApiDestination;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Archive;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ArchiveState;
|
||||
@@ -588,12 +589,17 @@ public class EventBridgeHandler {
|
||||
private Response handleListConnections(JsonNode request, String region) {
|
||||
String namePrefix = request.path("NamePrefix").asText(null);
|
||||
ConnectionState state = parseConnectionState(request.path("ConnectionState").asText(null));
|
||||
List<Connection> connections = eventBridgeService.listConnections(namePrefix, state, region);
|
||||
Integer limit = readLimit(request.path("Limit"));
|
||||
String nextToken = Pagination.parseNextToken(request, "NextToken", "SerializationException");
|
||||
PaginatedResult<Connection> page = eventBridgeService.listConnections(namePrefix, state, limit, nextToken, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode connectionsArray = response.putArray("Connections");
|
||||
for (Connection connection : connections) {
|
||||
for (Connection connection : page.items()) {
|
||||
connectionsArray.add(buildConnectionNode(connection, false));
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("NextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -58,6 +58,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
@@ -413,12 +414,19 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
*/
|
||||
public PaginatedResult<Rule> listRules(String busName, String namePrefix, Integer limit,
|
||||
String nextToken, String region) {
|
||||
return paginate(listRules(busName, namePrefix, region), Rule::getName, limit, nextToken, "rule");
|
||||
}
|
||||
|
||||
private static <T> PaginatedResult<T> paginate(List<T> items, Function<T, String> cursorOf, Integer limit,
|
||||
String nextToken, String scope) {
|
||||
if (limit != null && (limit < 1 || limit > MAX_LIST_LIMIT)) {
|
||||
throw limitOutOfRange(limit.toString(), limit < 1);
|
||||
}
|
||||
return Pagination.paginate(listRules(busName, namePrefix, region), Rule::getName,
|
||||
limit != null ? limit : MAX_LIST_LIMIT, nextToken, "rule",
|
||||
token -> new AwsException("InvalidToken", "Invalid NextToken: " + token, 400));
|
||||
if (nextToken != null && (nextToken.isEmpty() || nextToken.length() > 2048)) {
|
||||
throw new AwsException("ValidationException", "NextToken must contain 1 to 2048 characters.", 400);
|
||||
}
|
||||
return Pagination.paginate(items, cursorOf, limit == null ? MAX_LIST_LIMIT : limit, nextToken, scope,
|
||||
token -> new AwsException("InvalidToken", "Invalid NextToken.", 400));
|
||||
}
|
||||
|
||||
static AwsException limitOutOfRange(String value, boolean belowMinimum) {
|
||||
@@ -1669,6 +1677,14 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
});
|
||||
}
|
||||
|
||||
public PaginatedResult<Connection> listConnections(String namePrefix, ConnectionState state, Integer limit,
|
||||
String nextToken, String region) {
|
||||
String effectivePrefix = namePrefix == null || namePrefix.isBlank() ? "" : namePrefix;
|
||||
String scope = "events:ListConnections:" + regionResolver.getAccountId() + ":" + region
|
||||
+ ":" + effectivePrefix + ":" + (state == null ? "" : state.name());
|
||||
return paginate(listConnections(namePrefix, state, region), Connection::getName, limit, nextToken, scope);
|
||||
}
|
||||
|
||||
private static void validateConnectionName(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("ValidationException", "Connection name is required.", 400);
|
||||
|
||||
Reference in new issue
Block a user