mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(backup): paginate ListBackupVaults (#6541)
This commit is contained in:
1 parent
5fbc51f537
commit
13d0452a20
5 files changed
+288
-4
No files matched your search
@@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
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 io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.backup.model.*;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -103,12 +105,18 @@ public class BackupController {
|
||||
@GET
|
||||
@Path("/backup-vaults/")
|
||||
public Response listBackupVaults(@Context HttpHeaders headers,
|
||||
@QueryParam("vaultType") String byVaultType) {
|
||||
@QueryParam("vaultType") String byVaultType,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<BackupVault> vaults = service.listBackupVaults(region, byVaultType);
|
||||
PaginatedResult<BackupVault> page = service.listBackupVaults(region, byVaultType,
|
||||
Pagination.parseMaxResults(maxResults, "InvalidParameterValueException"), nextToken);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
ArrayNode list = out.putArray("BackupVaultList");
|
||||
vaults.forEach(v -> list.add(vaultJson(v)));
|
||||
page.items().forEach(v -> list.add(vaultJson(v)));
|
||||
if (page.nextToken() != null) {
|
||||
out.put("NextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(out).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
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 io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
@@ -279,6 +281,18 @@ public class BackupService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public PaginatedResult<BackupVault> listBackupVaults(String region, String byVaultType,
|
||||
Integer maxResults, String nextToken) {
|
||||
if (maxResults != null && (maxResults < 1 || maxResults > 1000)) {
|
||||
throw new AwsException("InvalidParameterValueException", "maxResults must be between 1 and 1000", 400);
|
||||
}
|
||||
String namespace = "backup:ListBackupVaults:" + regionResolver.getAccountId() + ":" + region + ":"
|
||||
+ (byVaultType == null ? "all" : "type:" + byVaultType);
|
||||
return Pagination.paginate(listBackupVaults(region, byVaultType), BackupVault::getBackupVaultName,
|
||||
maxResults == null ? 1000 : maxResults, nextToken, namespace,
|
||||
token -> new AwsException("InvalidParameterValueException", "Invalid nextToken.", 400));
|
||||
}
|
||||
|
||||
private static void requireNotAirGapped(BackupVault vault, String action) {
|
||||
if (vault.getVaultType() != null) {
|
||||
throw new AwsException("InvalidRequestException",
|
||||
|
||||
Reference in new issue
Block a user