Skip to content

Commit a9386a9

Browse files
committed
Storage account code bug fix
1 parent e40054f commit a9386a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

ai_search_with_adi/adi_function_app/storage_account.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,28 @@
77
from azure.storage.blob.aio import BlobServiceClient
88
from azure.identity import DefaultAzureCredential
99
import urllib
10+
from environment import IdentityType, get_identity_type
1011

1112

1213
class StorageAccountHelper:
1314
"""Helper class for interacting with Azure Blob Storage."""
1415

1516
def __init__(self) -> None:
1617
"""Initialize the StorageAccountHelper class."""
17-
self._client_id = os.environ["FunctionApp__ClientId"]
18-
1918
self._endpoint = os.environ["StorageAccount__ConnectionString"]
2019

2120
async def get_client(self):
2221
"""Get the BlobServiceClient object."""
23-
credential = DefaultAzureCredential(managed_identity_client_id=self._client_id)
24-
25-
return BlobServiceClient(account_url=self._endpoint, credential=credential)
22+
if get_identity_type() == IdentityType.SYSTEM_ASSIGNED:
23+
credential = DefaultAzureCredential()
24+
return BlobServiceClient(account_url=self._endpoint, credential=credential)
25+
elif get_identity_type() == IdentityType.USER_ASSIGNED:
26+
credential = DefaultAzureCredential(
27+
managed_identity_client_id=os.environ["FunctionApp__ClientId"]
28+
)
29+
return BlobServiceClient(account_url=self._endpoint, credential=credential)
30+
else:
31+
return BlobServiceClient(account_url=self._endpoint)
2632

2733
async def add_metadata_to_blob(
2834
self, source: str, container: str, metadata: dict

0 commit comments

Comments
 (0)