mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ec2): delete key pairs by name through the storage backend (#2187)
DeleteKeyPair with KeyName mutated the detached list returned by StorageBackend.scan, which is documented not to affect the store — so the call reported success while leaving the key pair in place. Resolve matching key pairs to their store key and delete through the backend instead. The only existing DeleteKeyPair test passed KeyPairId, the branch that already worked, and asserted just a 200; DeleteKeyPair always returns true, so the no-op was invisible. Cover the by-name path and assert removal rather than status. Closes #2185
This commit is contained in:
1 parent
4215006fe2
commit
fc74987bd3
3 files changed
+117
-1
No files matched your search
@@ -1830,7 +1830,13 @@ public class Ec2Service implements ContainerTeardown {
|
||||
if (keyPairId != null && !keyPairId.isEmpty()) {
|
||||
keyPairs.delete(key(region, keyPairId));
|
||||
} else {
|
||||
keyPairs.scan(k -> true).removeIf(k -> k.getRegion().equals(region) && k.getKeyName().equals(keyName));
|
||||
// scan() returns a detached copy, so the key pair has to be resolved to its
|
||||
// store key and deleted through the backend — mutating the scan result does
|
||||
// not touch the store.
|
||||
keyPairs.scan(k -> true).stream()
|
||||
.filter(k -> k.getRegion().equals(region) && k.getKeyName().equals(keyName))
|
||||
.map(KeyPair::getKeyPairId)
|
||||
.forEach(id -> keyPairs.delete(key(region, id)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user