mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
feat(kms): implement ListKeyPolicies (#2046)
* feat(kms): implement ListKeyPolicies
ListKeyPolicies failed with UnsupportedOperation, so clients enumerating
policy names before a GetKeyPolicy call could not proceed. GetKeyPolicy
and PutKeyPolicy were already supported, so this was a hole in an
otherwise complete area.
Returns the single `default` policy name, which is what the model
prescribes ("The only valid value is default"), with Truncated false and
NextMarker omitted rather than serialized as null, since AWS only emits
NextMarker when Truncated is true.
Limit and Marker are accepted and ignored. One policy name cannot be
paginated, and ListKeyPolicies is the one KMS list operation that does
not declare InvalidMarkerException, unlike ListKeys, ListAliases,
ListGrants, ListKeyRotations, ListResourceTags, ListRetirableGrants and
DescribeCustomKeyStores. There is therefore no marker it could
legitimately reject, and no undeclared error code is invented for one.
Closes #1528
Co-authored-by: Marcel Herhold <herhold.marcel@gmail.com>
* chore: drop hand-written ListKeyPolicies changelog entry (semantic-release owns CHANGELOG.md)
* fix(kms): drop unused ListKeyPolicies pagination params and fix test claims
Review follow-up, validated against the local AWS references: Limit/Marker are
accepted at the wire by never being read (matching moto's list_key_policies), so
the service signature drops the dead parameters and the structurally vacuous
paging unit test goes with them; the integration test remains the real coverage.
The javadoc justification now states the leniency honestly: SDKs do not fully
enforce LimitType [1..1000] client-side (botocore validates only the minimum),
so out-of-range values can arrive and are deliberately tolerated. The ARN
resolution test no longer claims alias coverage the operation does not have.
---------
Signed-off-by: Hector Ventura <hectorvent@gmail.com>
Co-authored-by: Marcel Herhold <herhold.marcel@gmail.com>
This commit is contained in:
1 parent
cc6e96de69
commit
760115db14
5 files changed
+142
No files matched your search
@@ -67,6 +67,7 @@ public class KmsJsonHandler {
|
||||
case "ListResourceTags" -> handleListResourceTags(request, region);
|
||||
case "GetKeyPolicy" -> handleGetKeyPolicy(request, region);
|
||||
case "PutKeyPolicy" -> handlePutKeyPolicy(request, region);
|
||||
case "ListKeyPolicies" -> handleListKeyPolicies(request, region);
|
||||
case "UpdateKeyDescription" -> handleUpdateKeyDescription(request, region);
|
||||
case "GetKeyRotationStatus" -> handleGetKeyRotationStatus(request, region);
|
||||
case "EnableKeyRotation" -> handleEnableKeyRotation(request, region);
|
||||
@@ -474,6 +475,14 @@ public class KmsJsonHandler {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response handleListKeyPolicies(JsonNode request, String region) {
|
||||
// Limit and Marker are accepted by simply not being read; see the service javadoc.
|
||||
Map<String, Object> result = service.listKeyPolicies(
|
||||
requiredText(request, "KeyId"),
|
||||
region);
|
||||
return Response.ok(objectMapper.valueToTree(result)).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateKeyDescription(JsonNode request, String region) {
|
||||
service.updateKeyDescription(
|
||||
request.path("KeyId").asText(),
|
||||
|
||||
@@ -489,6 +489,27 @@ public class KmsService {
|
||||
LOG.infov("Updated key policy for KMS key: {0} in {1}", key.getKeyId(), region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the policy names attached to a key. KMS supports exactly one key policy, named
|
||||
* {@code default}, so the result can never be truncated: {@code Truncated} is always false and
|
||||
* {@code NextMarker} is omitted.
|
||||
*
|
||||
* <p>{@code Limit} and {@code Marker} are accepted at the wire and ignored: the handler simply
|
||||
* never reads them, which is exactly what moto's KMS does for this operation. A single policy
|
||||
* name fits inside any limit, so the values cannot change the response. Real AWS rejects an
|
||||
* out-of-range {@code Limit} server-side (the model bounds LimitType to [1..1000], but SDKs do
|
||||
* not fully enforce that client-side — botocore checks only the minimum); not re-validating it
|
||||
* here is deliberate leniency, consistent with the emulator's general posture.
|
||||
*/
|
||||
public Map<String, Object> listKeyPolicies(String keyId, String region) {
|
||||
String policyName = (String) getKeyPolicy(keyId, region).get("PolicyName");
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("PolicyNames", List.of(policyName));
|
||||
result.put("Truncated", false);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateKeyDescription(String keyId, String description, String region) {
|
||||
KmsKey key = resolveKey(keyId, region);
|
||||
key.setDescription(description);
|
||||
|
||||
Reference in new issue
Block a user