feat(servicequotas): add quota request history lookup (#3054)

* feat(servicequotas): add quota request history lookup

* fix(servicequotas): validate history tokens and quota scope
This commit is contained in:
Franklin G. Mendoza authored and GitHub committed 2026-09-05 13:52:22 -04:00
1 parent a31a9599fd
commit 532e27986e
4 files changed
+116 -8

No files matched your search

@@ -33,6 +33,10 @@ public class ServiceQuotasJsonHandler {
case "GetAWSDefaultServiceQuota" -> handleGetServiceQuota(request, region, accountId);
case "ListAWSDefaultServiceQuotas" -> handleListServiceQuotas(request, region, accountId);
case "RequestServiceQuotaIncrease" -> handleRequestServiceQuotaIncrease(request, region, accountId);
case "ListRequestedServiceQuotaChangeHistoryByQuota" ->
Response.ok(service.listRequestedServiceQuotaChangeHistoryByQuota(
stringOrNull(request, "ServiceCode"), stringOrNull(request, "QuotaCode"),
stringOrNull(request, "NextToken"), integerOrNull(request, "MaxResults"))).build();
default -> Response.status(400)
.entity(new AwsErrorResponse("UnknownOperationException",
"Unknown operation: ServiceQuotasV20190624." + action))
@@ -54,9 +54,11 @@ public class ServiceQuotasService {
private static final Map<String, List<QuotaDefinition>> CURATED_QUOTAS = Map.of(
"codebuild", List.of(
new QuotaDefinition("L-2DC20C30", "Concurrently running builds", GENERIC_QUOTA_VALUE)),
new QuotaDefinition("L-2DC20C30", "Concurrently running builds", GENERIC_QUOTA_VALUE, false)),
"lambda", List.of(
new QuotaDefinition("L-B99A9384", "Concurrent executions", GENERIC_QUOTA_VALUE)));
new QuotaDefinition("L-B99A9384", "Concurrent executions", GENERIC_QUOTA_VALUE, false)),
"organizations", List.of(
new QuotaDefinition("L-E619E033", "Maximum number of accounts", 50.0, true)));
private static final List<String> GENERIC_QUOTA_NAMES = List.of(
"Resources per Region",
@@ -109,7 +111,9 @@ public class ServiceQuotasService {
List<QuotaDefinition> quotasFor(String serviceCode) {
List<QuotaDefinition> quotas = new ArrayList<>(CURATED_QUOTAS.getOrDefault(serviceCode, List.of()));
for (String name : GENERIC_QUOTA_NAMES) {
quotas.add(new QuotaDefinition(syntheticQuotaCode(serviceCode, name), name, GENERIC_QUOTA_VALUE));
quotas.add(new QuotaDefinition(
syntheticQuotaCode(serviceCode, name), name, GENERIC_QUOTA_VALUE,
"organizations".equals(serviceCode)));
}
return quotas;
}
@@ -135,7 +139,7 @@ public class ServiceQuotasService {
node.put("Value", quota.value());
node.put("Unit", "None");
node.put("Adjustable", true);
node.put("GlobalQuota", false);
node.put("GlobalQuota", quota.globalQuota());
node.put("QuotaAppliedAtLevel", "ACCOUNT");
return node;
}
@@ -190,7 +194,29 @@ public class ServiceQuotasService {
}
}
record QuotaDefinition(String quotaCode, String quotaName, double value) {
public ObjectNode listRequestedServiceQuotaChangeHistoryByQuota(String serviceCode, String quotaCode,
String nextToken, Integer maxResults) {
requireServiceCode(serviceCode);
if (quotaCode == null || quotaCode.isBlank()) {
throw new AwsException("IllegalArgumentException", "Invalid input: QuotaCode must not be empty.", 400);
}
boolean exists = quotasFor(serviceCode).stream().anyMatch(quota -> quota.quotaCode().equals(quotaCode));
if (!exists) {
throw new AwsException("NoSuchResourceException",
"The request failed because the specified service quota does not exist.", 400);
}
if (maxResults != null && (maxResults < 1 || maxResults > 100)) {
throw new AwsException("IllegalArgumentException", "Invalid input: MaxResults must be between 1 and 100.", 400);
}
if (nextToken != null && !nextToken.isEmpty()) {
throw new AwsException("InvalidPaginationTokenException", "Invalid NextToken.", 400);
}
ObjectNode response = objectMapper.createObjectNode();
response.putArray("RequestedQuotas");
return response;
}
record QuotaDefinition(String quotaCode, String quotaName, double value, boolean globalQuota) {
}
private record Page(List<QuotaDefinition> items, String nextToken) {
@@ -235,7 +261,7 @@ public class ServiceQuotasService {
requestedQuota.put("Status", "PENDING");
requestedQuota.put("Requester", "floci-emulator");
requestedQuota.put("Unit", "None");
requestedQuota.put("GlobalQuota", false);
requestedQuota.put("GlobalQuota", quota.globalQuota());
requestedQuota.put("QuotaRequestedAtLevel", "ACCOUNT");
requestedQuota.put("Created", now);
requestedQuota.put("LastUpdated", now);