mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 18:48:00 -05:00
feat(servicequotas): implement ListServices action (#7254)
This commit is contained in:
1 parent
fab3e7b923
commit
e95af9cbf6
6 files changed
+205
-3
No files matched your search
+16
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.servicequotas;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
@@ -41,6 +42,7 @@ public class ServiceQuotasJsonHandler {
|
||||
stringOrNull(request, "ServiceCode"), stringOrNull(request, "QuotaCode"),
|
||||
stringOrNull(request, "NextToken"), integerOrNull(request, "MaxResults"),
|
||||
region)).build();
|
||||
case "ListServices" -> handleListServices(request, region, accountId);
|
||||
default -> Response.status(400)
|
||||
.entity(new AwsErrorResponse("UnknownOperationException",
|
||||
"Unknown operation: ServiceQuotasV20190624." + action))
|
||||
@@ -48,6 +50,12 @@ public class ServiceQuotasJsonHandler {
|
||||
};
|
||||
}
|
||||
|
||||
private Response handleListServices(JsonNode request, String region, String accountId) {
|
||||
String nextToken = stringOrNull(request, "NextToken");
|
||||
Integer maxResults = integerOrNull(request, "MaxResults");
|
||||
return Response.ok(service.listServices(nextToken, maxResults)).build();
|
||||
}
|
||||
|
||||
private Response handleListServiceQuotas(JsonNode request, String region, String accountId, boolean awsDefault) {
|
||||
String serviceCode = stringOrNull(request, "ServiceCode");
|
||||
String quotaCode = stringOrNull(request, "QuotaCode");
|
||||
@@ -76,7 +84,14 @@ public class ServiceQuotasJsonHandler {
|
||||
|
||||
private static Integer integerOrNull(JsonNode node, String field) {
|
||||
JsonNode value = node == null ? null : node.get(field);
|
||||
return (value != null && value.isNumber()) ? value.asInt() : null;
|
||||
if (value == null || value.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!value.isInt()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"1 validation error detected: Value '" + value.asText() + "' at 'maxResults' failed to satisfy constraint: Member must be an integer.", 400);
|
||||
}
|
||||
return value.asInt();
|
||||
}
|
||||
|
||||
private Response handleRequestServiceQuotaIncrease(JsonNode request, String region, String accountId) {
|
||||
|
||||
+23
-1
@@ -108,6 +108,25 @@ public class ServiceQuotasService {
|
||||
return listQuotas(serviceCode, quotaCodeFilter, null, nextToken, maxResults, region, accountId, false);
|
||||
}
|
||||
|
||||
public ObjectNode listServices(String nextToken, Integer maxResults) {
|
||||
List<String> serviceCodes = new ArrayList<>(SERVICE_NAMES.keySet());
|
||||
serviceCodes.sort(String::compareToIgnoreCase);
|
||||
Page<String> page = paginate(serviceCodes, nextToken, maxResults);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("Services");
|
||||
for (String code : page.items()) {
|
||||
ObjectNode service = objectMapper.createObjectNode();
|
||||
service.put("ServiceCode", code);
|
||||
service.put("ServiceName", SERVICE_NAMES.getOrDefault(code, code));
|
||||
array.add(service);
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("NextToken", page.nextToken());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private ObjectNode listQuotas(String serviceCode, String quotaCodeFilter, String appliedAtLevel,
|
||||
String nextToken, Integer maxResults, String region, String accountId, boolean applied) {
|
||||
requireServiceCode(serviceCode);
|
||||
@@ -241,9 +260,12 @@ public class ServiceQuotasService {
|
||||
}
|
||||
|
||||
private static int decodeToken(String token) {
|
||||
if (token == null || token.isEmpty()) {
|
||||
if (token == null) {
|
||||
return 0;
|
||||
}
|
||||
if (token.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(Base64Url.decode(token));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
Reference in new issue
Block a user