fix(apigateway): filter GetUsagePlans by keyId (#7655)

This commit is contained in:
Mario Toffia authored and GitHub committed 2026-11-07 09:52:39 -04:00
1 parent 062389b370
commit 413f490d8c
4 files changed
+61 -4

No files matched your search

@@ -895,9 +895,9 @@ public class ApiGatewayController {
@GET
@Path("/usageplans")
public Response getUsagePlans(@Context HttpHeaders headers) {
public Response getUsagePlans(@Context HttpHeaders headers, @QueryParam("keyId") String keyId) {
String region = regionResolver.resolveRegion(headers);
List<UsagePlan> plans = service.getUsagePlans(region);
List<UsagePlan> plans = service.getUsagePlans(region, keyId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("item");
plans.forEach(p -> items.add(toUsagePlanNode(p, false)));
@@ -1639,6 +1639,21 @@ public class ApiGatewayService implements ResourceProvider {
return usagePlanStore.scan(k -> k.startsWith(prefix));
}
/**
* {@code GetUsagePlans} with its {@code keyId} filter, measured on API Gateway: only the plans
* the key is added to, an empty list for a key in no plan or no key at all, and every plan for a
* blank {@code keyId}.
*/
public List<UsagePlan> getUsagePlans(String region, String keyId) {
List<UsagePlan> plans = getUsagePlans(region);
if (keyId == null || keyId.isBlank()) {
return plans;
}
return plans.stream()
.filter(plan -> usagePlanKeyStore.get(usagePlanKeyPathKey(region, plan.getId(), keyId)).isPresent())
.toList();
}
public void deleteUsagePlan(String region, String usagePlanId) {
synchronized (usagePlanLock) {
getUsagePlan(region, usagePlanId);