diff --git a/docs/services/service-catalog.md b/docs/services/service-catalog.md
index f12f0301cc..1f1b9da2fa 100644
--- a/docs/services/service-catalog.md
+++ b/docs/services/service-catalog.md
@@ -8,6 +8,14 @@ resource associations, provisioned products, and organization/account portfolio
Portfolio-share operations complete immediately while preserving the AWS status-token
workflow.
+`ListPortfolios` supports `PageSize` from 0 to 100 and opaque `PageToken` /
+`NextPageToken` cursors. Floci uses 100 items when the size is omitted or zero;
+this is an emulator default, since AWS does not document those cases. Tokens
+are scoped to the action, account, and request region and may be resumed with a
+different page size. Final pages omit `NextPageToken`. Invalid sizes, malformed
+tokens, and tokens longer than 2024 characters return `InvalidParametersException`.
+The existing seeded Control Tower portfolio participates in pagination.
+
## Supported Actions
diff --git a/pom.xml b/pom.xml
index 8a00e94370..fc6aea2dcd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -408,6 +408,12 @@
${aws.sdk.version}
test
+
+ software.amazon.awssdk
+ servicecatalog
+ ${aws.sdk.version}
+ test
+
software.amazon.awssdk
redshift
diff --git a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java
index 62c1c27d11..0fdce52aa5 100644
--- a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java
@@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
@@ -33,7 +35,7 @@ public class ServiceCatalogJsonHandler {
case "CreatePortfolio" -> portfolioResponse(service.createPortfolio(request, region, accountId));
case "UpdatePortfolio" -> portfolioResponse(service.updatePortfolio(text(request, "Id"), request));
case "DescribePortfolio" -> portfolioResponse(service.describePortfolio(text(request, "Id")));
- case "ListPortfolios" -> listPortfolios(region, accountId);
+ case "ListPortfolios" -> listPortfolios(request, region, accountId);
case "DeletePortfolio" -> empty(() -> service.deletePortfolio(text(request, "Id")));
case "CreateProduct" -> productResponse(service.createProduct(request, region, accountId));
case "UpdateProduct" -> productResponse(service.updateProduct(text(request, "Id"), request));
@@ -144,6 +146,24 @@ public class ServiceCatalogJsonHandler {
}
}
+ private Response listPortfolios(JsonNode request, String region, String accountId) {
+ Integer pageSize = Pagination.parseMaxResults(request, "PageSize", "InvalidParametersException");
+ if (pageSize != null && pageSize == 0) {
+ pageSize = null;
+ }
+ String pageToken = Pagination.parseNextToken(request, "PageToken", "InvalidParametersException");
+ PaginatedResult page = Pagination.paginate(service.listPortfolios(region, accountId),
+ item -> text(item, "Id"), pageSize, pageToken, 100, 100, 2024, "InvalidParametersException",
+ "ListPortfolios:" + accountId + ":" + region);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("PortfolioDetails");
+ page.items().forEach(details::add);
+ if (page.nextToken() != null) {
+ response.put("NextPageToken", page.nextToken());
+ }
+ return Response.ok(response).build();
+ }
+
private Response listPortfolios(String region, String accountId) {
ObjectNode response = objectMapper.createObjectNode();
ArrayNode details = response.putArray("PortfolioDetails");
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioPaginationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioPaginationIntegrationTest.java
new file mode 100644
index 0000000000..acfaed0c88
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioPaginationIntegrationTest.java
@@ -0,0 +1,211 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.common.http.TestHTTPResource;
+import io.quarkus.test.junit.QuarkusTest;
+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.awscore.exception.AwsServiceException;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.servicecatalog.ServiceCatalogClient;
+import software.amazon.awssdk.services.servicecatalog.model.ListPortfoliosResponse;
+import software.amazon.awssdk.services.servicecatalog.model.PortfolioDetail;
+
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Map;
+
+import static io.restassured.RestAssured.given;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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;
+
+@QuarkusTest
+class ServiceCatalogPortfolioPaginationIntegrationTest {
+
+ private static final String ACCOUNT = "741660500001";
+ private static final String OTHER_ACCOUNT = "741660500002";
+ private static final Region REGION = Region.US_EAST_1;
+
+ @Inject
+ StorageFactory storageFactory;
+
+ @Inject
+ ObjectMapper objectMapper;
+
+ @TestHTTPResource
+ URI endpoint;
+
+ private final List> stores = new ArrayList<>();
+ private ServiceCatalogClient client;
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @BeforeEach
+ void setUp() {
+ for (String name : List.of("portfolios", "products", "associations")) {
+ stores.add(storageFactory.create("servicecatalog", "servicecatalog-" + name + ".json",
+ new TypeReference