From a44359a7028ccce95b43063d977bc5db6452e00f Mon Sep 17 00:00:00 2001 From: Ike Johnson-Woods Date: Tue, 28 May 2024 20:21:24 +0800 Subject: [PATCH] Keycloak: raise Exception if group isn't found --- githubapp/keycloak.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/githubapp/keycloak.py b/githubapp/keycloak.py index f397b7c..8dac12e 100644 --- a/githubapp/keycloak.py +++ b/githubapp/keycloak.py @@ -50,9 +50,12 @@ def get_group_id(client: KeycloakAdmin = None): :return: The group's UUID in Keycloak """ - group = client.get_groups(query={"search": group_name}) + group = client.get_groups(query={"search": group_name, "briefRepresentation": "true", "exact": "true"}) - return group[0]["id"] + if not group: + raise Exception(f"Cannot find group {group_name} in Keycloak") + else: + return group[0]["id"] def get_members(client: KeycloakAdmin = None, group_id: str = None): """