mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(kms): support KeyId filter on ListAliases (#1651)
* feat(kms): support KeyId filter on ListAliases * feat(kms): avoid null key ids in handler
This commit is contained in:
1 parent
af0ec51f98
commit
cd7370c730
3 files changed
+59
-2
No files matched your search
@@ -384,7 +384,9 @@ public class KmsJsonHandler {
|
||||
}
|
||||
|
||||
private Response handleListAliases(JsonNode request, String region) {
|
||||
List<KmsAlias> aliases = service.listAliases(region);
|
||||
JsonNode keyIdNode = request.path("KeyId");
|
||||
String keyId = (keyIdNode.isMissingNode() || keyIdNode.isNull()) ? null : keyIdNode.asText();
|
||||
List<KmsAlias> aliases = service.listAliases(keyId, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = response.putArray("Aliases");
|
||||
for (KmsAlias a : aliases) {
|
||||
|
||||
@@ -593,8 +593,19 @@ public class KmsService {
|
||||
}
|
||||
|
||||
public List<KmsAlias> listAliases(String region) {
|
||||
return listAliases(null, region);
|
||||
}
|
||||
|
||||
public List<KmsAlias> listAliases(String keyId, String region) {
|
||||
String prefix = region + "::";
|
||||
return aliasStore.scan(k -> k.startsWith(prefix));
|
||||
List<KmsAlias> all = aliasStore.scan(k -> k.startsWith(prefix));
|
||||
if (keyId == null || keyId.isBlank()) {
|
||||
return all;
|
||||
}
|
||||
KmsKey key = resolveKey(keyId, region);
|
||||
return all.stream()
|
||||
.filter(a -> key.getKeyId().equals(a.getTargetKeyId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Crypto Ops (Mocks) ────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user