Commit cedf155c authored by Christophe Lallement's avatar Christophe Lallement
Browse files

add logger and enable http logging for credentials and clients

parent a95216c4
Pipeline #44380 passed with stage
in 31 seconds
import logging
from typing import Optional, List, Any
from azure.storage.blob.aio import BlobServiceClient
......@@ -15,9 +16,10 @@ from osdu.core.api.storage.exceptions import (
ResourceNotFoundException,
ResourceExistsException,
PreconditionFailedException)
from osdu_az.partition.partition_service import PartitionService
_LOGGER = logging.getLogger(__name__)
class AzureAioBlobStorage(BlobStorageBase):
"""
......@@ -46,21 +48,28 @@ class AzureAioBlobStorage(BlobStorageBase):
def _get_credentials(self):
if AzureAioBlobStorage.Credentials is None:
_LOGGER.info(f"blob_storage_az: Acquire new Credentials using DefaultAzureCredential")
AzureAioBlobStorage.Credentials = DefaultAzureCredential(
exclude_shared_token_cache_credential=True,
exclude_visual_studio_code_credential=True,
exclude_environment_credential=True)
exclude_environment_credential=True,
logging_enable=True)
else:
_LOGGER.info(f"blob_storage_az: use cached Credentials")
_LOGGER.debug(f"blob_storage_az returns current DefaultAzureCredential {AzureAioBlobStorage.Credentials}")
return AzureAioBlobStorage.Credentials
async def _get_blob_service_client(self, tenant):
storage_account = await self._get_storage_account_name(tenant.data_partition_id)
cred = self._get_credentials()
account_url = self._build_url(storage_account)
return BlobServiceClient(account_url=account_url, credential=cred)
return BlobServiceClient(account_url=account_url, credential=cred, logging_enable=True)
@classmethod
async def close_credentials(cls):
""" This cause to gracefully dispose credentials if any. Next calls will then initialize a new one """
_LOGGER.info(f"blob_storage_az close_credentials")
credentials_to_close, cls.Credentials = cls.Credentials, None # swap
if credentials_to_close is not None:
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