feat(kms): add RotateKeyOnDemand support (#990)

This commit is contained in:
kyounghoonJang authored and GitHub committed 2026-05-24 14:34:51 -05:00
1 parent 8fb07d2654
commit 255b41bca8
5 files changed
+73

No files matched your search

@@ -60,6 +60,7 @@ public class KmsJsonHandler {
case "GetKeyRotationStatus" -> handleGetKeyRotationStatus(request, region);
case "EnableKeyRotation" -> handleEnableKeyRotation(request, region);
case "DisableKeyRotation" -> handleDisableKeyRotation(request, region);
case "RotateKeyOnDemand" -> handleRotateKeyOnDemand(request, region);
default -> Response.status(400)
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
.build();
@@ -383,6 +384,13 @@ public class KmsJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleRotateKeyOnDemand(JsonNode request, String region) {
String keyId = service.rotateKeyOnDemand(request.path("KeyId").asText(), region);
ObjectNode response = objectMapper.createObjectNode();
response.put("KeyId", keyId);
return Response.ok(response).build();
}
private ObjectNode keyToNode(KmsKey k) {
ObjectNode node = objectMapper.createObjectNode();
node.put("AWSAccountId", regionResolver.getAccountId());
@@ -290,6 +290,16 @@ public class KmsService {
LOG.infov("Disabled key rotation for KMS key: {0} in {1}", key.getKeyId(), region);
}
public String rotateKeyOnDemand(String keyId, String region) {
KmsKey key = resolveKey(keyId, region);
if (!key.isEnabled()) {
throw new AwsException("DisabledException",
"KMS key " + key.getKeyId() + " is disabled.", 400);
}
validateRotationSupported(key);
return key.getKeyId();
}
private void validateRotationSupported(KmsKey key) {
if (!"ENCRYPT_DECRYPT".equals(key.getKeyUsage())
|| !"SYMMETRIC_DEFAULT".equals(key.getCustomerMasterKeySpec())) {