mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): paginate code signing configurations (#6832)
* fix(lambda): paginate code signing configurations * fix(lambda): reuse signed service pagination
This commit is contained in:
1 parent
8a19c3024b
commit
3c391a06fb
6 files changed
+210
-8
No files matched your search
+14
-7
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.lambda;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
|
||||
@@ -20,8 +21,8 @@ import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -139,12 +140,17 @@ public class LambdaCodeSigningConfigFunctionsController {
|
||||
@GET
|
||||
@Path("/code-signing-configs")
|
||||
public Response listCodeSigningConfigs(@Context HttpHeaders headers,
|
||||
@QueryParam("Marker") String marker,
|
||||
@Context UriInfo uriInfo,
|
||||
@QueryParam("MaxItems") String maxItems) {
|
||||
parseMaxItems(maxItems);
|
||||
List<CodeSigningConfig> configs = service.list(regionResolver.resolveRegion(headers));
|
||||
int limit = parseMaxItems(maxItems);
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String marker = uriInfo.getQueryParameters().getFirst("Marker");
|
||||
PaginatedResult<CodeSigningConfig> page = service.list(region, limit, marker);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
root.set("CodeSigningConfigs", objectMapper.valueToTree(configs));
|
||||
root.set("CodeSigningConfigs", objectMapper.valueToTree(page.items()));
|
||||
if (page.nextToken() != null) {
|
||||
root.put("NextMarker", page.nextToken());
|
||||
}
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
@@ -185,9 +191,9 @@ public class LambdaCodeSigningConfigFunctionsController {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseMaxItems(String maxItems) {
|
||||
private int parseMaxItems(String maxItems) {
|
||||
if (maxItems == null || maxItems.isBlank()) {
|
||||
return;
|
||||
return MAX_ITEMS_MAX;
|
||||
}
|
||||
int value;
|
||||
try {
|
||||
@@ -202,5 +208,6 @@ public class LambdaCodeSigningConfigFunctionsController {
|
||||
"Value '" + value + "' at 'maxItems' failed to satisfy constraint: "
|
||||
+ "Member must be between " + MAX_ITEMS_MIN + " and " + MAX_ITEMS_MAX, 400);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
+14
-1
@@ -3,6 +3,9 @@ package io.github.hectorvent.floci.services.lambda;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SignedMarkers;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
|
||||
@@ -36,6 +39,7 @@ public class LambdaCodeSigningConfigService {
|
||||
private static final int ID_LENGTH = 17;
|
||||
private static final int MAX_DESCRIPTION = 256;
|
||||
private static final int MAX_SIGNING_PROFILE_ARNS = 20;
|
||||
private static final int LIST_PAGE_SIZE = 10000;
|
||||
|
||||
/** The model documents Warn as the default when the request names no policy. */
|
||||
static final String DEFAULT_UNTRUSTED_ARTIFACT_POLICY = "Warn";
|
||||
@@ -45,10 +49,13 @@ public class LambdaCodeSigningConfigService {
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneOffset.UTC);
|
||||
|
||||
private final StorageBackend<String, CodeSigningConfig> store;
|
||||
private final RegionResolver regionResolver;
|
||||
private final SignedMarkers markers = new SignedMarkers();
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
|
||||
@Inject
|
||||
public LambdaCodeSigningConfigService(StorageFactory storageFactory) {
|
||||
public LambdaCodeSigningConfigService(StorageFactory storageFactory, RegionResolver regionResolver) {
|
||||
this.regionResolver = regionResolver;
|
||||
this.store = storageFactory.create("lambda", "lambda-code-signing-configs.json",
|
||||
new TypeReference<Map<String, CodeSigningConfig>>() {});
|
||||
}
|
||||
@@ -127,6 +134,12 @@ public class LambdaCodeSigningConfigService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public PaginatedResult<CodeSigningConfig> list(String region, int maxItems, String marker) {
|
||||
String scope = regionResolver.getAccountId() + "\n" + region + "\n";
|
||||
return LambdaPagination.paginate(list(region), CodeSigningConfig::getCodeSigningConfigId,
|
||||
maxItems, LIST_PAGE_SIZE, marker, markers, scope);
|
||||
}
|
||||
|
||||
private static AwsException notFound(String arn) {
|
||||
return new AwsException("ResourceNotFoundException",
|
||||
"The code signing configuration " + arn + " does not exist.", 404);
|
||||
|
||||
Reference in new issue
Block a user