From 7bc77239cfe48d5a97a9060cb6c4a7ba05b566d9 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..e081579 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"] + try: + group_id = group[0]["id"] + except IndexError: + raise Exception(f"Cannot find group {group_name} in Keycloak") + return group_id def get_members(client: KeycloakAdmin = None, group_id: str = None): """