Commit 5dd899d0 authored by Christophe Lallement's avatar Christophe Lallement
Browse files

logging get_credentials in azure blob client

parent a95216c4
import logging
from typing import Optional, List, Any from typing import Optional, List, Any
from azure.storage.blob.aio import BlobServiceClient from azure.storage.blob.aio import BlobServiceClient
...@@ -18,6 +19,8 @@ from osdu.core.api.storage.exceptions import ( ...@@ -18,6 +19,8 @@ from osdu.core.api.storage.exceptions import (
from osdu_az.partition.partition_service import PartitionService from osdu_az.partition.partition_service import PartitionService
_LOGGER = logging.getLogger(__name__)
class AzureAioBlobStorage(BlobStorageBase): class AzureAioBlobStorage(BlobStorageBase):
""" """
...@@ -46,10 +49,13 @@ class AzureAioBlobStorage(BlobStorageBase): ...@@ -46,10 +49,13 @@ class AzureAioBlobStorage(BlobStorageBase):
def _get_credentials(self): def _get_credentials(self):
if AzureAioBlobStorage.Credentials is None: if AzureAioBlobStorage.Credentials is None:
_LOGGER.info(f"Acquire new Credentials using DefaultAzureCredential")
AzureAioBlobStorage.Credentials = DefaultAzureCredential( AzureAioBlobStorage.Credentials = DefaultAzureCredential(
exclude_shared_token_cache_credential=True, exclude_shared_token_cache_credential=True,
exclude_visual_studio_code_credential=True, exclude_visual_studio_code_credential=True,
exclude_environment_credential=True) exclude_environment_credential=True)
else:
_LOGGER.info(f"Using cached Credentials")
return AzureAioBlobStorage.Credentials return AzureAioBlobStorage.Credentials
async def _get_blob_service_client(self, tenant): async def _get_blob_service_client(self, tenant):
...@@ -61,6 +67,7 @@ class AzureAioBlobStorage(BlobStorageBase): ...@@ -61,6 +67,7 @@ class AzureAioBlobStorage(BlobStorageBase):
@classmethod @classmethod
async def close_credentials(cls): async def close_credentials(cls):
""" This cause to gracefully dispose credentials if any. Next calls will then initialize a new one """ """ This cause to gracefully dispose credentials if any. Next calls will then initialize a new one """
_LOGGER.info(f"Closing cached Credentials")
credentials_to_close, cls.Credentials = cls.Credentials, None # swap credentials_to_close, cls.Credentials = cls.Credentials, None # swap
if credentials_to_close is not None: if credentials_to_close is not None:
await credentials_to_close.close() await credentials_to_close.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment