diff --git a/docs/services/ecr.md b/docs/services/ecr.md
index 7c4ce7b170..aa0e94bbee 100644
--- a/docs/services/ecr.md
+++ b/docs/services/ecr.md
@@ -17,7 +17,7 @@
| `DescribeRepositories` | List repositories or fetch by name |
| `DeleteRepository` | Delete a repository (with `force=true` semantics for non-empty repos) |
| `GetAuthorizationToken` | Returns a docker-login token + proxy endpoint |
-| `ListImages` | Enumerate tags and digests in a repository |
+| `ListImages` | Enumerate paginated tags and digests in a repository |
| `DescribeImages` | Image metadata: digest, size, push timestamp, manifest media type |
| `BatchGetImage` | Fetch image manifests, honoring `acceptedMediaTypes` |
| `BatchDeleteImage` | Delete images by tag or digest |
@@ -37,6 +37,11 @@
| `PutReplicationConfiguration` / `DescribeRegistry` | Store the registry's replication rules and return them with the registry ID (stored, not acted on) |
| `PutRegistryScanningConfiguration` / `GetRegistryScanningConfiguration` | Store the registry's scan type and scanning rules (stored, not acted on) |
+`ListImages` accepts `maxResults` from 1 to 1000 (default 100) and returns `nextToken`
+when another page remains. Tokens are scoped to the region, registry, and repository;
+local pages use stable tag order. Listing still enumerates tagged images and ignores
+the optional `filter` fields.
+
### Admin Endpoints
| Endpoint | Description |
diff --git a/pom.xml b/pom.xml
index 649f06ea9a..564145197a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -360,6 +360,12 @@
${aws.sdk.version}
test
+
+ software.amazon.awssdk
+ ecr
+ ${aws.sdk.version}
+ test
+
software.amazon.awssdk
bedrock
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java
index eb437aa942..dc3dc8796a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrJsonHandler.java
@@ -315,14 +315,27 @@ public class EcrJsonHandler {
private Response handleListImages(JsonNode request, String region) {
String repo = request.path("repositoryName").asText(null);
String registryId = request.path("registryId").asText(null);
- List ids = service.listImages(repo, registryId, region);
+ JsonNode limit = request.get("maxResults");
+ if (limit != null && !limit.isNull() && (!limit.isIntegralNumber() || !limit.canConvertToInt())) {
+ throw new AwsException("InvalidParameterException", "maxResults must be between 1 and 1000", 400);
+ }
+ JsonNode token = request.get("nextToken");
+ if (token != null && !token.isNull() && !token.isTextual()) {
+ throw new AwsException("InvalidParameterException", "Invalid nextToken", 400);
+ }
+ Integer maxResults = request.hasNonNull("maxResults") ? limit.asInt() : null;
+ PaginatedResult page = service.listImages(repo, registryId, region,
+ maxResults, request.path("nextToken").asText(null));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode arr = objectMapper.createArrayNode();
- for (ImageIdentifier id : ids) {
+ for (ImageIdentifier id : page.items()) {
arr.add(buildImageIdentifier(id));
}
response.set("imageIds", arr);
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
return Response.ok(response).build();
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrService.java b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrService.java
index 1ada510a54..91b29cc4d4 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ecr/EcrService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ecr/EcrService.java
@@ -33,6 +33,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
@@ -513,25 +514,37 @@ public class EcrService implements ResourceProvider {
// ListImages / DescribeImages / BatchGetImage / BatchDeleteImage
// ============================================================
- public List listImages(String repositoryName, String registryId, String region) {
+ public PaginatedResult listImages(String repositoryName, String registryId, String region,
+ Integer maxResults, String nextToken) {
+ int limit = maxResults != null ? maxResults : 100;
+ if (limit < 1 || limit > 1000) {
+ throw new AwsException("InvalidParameterException", "maxResults must be between 1 and 1000", 400);
+ }
+ String namespace = "ListImages:" + region + ":" + effectiveAccount(registryId) + ":" + repositoryName;
Repository repo = requireRepo(repositoryName, registryId, region);
requireRegistry();
String internal = resolveRegistryRepoName(repo.getRegistryId(), region, repositoryName);
try {
RegistryHttpClient http = registryManager.httpClient();
- List tags = http.listTags(internal);
- List out = new ArrayList<>();
- for (String tag : tags) {
- String digest = http.headManifestDigest(internal, tag, null);
- out.add(new ImageIdentifier(tag, digest));
- }
- return out;
- } catch (Exception e) {
+ PaginatedResult page = Pagination.paginate(http.listTags(internal), Function.identity(),
+ limit, nextToken, namespace,
+ token -> new AwsException("InvalidParameterException", "Invalid nextToken", 400));
+ return new PaginatedResult<>(imageIdentifiers(http, internal, page.items()), page.nextToken());
+ } catch (IOException | InterruptedException e) {
LOG.warnv("ListImages registry query failed for {0}: {1}", repositoryName, e.getMessage());
- return List.of();
+ return new PaginatedResult<>(List.of(), null);
}
}
+ private static List imageIdentifiers(RegistryHttpClient http, String internal, List tags)
+ throws IOException, InterruptedException {
+ List identifiers = new ArrayList<>();
+ for (String tag : tags) {
+ identifiers.add(new ImageIdentifier(tag, http.headManifestDigest(internal, tag, null)));
+ }
+ return identifiers;
+ }
+
public DescribeImagesResult describeImages(String repositoryName,
List requested,
String registryId,
diff --git a/src/test/java/io/github/hectorvent/floci/services/ecr/EcrListImagesPaginationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrListImagesPaginationIntegrationTest.java
new file mode 100644
index 0000000000..a282290f8e
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/ecr/EcrListImagesPaginationIntegrationTest.java
@@ -0,0 +1,269 @@
+package io.github.hectorvent.floci.services.ecr;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.ecr.model.Repository;
+import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
+import io.github.hectorvent.floci.services.ecr.registry.RegistryHttpClient;
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.InjectMock;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import jakarta.inject.Inject;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+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;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.ecr.EcrClient;
+import software.amazon.awssdk.services.ecr.model.InvalidParameterException;
+import software.amazon.awssdk.services.ecr.model.ListImagesResponse;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+@QuarkusTest
+class EcrListImagesPaginationIntegrationTest {
+
+ private static final String ACCOUNT = "741650100001";
+ private static final Region REGION = Region.EU_CENTRAL_1;
+ private static final String DIGEST = "sha256:" + "a".repeat(64);
+
+ @InjectMock
+ EcrRegistryManager registryManager;
+ @Inject
+ StorageFactory storageFactory;
+ @Inject
+ ObjectMapper mapper;
+
+ private final Map images = new ConcurrentHashMap<>();
+ private final List repositories = new ArrayList<>();
+ private final AtomicInteger manifestHeads = new AtomicInteger();
+ private HttpServer registry;
+ private EcrClient client;
+ private String repository;
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @BeforeEach
+ void setUp() throws IOException {
+ registry = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ registry.createContext("/v2/", this::registryRequest);
+ registry.start();
+ when(registryManager.tryEnsureStarted()).thenReturn(true);
+ when(registryManager.httpClient()).thenReturn(new RegistryHttpClient(
+ "http://127.0.0.1:" + registry.getAddress().getPort()));
+ when(registryManager.internalRepoName(anyString(), anyString(), anyString()))
+ .thenAnswer(call -> call.getArgument(0) + "/" + call.getArgument(1) + "/" + call.getArgument(2));
+ when(registryManager.getRepositoryUri(anyString(), anyString(), anyString()))
+ .thenAnswer(call -> "localhost:4566/" + call.getArgument(2));
+ client = client(REGION);
+ repository = createRepository(client, REGION);
+ }
+
+ @AfterEach
+ void cleanUp() {
+ AccountAwareStorageBackend store = storageFactory.create("ecr", "repositories.json",
+ new TypeReference