From 9c8835c2550a55c689355e3118f8a00da924a3a4 Mon Sep 17 00:00:00 2001 From: Lilis Iskandar Date: Tue, 9 Mar 2021 18:26:10 +0800 Subject: [PATCH] Added get_events method for KeycloakAdmin Signed-off-by: Lilis Iskandar --- keycloak/keycloak_admin.py | 16 +++++++++++++++- keycloak/urls_patterns.py | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index c0ac364..e2e5648 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -47,7 +47,7 @@ from .urls_patterns import URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENT_AUTHZ_RESOURC URL_ADMIN_REALM_ROLES_MEMBERS, URL_ADMIN_CLIENT_PROTOCOL_MAPPER, URL_ADMIN_CLIENT_SCOPES_MAPPERS, \ URL_ADMIN_FLOWS_EXECUTIONS_EXEUCUTION, URL_ADMIN_FLOWS_EXECUTIONS_FLOW, URL_ADMIN_FLOWS_COPY, \ URL_ADMIN_FLOWS_ALIAS, URL_ADMIN_CLIENT_SERVICE_ACCOUNT_USER, URL_ADMIN_AUTHENTICATOR_CONFIG, \ - URL_ADMIN_CLIENT_ROLES_COMPOSITE_CLIENT_ROLE, URL_ADMIN_CLIENT_ALL_SESSIONS + URL_ADMIN_CLIENT_ROLES_COMPOSITE_CLIENT_ROLE, URL_ADMIN_CLIENT_ALL_SESSIONS, URL_ADMIN_EVENTS class KeycloakAdmin: @@ -1760,6 +1760,20 @@ class KeycloakAdmin: data=None) return raise_error_from_response(data_raw, KeycloakGetError) + def get_events(self, query=None): + """ + Return a list of events, filtered according to query parameters + + EventRepresentation array + https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_eventrepresentation + + :return: events list + """ + params_path = {"realm-name": self.realm_name} + data_raw = self.raw_get(URL_ADMIN_EVENTS.format(**params_path), + data=None, **query) + return raise_error_from_response(data_raw, KeycloakGetError) + def raw_get(self, *args, **kwargs): """ Calls connection.raw_get. diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 7aa40f8..b594efe 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -105,3 +105,5 @@ URL_ADMIN_KEYS = "admin/realms/{realm-name}/keys" URL_ADMIN_USER_FEDERATED_IDENTITIES = "admin/realms/{realm-name}/users/{id}/federated-identity" URL_ADMIN_USER_FEDERATED_IDENTITY = "admin/realms/{realm-name}/users/{id}/federated-identity/{provider}" + +URL_ADMIN_EVENTS = 'admin/realms/{realm-name}/events' \ No newline at end of file