-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure_blob_storage.py
31 lines (25 loc) · 1.27 KB
/
azure_blob_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Any
from azure.storage.blob import BlobServiceClient
from dify_plugin import ToolProvider
from dify_plugin.errors.tool import ToolProviderCredentialValidationError
class AzureBlobStorageProvider(ToolProvider):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
account_name = credentials.get("account_name")
api_key = credentials.get("api_key")
# ensure account name and api key are provided
if not account_name:
raise Exception("Azure Blob Storage Account Name is required")
if not api_key:
raise Exception("Azure Blob Storage API Key is required")
# validate connection string
try:
blob_service_client = BlobServiceClient(
account_url=f"https://{account_name}.blob.core.windows.net", credential=api_key
)
containers = blob_service_client.list_containers()
containers_count = len(list(containers)) # noqa: F841
except Exception as e:
raise Exception("Invalid Azure Blob Storage connection string") from e
except Exception as e:
raise ToolProviderCredentialValidationError(str(e)) from e