Browse Source

fix: improve KeycloakAdmin.get_client_id() performances (#511)

Co-authored-by: Aurélien Alet <aurelien.alet@cdbdx.biz>
pull/545/head v3.10.1
Aurélien Alet 9 months ago
committed by GitHub
parent
commit
8f10fe5f0a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      src/keycloak/keycloak_admin.py
  2. 1
      src/keycloak/urls_patterns.py

8
src/keycloak/keycloak_admin.py

@ -1580,9 +1580,13 @@ class KeycloakAdmin:
:return: client_id (uuid as string)
:rtype: str
"""
clients = self.get_clients()
params_path = {"realm-name": self.connection.realm_name, "client-id": client_id}
data_raw = self.connection.raw_get(
urls_patterns.URL_ADMIN_CLIENTS_CLIENT_ID.format(**params_path)
)
data_response = raise_error_from_response(data_raw, KeycloakGetError)
for client in clients:
for client in data_response:
if client_id == client.get("clientId"):
return client["id"]

1
src/keycloak/urls_patterns.py

@ -90,6 +90,7 @@ URL_ADMIN_GROUP_MEMBERS = "admin/realms/{realm-name}/groups/{id}/members"
URL_ADMIN_CLIENT_INITIAL_ACCESS = "admin/realms/{realm-name}/clients-initial-access"
URL_ADMIN_CLIENTS = "admin/realms/{realm-name}/clients"
URL_ADMIN_CLIENT = URL_ADMIN_CLIENTS + "/{id}"
URL_ADMIN_CLIENTS_CLIENT_ID = URL_ADMIN_CLIENTS + "?clientId={client-id}"
URL_ADMIN_CLIENT_ALL_SESSIONS = URL_ADMIN_CLIENT + "/user-sessions"
URL_ADMIN_CLIENT_SECRETS = URL_ADMIN_CLIENT + "/client-secret"
URL_ADMIN_CLIENT_ROLES = URL_ADMIN_CLIENT + "/roles"

Loading…
Cancel
Save