Files
floci/src/main/java/io
Ovidiu (Ovi) f99e507916 feat(apigateway): implement GetUsage (#3561)
* feat(apigateway): implement GetUsage

GetUsage had no implementation, so a caller asking a usage plan what it
had consumed hit an unsupported action.

This returns the real envelope with zeroed numbers rather than metering
anything. Shape captured from real API Gateway: an items map of API key id
to one pair per day of the inclusive range, alongside usagePlanId,
startDate and endDate, and no position element when there is no further
page.

The pair is [used, remaining], not [used, quota]. Measured on a live usage
plan, the second element is the quota limit minus cumulative use in the
period: a plan with a 1,000,000 limit reported 999863 after 137 calls, then
999740 after 123 more. Anything reading that element as a quota is reading
it wrong.

Both elements are zero here, deliberately. Nothing counts requests per API
key, and a usage plan carries no quota to subtract from, so there is no
limit to report against. Throttle settings are already accepted and stored
without being enforced, so this is consistent with how the service treats
the rest of that surface. Storing a quota on the usage plan and counting on
the execute path are the two pieces still missing, and both the javadoc and
the service docs say so.

A caller that sums the used counts therefore gets zero, which is what it
already got when the action did not exist, without having to special-case a
missing endpoint.

Validation follows the captured errors: an unknown plan is NotFoundException
and an end date before the start date is BadRequestException, "Usage end
date must be after start date".

* fix(apigateway): paginate GetUsage

GetUsage takes limit and position, which this did not accept at all: every
attached key came back in one response, so the implementation only matched
the single-page case the original capture happened to exercise.

Pagination now runs over the API key entries, defaulting to 25 a page. The
token is the last key id already returned rather than a positional offset,
so a page resumes after a known key and a concurrent key attachment cannot
shift it. No position is emitted on the terminal page, matching the shape
captured from real AWS.

Two edges deliberately differ from real API Gateway, because it is not a
good guide there. It answers limit=0 with an InternalFailure, which is a
fault rather than a contract, so a page size below one is a
BadRequestException here. It also accepts a limit past the documented
maximum of 500, so anything larger is clamped rather than refused. Both
choices are written down in the service docs.

An unrecognised position is a BadRequestException, "Invalid position
parameter", which is the message real API Gateway returns.

The existing tests looked keys up with a dotted GPath. API key ids are
random and can begin with a digit, which Groovy then parses as a number, so
every lookup into items now uses bracket notation. That was luck rather
than correctness before.

* fix(apigateway): stop inventing a GetUsage limit ceiling

The previous head clamped any limit above 500 to 500, extrapolated from a
single observation that 501 was accepted. One accepted value does not
establish a rule.

Probed properly against real API Gateway: 500, 501, 1000, 5000, 100000 and
2147483647 are all accepted without error. The documented maximum is not a
rejection boundary, so no ceiling is imposed here either and the regression
asserts the observed rule across that ladder rather than an emulator
specific clamp.

Whether the service caps the page it actually returns above 500 is not
observable without a usage plan holding more than 500 keys, so nothing is
assumed about it and the docs say as much.

The lower bound stays a deliberate divergence, now with both values
measured: limit=0 and limit=-1 both answer InternalFailure on real API
Gateway. That is a fault rather than a contract, so a page size below one
is a bad request here instead of a reproduced 500.

* fix(apigateway): cap the GetUsage page at 500 while still accepting more

Removing the ceiling entirely went too far the other way. The probe shows
real API Gateway accepts a limit above 500, so rejecting one would be
wrong, but it never showed the service returning more than 500 entries in a
single page, and the documented contract caps a page at 500. Returning more
than 500 was therefore as unevidenced as rejecting the request.

Request acceptance and response page size are now separate: a larger limit
is honoured as a request, and the page stays capped at 500 until a real
result with more than 500 keys shows otherwise.

resolveUsageLimit becomes package-private so the distinction can be
asserted directly rather than needing a usage plan with 500 keys behind it.

* fix(apigateway): return GetUsage key usage under the values wire key

The response serialised the per-key usage map as "items", which is the
SDK-side member name, not the wire key. The Usage shape models that
member with locationName "values", so a real client parsing a body keyed
"items" finds the field absent and reads no usage at all.

Verified with botocore's own rest-json parser against the apigateway
service model: a body keyed "values" populates the member, a body keyed
"items" leaves it None.

Assertions and the service docs move with it. Only GetUsage is affected;
the sibling list actions are a different shape and are untouched.
2026-09-16 09:20:30 -04:00
..