Skip to content

Commit e565cc2

Browse files
committed
Cosmetic: Use plural in fn name. More SDK explanation.
Improve comment explaining the SDK (and possibly API) misbehavior. Also add comment on chosen workaround with robustness in mind, but without taking it to the extreme of adding 5 additional API calls. Signed-off-by: Kurt Garloff <[email protected]>
1 parent 57a5192 commit e565cc2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Tests/iaas/key-manager/check-for-key-manager.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ def check_presence_of_key_manager(conn: openstack.connection.Connection) -> None
5757
return True
5858

5959

60-
def _find_secret(conn: openstack.connection.Connection, secret_name_or_id: str):
60+
def _find_secrets(conn: openstack.connection.Connection, secret_name_or_id: str):
6161
"""Replacement method for finding secrets.
6262
6363
Mimicks the behavior of Connection.key_manager.find_secret()
6464
but fixes an issue with the internal implementation raising an
6565
exception due to an unexpected microversion parameter.
66+
Unlike find_secret(), we return a list with all secrets that match.
6667
"""
6768
secrets = conn.key_manager.secrets()
6869
return [s for s in secrets if s.name == secret_name_or_id or s.id == secret_name_or_id]
@@ -76,13 +77,22 @@ def check_key_manager_permissions(conn: openstack.connection.Connection) -> None
7677
"""
7778
secret_name = "scs-member-role-test-secret"
7879
try:
79-
existing_secrets = _find_secret(conn, secret_name)
80+
existing_secrets = _find_secrets(conn, secret_name)
8081
for secret in existing_secrets:
8182
# Workaround for SDK bugs:
8283
# - The id field in reality is a href (containg the UUID at the end)
8384
# - The delete_secret() function contrary to the documentation does
8485
# not accept openstack.key_managerv1.secret.Secret objects nor the
8586
# hrefs, just plain UUIDs.
87+
# - It does not return an error when I try to delete a secret passing
88+
# an object or href, just silently does nothing.
89+
# The code here assumes that the SDK (when fixed) will continue to
90+
# accept UUIDs as argument for delete_secret() in the future.
91+
# Code is robust against those being passed directly in the .id attr
92+
# of the objects. (It would be even more robust to try to pass the
93+
# object first, then the href, then the UUID extracted from the href,
94+
# each time checking whether it was effective. But that's three delete
95+
# plus list calls and very ugly.)
8696
uuid_part = secret.id.rfind('/') + 1
8797
if uuid_part != 0:
8898
conn.key_manager.delete_secret(secret.id[uuid_part:])

0 commit comments

Comments
 (0)