26
26
27
27
28
28
MICROSOFT_GRAPH_URL = config .MICROSOFT_GRAPH_URL .strip ("/" )
29
+ GRAPH_REQUEST_TIMEOUT = 10
29
30
30
31
31
32
class PrincipalType (Enum ):
@@ -325,7 +326,8 @@ def get_assignable_users(self, filter: str = "", maxResultCount: int = 5) -> Lis
325
326
users_endpoint = f"{ MICROSOFT_GRAPH_URL } /v1.0/users?$filter=startswith(displayName,'{ filter } ')&$top={ maxResultCount } "
326
327
327
328
graph_data = requests .get (users_endpoint ,
328
- headers = self ._get_auth_header (msgraph_token )).json ()
329
+ headers = self ._get_auth_header (msgraph_token ),
330
+ timeout = GRAPH_REQUEST_TIMEOUT ).json ()
329
331
result = []
330
332
331
333
for user_data in graph_data ["value" ]:
@@ -443,7 +445,7 @@ def _assign_workspace_user_to_application(self, user_id: str, workspace: Workspa
443
445
"appRoleId" : role_id ,
444
446
}
445
447
446
- response = requests .post (url , json = body , headers = self ._get_auth_header (msgraph_token ))
448
+ response = requests .post (url , json = body , headers = self ._get_auth_header (msgraph_token ), timeout = GRAPH_REQUEST_TIMEOUT )
447
449
return response
448
450
449
451
def _get_role_assignment_for_user (self , user_id : str , role_id : str ) -> dict :
@@ -468,7 +470,7 @@ def _remove_workspace_user_from_application(self, user_id: str, role_id: str) ->
468
470
469
471
msgraph_token = self ._get_msgraph_token ()
470
472
url = f"{ MICROSOFT_GRAPH_URL } /v1.0/users/{ user_id } /appRoleAssignments/{ role_assignment ['id' ]} "
471
- response = requests .delete (url , headers = self ._get_auth_header (msgraph_token ))
473
+ response = requests .delete (url , headers = self ._get_auth_header (msgraph_token ), timeout = GRAPH_REQUEST_TIMEOUT )
472
474
return response
473
475
474
476
def _get_batch_users_by_role_assignments_body (self , roles_graph_data ):
@@ -519,9 +521,9 @@ def _ms_graph_query(self, url: str, http_method: str, json=None) -> dict:
519
521
break
520
522
logger .debug (f"Making request to: { url } " )
521
523
if json :
522
- response = requests .request (method = http_method , url = url , json = json , headers = auth_headers )
524
+ response = requests .request (method = http_method , url = url , json = json , headers = auth_headers , timeout = GRAPH_REQUEST_TIMEOUT )
523
525
else :
524
- response = requests .request (method = http_method , url = url , headers = auth_headers )
526
+ response = requests .request (method = http_method , url = url , headers = auth_headers , timeout = GRAPH_REQUEST_TIMEOUT )
525
527
url = ""
526
528
if response .status_code == 200 :
527
529
json_response = response .json ()
0 commit comments