diff --git a/services/microsoft_graph_service/app/entra_client.py b/services/microsoft_graph_service/app/entra_client.py index 28e614454896f7239a8d47f9d8a9c2703fc5ce81..9fa75ce3d671920230e68c8d9bd62a3018fb41c5 100644 --- a/services/microsoft_graph_service/app/entra_client.py +++ b/services/microsoft_graph_service/app/entra_client.py @@ -10,6 +10,7 @@ from authlib.integrations.requests_client import ( # pyright: ignore[reportMiss from requests.models import Response from shared.config import Config +from shared.logging_utils import Logger GRAPH_API_URL = "https://graph.microsoft.com/v1.0" @@ -37,10 +38,17 @@ class EntraClient: f"https://login.microsoftonline.com/{self.tenant_id}/oauth2/v2.0/token" ) - print(f"Tentant ID: {self.tenant_id}") - print(f"Client ID: {self.client_id}") - print(f"Token URL: {self.token_url}") - print(f"Entra Groups: {self.allowed_groups}") + self.logger: Logger = Logger.get_logger() + + self.logger.info( + message="EntraClient initialized", + extra={ + "tenant_id": self.tenant_id, + "client_id": self.client_id, + "token_url": self.token_url, + "allowed_groups": self.allowed_groups, + }, + ) self.token: str = self._get_token() @@ -76,7 +84,9 @@ class EntraClient: response: Response if not self.allowed_groups: - print("No ENTRA_GROUP_IDS configured – fetching all users.") + self.logger.info( + message="No ENTRA_GROUP_IDS configured – fetching all users.", + ) # Fetch all users url = f"{GRAPH_API_URL}/users?$select=id,displayName,mail,userPrincipalName" else: @@ -89,8 +99,13 @@ class EntraClient: data: dict[str, Any] = response.json() if response.status_code != 200: - print("Entra error - status code", response.status_code) - print(data) + self.logger.error( + message="Error while attemtping to fetch users", + extra={ + "Status code": response.status_code, + "Details": data, + }, + ) sys.exit() users: list[EntraUser] = data.get("value", [])