diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index a5052f3..6c27112 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -3839,6 +3839,27 @@ class KeycloakAdmin: ) return raise_error_from_response(data_raw, KeycloakGetError) + def get_admin_events(self, query=None): + """Get Administrative events. + + Return a list of events, filtered according to query parameters + + AdminEvents Representation array + https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_getevents + https://www.keycloak.org/docs-api/22.0.1/rest-api/index.html#_get_adminrealmsrealmadmin_events + + :param query: Additional query parameters + :type query: dict + :return: events list + :rtype: list + """ + query = query or dict() + params_path = {"realm-name": self.connection.realm_name} + data_raw = self.connection.raw_get( + urls_patterns.URL_ADMIN_ADMIN_EVENTS.format(**params_path), data=None, **query + ) + return raise_error_from_response(data_raw, KeycloakGetError) + def get_events(self, query=None): """Get events. @@ -3855,7 +3876,7 @@ class KeycloakAdmin: query = query or dict() params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( - urls_patterns.URL_ADMIN_EVENTS.format(**params_path), data=None, **query + urls_patterns.URL_ADMIN_USER_EVENTS.format(**params_path), data=None, **query ) return raise_error_from_response(data_raw, KeycloakGetError) diff --git a/src/keycloak/urls_patterns.py b/src/keycloak/urls_patterns.py index bb5042e..a433444 100644 --- a/src/keycloak/urls_patterns.py +++ b/src/keycloak/urls_patterns.py @@ -192,8 +192,9 @@ URL_ADMIN_USER_FEDERATED_IDENTITY = ( "admin/realms/{realm-name}/users/{id}/federated-identity/{provider}" ) -URL_ADMIN_EVENTS = "admin/realms/{realm-name}/events" -URL_ADMIN_EVENTS_CONFIG = URL_ADMIN_EVENTS + "/config" +URL_ADMIN_USER_EVENTS = "admin/realms/{realm-name}/events" +URL_ADMIN_ADMIN_EVENTS = "admin/realms/{realm-name}/admin-events" +URL_ADMIN_EVENTS_CONFIG = URL_ADMIN_USER_EVENTS + "/config" URL_ADMIN_CLIENT_SESSION_STATS = "admin/realms/{realm-name}/client-session-stats" URL_ADMIN_GROUPS_CLIENT_ROLES_COMPOSITE = URL_ADMIN_GROUPS_CLIENT_ROLES + "/composite" diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index eec3a28..0951db3 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -2284,7 +2284,23 @@ def test_keys(admin: KeycloakAdmin, realm: str): } -def test_events(admin: KeycloakAdmin, realm: str): +def test_admin_events(admin: KeycloakAdmin, realm: str): + """Test events. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ + admin.realm_name = realm + + admin.create_client(payload={"name": "test", "clientId": "test"}) + + events = admin.get_admin_events() + assert events == list() + + +def test_user_events(admin: KeycloakAdmin, realm: str): """Test events. :param admin: Keycloak Admin client diff --git a/tox.ini b/tox.ini index cf443a5..9fe190a 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ skipsdist = true envlist = check, apply-check, docs, tests, build, changelog [testenv] -allowlist_externals = poetry, ./test_keycloak_init.sh +allowlist_externals = poetry, ./test_keycloak_init.sh, black, isort, flake8, codespell commands_pre = poetry install --sync