Browse Source

feat: added support for Admin Events api

pull/474/head
Simone Ferrigno 1 year ago
parent
commit
555df75b8e
  1. 23
      src/keycloak/keycloak_admin.py
  2. 5
      src/keycloak/urls_patterns.py
  3. 18
      tests/test_keycloak_admin.py
  4. 2
      tox.ini

23
src/keycloak/keycloak_admin.py

@ -3839,6 +3839,27 @@ class KeycloakAdmin:
) )
return raise_error_from_response(data_raw, KeycloakGetError) 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): def get_events(self, query=None):
"""Get events. """Get events.
@ -3855,7 +3876,7 @@ class KeycloakAdmin:
query = query or dict() query = query or dict()
params_path = {"realm-name": self.connection.realm_name} params_path = {"realm-name": self.connection.realm_name}
data_raw = self.connection.raw_get( 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) return raise_error_from_response(data_raw, KeycloakGetError)

5
src/keycloak/urls_patterns.py

@ -192,8 +192,9 @@ URL_ADMIN_USER_FEDERATED_IDENTITY = (
"admin/realms/{realm-name}/users/{id}/federated-identity/{provider}" "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_CLIENT_SESSION_STATS = "admin/realms/{realm-name}/client-session-stats"
URL_ADMIN_GROUPS_CLIENT_ROLES_COMPOSITE = URL_ADMIN_GROUPS_CLIENT_ROLES + "/composite" URL_ADMIN_GROUPS_CLIENT_ROLES_COMPOSITE = URL_ADMIN_GROUPS_CLIENT_ROLES + "/composite"

18
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. """Test events.
:param admin: Keycloak Admin client :param admin: Keycloak Admin client

2
tox.ini

@ -4,7 +4,7 @@ skipsdist = true
envlist = check, apply-check, docs, tests, build, changelog envlist = check, apply-check, docs, tests, build, changelog
[testenv] [testenv]
allowlist_externals = poetry, ./test_keycloak_init.sh
allowlist_externals = poetry, ./test_keycloak_init.sh, black, isort, flake8, codespell
commands_pre = commands_pre =
poetry install --sync poetry install --sync

Loading…
Cancel
Save