From 30e489affd05291843841fe45d10f81fdc9d864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Mon, 18 Mar 2019 19:22:43 -0300 Subject: [PATCH] Create method to list all realms from a Keycloak deployment --- keycloak/keycloak_admin.py | 13 +++++++++++-- keycloak/urls_patterns.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index d6395ad..36da933 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -34,7 +34,7 @@ from .urls_patterns import URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENT_AUTHZ_RESOURC URL_ADMIN_USER_CLIENT_ROLES_COMPOSITE, URL_ADMIN_USER_GROUP, URL_ADMIN_REALM_ROLES, URL_ADMIN_GROUP_CHILD, \ URL_ADMIN_USER_CONSENTS, URL_ADMIN_SEND_VERIFY_EMAIL, URL_ADMIN_CLIENT, URL_ADMIN_USER, URL_ADMIN_CLIENT_ROLE, \ URL_ADMIN_USER_GROUPS, URL_ADMIN_CLIENTS, URL_ADMIN_FLOWS_EXECUTIONS, URL_ADMIN_GROUPS, URL_ADMIN_USER_CLIENT_ROLES, \ - URL_ADMIN_REALM_IMPORT, URL_ADMIN_USERS_COUNT, URL_ADMIN_FLOWS, URL_ADMIN_GROUP, URL_ADMIN_CLIENT_AUTHZ_SETTINGS, \ + URL_ADMIN_REALMS, URL_ADMIN_USERS_COUNT, URL_ADMIN_FLOWS, URL_ADMIN_GROUP, URL_ADMIN_CLIENT_AUTHZ_SETTINGS, \ URL_ADMIN_GROUP_MEMBERS, URL_ADMIN_USER_STORAGE, URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_IDPS, \ URL_ADMIN_USER_CLIENT_ROLES_AVAILABLE, URL_ADMIN_USERS, URL_ADMIN_CLIENT_SCOPES, \ URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER, URL_ADMIN_CLIENT_SCOPE @@ -132,10 +132,19 @@ class KeycloakAdmin: :return: RealmRepresentation """ - data_raw = self.connection.raw_post(URL_ADMIN_REALM_IMPORT, + data_raw = self.connection.raw_post(URL_ADMIN_REALMS, data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) + def get_realms(self): + """ + Lists all realms in Keycloak deployment + + :return: realms list + """ + data_raw = self.connection.raw_get(URL_ADMIN_REALMS) + return raise_error_from_response(data_raw, KeycloakGetError) + def get_users(self, query=None): """ Get users Returns a list of users, filtered according to query parameters diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 22f9967..2628b43 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -69,7 +69,7 @@ URL_ADMIN_CLIENT_SCOPE = URL_ADMIN_CLIENT_SCOPES + "/{scope-id}" URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER = URL_ADMIN_CLIENT_SCOPE + "/protocol-mappers/models" URL_ADMIN_REALM_ROLES = "admin/realms/{realm-name}/roles" -URL_ADMIN_REALM_IMPORT = "admin/realms" +URL_ADMIN_REALMS = "admin/realms" URL_ADMIN_IDPS = "admin/realms/{realm-name}/identity-provider/instances" URL_ADMIN_FLOWS = "admin/realms/{realm-name}/authentication/flows"