From 8ac56502d9b2f86795a22da08ae4d3ddf55f0976 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Thu, 11 Apr 2024 14:18:44 +0100 Subject: [PATCH] :bug: Remove infinite loop following suggestion from @JimMadge Co-authored-by: Jim Madge --- data_safe_haven/external/api/graph_api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data_safe_haven/external/api/graph_api.py b/data_safe_haven/external/api/graph_api.py index de4fb1bb99..692a921531 100644 --- a/data_safe_haven/external/api/graph_api.py +++ b/data_safe_haven/external/api/graph_api.py @@ -240,13 +240,19 @@ def create_application( self.grant_application_role_permissions(application_name, scope) for scope in delegated_scopes: self.grant_delegated_role_permissions(application_name, scope) - while True: + attempts = 0 + max_attempts = 5 + while attempts < max_attempts: if application_sp := self.get_service_principal_by_name( application_name ): if self.read_application_permissions(application_sp["id"]): break time.sleep(10) + attempts += 1 + + if attempts == max_attempts: + raise DataSafeHavenException("Maximum attempts to validate service principle permissions exceeded") # Return JSON representation of the AzureAD application return json_response