Spaces:
Sleeping
Sleeping
Update Azure Blob Service Config
Browse files
externals/storages/azure_blob.py
CHANGED
|
@@ -19,15 +19,14 @@ if "azureai__container__key" not in os.environ:
|
|
| 19 |
credential=DefaultAzureCredential()
|
| 20 |
logger.info(f"β
Initialized Azure AI Cred: Using Default Credential")
|
| 21 |
else:
|
| 22 |
-
from azure.core.credentials import AzureKeyCredential
|
| 23 |
# credential = AzureKeyCredential(os.environ.get('azureai__container__key'))
|
| 24 |
-
credential = AzureKeyCredential(AzureBlobConstants.SAS_KEY)
|
|
|
|
| 25 |
logger.info(f"β
Initialized Azure AI Cred: Using Azure Key Credential")
|
| 26 |
|
| 27 |
|
| 28 |
async def get_blob_service_client() -> BlobServiceClient:
|
| 29 |
-
# global _blob_service_client, _credential
|
| 30 |
-
# _credential = DefaultAzureCredential()
|
| 31 |
_blob_service_client = BlobServiceClient(
|
| 32 |
account_url=AzureBlobConstants.ENDPOINT,
|
| 33 |
credential=credential,
|
|
|
|
| 19 |
credential=DefaultAzureCredential()
|
| 20 |
logger.info(f"β
Initialized Azure AI Cred: Using Default Credential")
|
| 21 |
else:
|
| 22 |
+
# from azure.core.credentials import AzureKeyCredential
|
| 23 |
# credential = AzureKeyCredential(os.environ.get('azureai__container__key'))
|
| 24 |
+
# credential = AzureKeyCredential(AzureBlobConstants.SAS_KEY)
|
| 25 |
+
credential = AzureBlobConstants.SAS_KEY
|
| 26 |
logger.info(f"β
Initialized Azure AI Cred: Using Azure Key Credential")
|
| 27 |
|
| 28 |
|
| 29 |
async def get_blob_service_client() -> BlobServiceClient:
|
|
|
|
|
|
|
| 30 |
_blob_service_client = BlobServiceClient(
|
| 31 |
account_url=AzureBlobConstants.ENDPOINT,
|
| 32 |
credential=credential,
|
services/uploader/azure_blob_service.py
CHANGED
|
@@ -27,16 +27,21 @@ 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(
|
| 36 |
try:
|
| 37 |
# default_credential = DefaultAzureCredential()
|
| 38 |
-
blob_service_client = BlobServiceClient(url, credential=credential)
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
except Exception as E:
|
| 41 |
logger.error(f'β Getting blob service client error, {E}')
|
| 42 |
raise
|
|
@@ -59,9 +64,9 @@ async def get_blob_service_client(url=os.environ.get('azureai__container__endpoi
|
|
| 59 |
# raise
|
| 60 |
|
| 61 |
|
| 62 |
-
async def get_container_client(
|
| 63 |
try:
|
| 64 |
-
blob_service_client = await get_blob_service_client(
|
| 65 |
blob_client = blob_service_client.get_container_client(container_name)
|
| 66 |
return blob_client
|
| 67 |
except Exception as E:
|
|
|
|
| 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 |
+
credential = AzureBlobConstants.SAS_KEY
|
| 33 |
logger.info(f"β
Initialized Azure AI Cred: Using Azure Key Credential")
|
| 34 |
|
| 35 |
|
| 36 |
+
async def get_blob_service_client() -> BlobServiceClient:
|
| 37 |
try:
|
| 38 |
# default_credential = DefaultAzureCredential()
|
| 39 |
+
# blob_service_client = BlobServiceClient(url, credential=credential)
|
| 40 |
+
_blob_service_client = BlobServiceClient(
|
| 41 |
+
account_url=AzureBlobConstants.ENDPOINT,
|
| 42 |
+
credential=credential,
|
| 43 |
+
)
|
| 44 |
+
return _blob_service_client
|
| 45 |
except Exception as E:
|
| 46 |
logger.error(f'β Getting blob service client error, {E}')
|
| 47 |
raise
|
|
|
|
| 64 |
# raise
|
| 65 |
|
| 66 |
|
| 67 |
+
async def get_container_client(container_name=os.environ.get("azureai__container__name")) -> ContainerClient:
|
| 68 |
try:
|
| 69 |
+
blob_service_client = await get_blob_service_client()
|
| 70 |
blob_client = blob_service_client.get_container_client(container_name)
|
| 71 |
return blob_client
|
| 72 |
except Exception as E:
|