1

I have an OpenStack cloud connected to LDAP (of which I have no control and doesn't return the matching case when I query) where Keystone has the user as 'UserNaMe' and if I search for a user with this code, the id is returned:

conn = openstack.connect(cloud)
pprint(conn.identity.find_user('UserNaMe'))

However, if I search for a username without the proper case, no id is returned:

pprint(conn.identity.find_user('username'))

Since the https://docs.openstack.org/openstacksdk/latest/user/proxies/identity_v3.html#user-operations documentation is not specific, how do I make the search case insensitive so that I always get the correct user id?

Horizon seems to have no issue with 'username' instead of 'UserNaMe', so there must be a way to search insensitively.

reukiodo
  • 740
  • 6
  • 12

1 Answers1

1

One option would be to inspect the Horizon source and see how it handles the user search.

Another option would be to iterate over the list of users and perform case-insensitive comparisons. E.g.:

want_user = 'UserNaMe'

found_user = [user for user in conn.identity.users()
              if user.name.lower() == want_user.lower()]
larsks
  • 277,717
  • 41
  • 399
  • 399
  • While not the ideal solution, this works around the issue well enough to unblock. A slight improvement would be to use casefold() instead of lower() for reasons shown in https://stackoverflow.com/questions/319426/how-do-i-do-a-case-insensitive-string-comparison question. Since the find_user function returns the id of the user, it would not be difficult to modify this sample code to do similar. – reukiodo Nov 14 '20 at 00:36