ishaq101 commited on
Commit
ff2d5ce
Β·
1 Parent(s): 35a525f

Update Azure Blob Service Config

Browse files
services/uploader/azure_blob_service.py CHANGED
@@ -5,6 +5,7 @@ dotenv.load_dotenv(EnvFilepath.ENVPATH)
5
 
6
  from config.constant import AzureBlobConstants
7
  from azure.identity import DefaultAzureCredential
 
8
  from azure.storage.blob.aio import BlobServiceClient, ContainerClient
9
  # from azure.storage.blob import BlobServiceClient, ContainerClient
10
  from fastapi import UploadFile
@@ -21,31 +22,42 @@ logger = get_logger("azure blob")
21
  # CONNECTION_STRING = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
22
  # CONTAINER_NAME = "pdf-uploads" # The name of your Azure Blob Storage container
23
 
24
- # async def get_blob_service_client(url=os.environ.get('azureai__container__endpoint')) -> BlobServiceClient:
25
- # try:
26
- # default_credential = DefaultAzureCredential()
27
- # blob_service_client = BlobServiceClient(url, credential=default_credential)
28
- # return blob_service_client
29
- # except Exception as E:
30
- # logger.error(f'❌ Getting blob service client error, {E}')
31
 
32
- async def get_blob_service_client() -> BlobServiceClient:
33
- try:
34
- account_url = os.environ.get("azureai__container__endpoint")
35
- sas_token = os.environ.get("azureai__search__sas")
 
 
 
36
 
37
- if not account_url or not sas_token:
38
- raise ValueError("Missing AZURE_STORAGE_ACCOUNT_URL or AZURE_STORAGE_SAS_TOKEN")
39
 
40
- blob_service_client = BlobServiceClient(
41
- account_url=account_url,
42
- credential=sas_token
43
- )
44
  return blob_service_client
45
- except Exception as e:
46
- logger.error(f"❌ Getting blob service client error: {e}")
47
  raise
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  async def get_container_client(url=os.environ.get('azureai__container__endpoint'), container_name=os.environ.get("azureai__container__name")) -> ContainerClient:
51
  try:
 
5
 
6
  from config.constant import AzureBlobConstants
7
  from azure.identity import DefaultAzureCredential
8
+
9
  from azure.storage.blob.aio import BlobServiceClient, ContainerClient
10
  # from azure.storage.blob import BlobServiceClient, ContainerClient
11
  from fastapi import UploadFile
 
22
  # CONNECTION_STRING = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
23
  # CONTAINER_NAME = "pdf-uploads" # The name of your Azure Blob Storage container
24
 
 
 
 
 
 
 
 
25
 
26
+ if "azureai__container__key" not in os.environ:
27
+ credential=DefaultAzureCredential()
28
+ logger.info(f"βœ… Initialized Azure AI Cred: Using Default Credential")
29
+ else:
30
+ from azure.core.credentials import AzureKeyCredential
31
+ credential = AzureKeyCredential(os.environ.get('azureai__container__key'))
32
+ logger.info(f"βœ… Initialized Azure AI Cred: Using Azure Key Credential")
33
 
 
 
34
 
35
+ async def get_blob_service_client(url=os.environ.get('azureai__container__endpoint')) -> BlobServiceClient:
36
+ try:
37
+ # default_credential = DefaultAzureCredential()
38
+ blob_service_client = BlobServiceClient(url, credential=credential)
39
  return blob_service_client
40
+ except Exception as E:
41
+ logger.error(f'❌ Getting blob service client error, {E}')
42
  raise
43
 
44
+ # async def get_blob_service_client() -> BlobServiceClient:
45
+ # try:
46
+ # account_url = os.environ.get("azureai__container__endpoint")
47
+ # sas_token = os.environ.get("azureai__search__sas")
48
+
49
+ # if not account_url or not sas_token:
50
+ # raise ValueError("Missing AZURE_STORAGE_ACCOUNT_URL or AZURE_STORAGE_SAS_TOKEN")
51
+
52
+ # blob_service_client = BlobServiceClient(
53
+ # account_url=account_url,
54
+ # credential=sas_token
55
+ # )
56
+ # return blob_service_client
57
+ # except Exception as e:
58
+ # logger.error(f"❌ Getting blob service client error: {e}")
59
+ # raise
60
+
61
 
62
  async def get_container_client(url=os.environ.get('azureai__container__endpoint'), container_name=os.environ.get("azureai__container__name")) -> ContainerClient:
63
  try: