fix KeyError in delete_alias in the KmsBackend. (#1359)
* fix KeyError in delete_alias in the KmsBackend. If there're several aliases in the backend, previously we will bump into a KeyError here. Signed-off-by: Kai Xia <xiaket@gmail.com> * add doc to make travis try one more time. Signed-off-by: Kai Xia <xiaket@gmail.com> a * add another key and alias before the deletion of an alias. This was done to make sure that we can correctly handle the deletion when there are more than one alias defined. Signed-off-by: Kai Xia <xiaket@gmail.com>
This commit is contained in:
parent
d5ee48eedd
commit
9e1a233549
@ -103,8 +103,10 @@ class KmsBackend(BaseBackend):
|
||||
self.key_to_aliases[target_key_id].add(alias_name)
|
||||
|
||||
def delete_alias(self, alias_name):
|
||||
"""Delete the alias."""
|
||||
for aliases in self.key_to_aliases.values():
|
||||
aliases.remove(alias_name)
|
||||
if alias_name in aliases:
|
||||
aliases.remove(alias_name)
|
||||
|
||||
def get_all_aliases(self):
|
||||
return self.key_to_aliases
|
||||
|
@ -491,7 +491,14 @@ def test__delete_alias():
|
||||
key_id = create_resp['KeyMetadata']['KeyId']
|
||||
alias = 'alias/my-alias'
|
||||
|
||||
# added another alias here to make sure that the deletion of the alias can
|
||||
# be done when there are multiple existing aliases.
|
||||
another_create_resp = kms.create_key()
|
||||
another_key_id = create_resp['KeyMetadata']['KeyId']
|
||||
another_alias = 'alias/another-alias'
|
||||
|
||||
kms.create_alias(alias, key_id)
|
||||
kms.create_alias(another_alias, another_key_id)
|
||||
|
||||
resp = kms.delete_alias(alias)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user