Browse Source

feat: add an optional search criteria to the get_realm_roles function

pull/277/head
Salem Wafi 1 year ago
parent
commit
5114c3e28a
No known key found for this signature in database GPG Key ID: 6451BA63EAE5EFC8
  1. 13
      src/keycloak/keycloak_admin.py

13
src/keycloak/keycloak_admin.py

@ -2147,7 +2147,7 @@ class KeycloakAdmin:
) )
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[200]) return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[200])
def get_realm_roles(self, brief_representation=True):
def get_realm_roles(self, brief_representation=True, search_text=""):
"""Get all roles for the realm or client. """Get all roles for the realm or client.
RoleRepresentation RoleRepresentation
@ -2155,13 +2155,22 @@ class KeycloakAdmin:
:param brief_representation: whether to omit role attributes in the response :param brief_representation: whether to omit role attributes in the response
:type brief_representation: bool :type brief_representation: bool
:param search_text: optional search text to limit the returned result.
:type search_text: str
:return: Keycloak server response (RoleRepresentation) :return: Keycloak server response (RoleRepresentation)
:rtype: list :rtype: list
""" """
url = urls_patterns.URL_ADMIN_REALM_ROLES
params_path = {"realm-name": self.connection.realm_name} params_path = {"realm-name": self.connection.realm_name}
params = {"briefRepresentation": brief_representation} params = {"briefRepresentation": brief_representation}
# set the search_text path param, if it is a valid string
if search_text is not None and search_text.strip() != '':
params_path["search-text"] = search_text
url = urls_patterns.URL_ADMIN_REALM_ROLES_SEARCH
data_raw = self.connection.raw_get( data_raw = self.connection.raw_get(
urls_patterns.URL_ADMIN_REALM_ROLES.format(**params_path), **params
url.format(**params_path), **params
) )
return raise_error_from_response(data_raw, KeycloakGetError) return raise_error_from_response(data_raw, KeycloakGetError)

Loading…
Cancel
Save