From 8f10fe5f0af55e863b6ea22772d554a0733342c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Alet?= <32936891+aurelien-alet@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:14:10 +0200 Subject: [PATCH] fix: improve KeycloakAdmin.get_client_id() performances (#511) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aurélien Alet --- src/keycloak/keycloak_admin.py | 8 ++++++-- src/keycloak/urls_patterns.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index d3b85d0..ea27b24 100644 --- a/src/keycloak/keycloak_admin.py +++ b/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"] diff --git a/src/keycloak/urls_patterns.py b/src/keycloak/urls_patterns.py index 0531bd8..b40bcef 100644 --- a/src/keycloak/urls_patterns.py +++ b/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"