mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(servicequotas): filter ListServiceQuotas by QuotaAppliedAtLevel (#7238)
This commit is contained in:
1 parent
d44e96eab8
commit
be696ff51d
4 files changed
+114
-16
No files matched your search
+6
-3
@@ -53,9 +53,12 @@ public class ServiceQuotasJsonHandler {
|
||||
String quotaCode = stringOrNull(request, "QuotaCode");
|
||||
String nextToken = stringOrNull(request, "NextToken");
|
||||
Integer maxResults = integerOrNull(request, "MaxResults");
|
||||
return Response.ok(awsDefault
|
||||
? service.listAwsDefaultServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)
|
||||
: service.listServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)).build();
|
||||
if (awsDefault) {
|
||||
// ListAWSDefaultServiceQuotas does not have QuotaAppliedAtLevel in the service model
|
||||
return Response.ok(service.listAwsDefaultServiceQuotas(serviceCode, quotaCode, nextToken, maxResults, region, accountId)).build();
|
||||
}
|
||||
String appliedAtLevel = stringOrNull(request, "QuotaAppliedAtLevel");
|
||||
return Response.ok(service.listServiceQuotas(serviceCode, quotaCode, appliedAtLevel, nextToken, maxResults, region, accountId)).build();
|
||||
}
|
||||
|
||||
private Response handleGetServiceQuota(JsonNode request, String region, String accountId, boolean awsDefault) {
|
||||
|
||||
+24
-8
@@ -18,6 +18,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -97,23 +98,35 @@ public class ServiceQuotasService {
|
||||
new TypeReference<Map<String, ObjectNode>>() {});
|
||||
}
|
||||
|
||||
public ObjectNode listServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
|
||||
Integer maxResults, String region, String accountId) {
|
||||
return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, true);
|
||||
public ObjectNode listServiceQuotas(String serviceCode, String quotaCodeFilter, String appliedAtLevel,
|
||||
String nextToken, Integer maxResults, String region, String accountId) {
|
||||
return listQuotas(serviceCode, quotaCodeFilter, appliedAtLevel, nextToken, maxResults, region, accountId, true);
|
||||
}
|
||||
|
||||
public ObjectNode listAwsDefaultServiceQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
|
||||
Integer maxResults, String region, String accountId) {
|
||||
return listQuotas(serviceCode, quotaCodeFilter, nextToken, maxResults, region, accountId, false);
|
||||
return listQuotas(serviceCode, quotaCodeFilter, null, nextToken, maxResults, region, accountId, false);
|
||||
}
|
||||
|
||||
private ObjectNode listQuotas(String serviceCode, String quotaCodeFilter, String nextToken,
|
||||
Integer maxResults, String region, String accountId, boolean applied) {
|
||||
private ObjectNode listQuotas(String serviceCode, String quotaCodeFilter, String appliedAtLevel,
|
||||
String nextToken, Integer maxResults, String region, String accountId, boolean applied) {
|
||||
requireServiceCode(serviceCode);
|
||||
List<QuotaDefinition> quotas = quotasFor(serviceCode);
|
||||
if (quotaCodeFilter != null && !quotaCodeFilter.isEmpty()) {
|
||||
quotas = quotas.stream().filter(q -> q.quotaCode().equals(quotaCodeFilter)).toList();
|
||||
}
|
||||
// Filter by QuotaAppliedAtLevel: ACCOUNT, RESOURCE, or ALL (exact match per AppliedLevelEnum)
|
||||
if (appliedAtLevel != null && !appliedAtLevel.isBlank()) {
|
||||
if (!"ALL".equals(appliedAtLevel) && !"ACCOUNT".equals(appliedAtLevel) && !"RESOURCE".equals(appliedAtLevel)) {
|
||||
throw new AwsException("IllegalArgumentException",
|
||||
"Invalid value for QuotaAppliedAtLevel: " + appliedAtLevel + ". Valid values: ACCOUNT, RESOURCE, ALL.", 400);
|
||||
}
|
||||
if (!"ALL".equals(appliedAtLevel)) {
|
||||
quotas = quotas.stream()
|
||||
.filter(q -> appliedAtLevel.equalsIgnoreCase(q.appliedAtLevel()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Page<QuotaDefinition> page = paginate(quotas, nextToken, maxResults);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
@@ -186,7 +199,7 @@ public class ServiceQuotasService {
|
||||
node.put("Unit", "None");
|
||||
node.put("Adjustable", true);
|
||||
node.put("GlobalQuota", quota.globalQuota());
|
||||
node.put("QuotaAppliedAtLevel", "ACCOUNT");
|
||||
node.put("QuotaAppliedAtLevel", quota.appliedAtLevel());
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -269,7 +282,10 @@ public class ServiceQuotasService {
|
||||
return response;
|
||||
}
|
||||
|
||||
record QuotaDefinition(String quotaCode, String quotaName, double value, boolean globalQuota) {
|
||||
record QuotaDefinition(String quotaCode, String quotaName, double value, boolean globalQuota, String appliedAtLevel) {
|
||||
public QuotaDefinition(String quotaCode, String quotaName, double value, boolean globalQuota) {
|
||||
this(quotaCode, quotaName, value, globalQuota, "ACCOUNT");
|
||||
}
|
||||
}
|
||||
|
||||
private record Page<T>(List<T> items, String nextToken) {
|
||||
|
||||
Reference in new issue
Block a user