-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdee967
commit ac727e2
Showing
5 changed files
with
18 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
from typing import Dict, Optional, Union | ||
|
||
from azure.identity import DefaultAzureCredential | ||
from azure.identity import ManagedIdentityCredential | ||
from azure.storage.blob import ContainerClient | ||
|
||
from pccommon.constants import AZURITE_ACCOUNT_KEY | ||
|
||
|
||
def get_container_client( | ||
container_url: str, | ||
account_key: Optional[str] = None, | ||
) -> ContainerClient: | ||
credential: Optional[Union[str, Dict[str, str], DefaultAzureCredential]] = None | ||
if account_key: | ||
# Handle Azurite | ||
if container_url.startswith("http://azurite:"): | ||
credential = { | ||
"account_name": "devstoreaccount1", | ||
"account_key": account_key, | ||
} | ||
else: | ||
raise ValueError( | ||
"Non-azurite account key provided. " | ||
"Account keys can only be used with Azurite emulator." | ||
) | ||
credential: Optional[Union[Dict[str, str], ManagedIdentityCredential]] = None | ||
# Handle Azurite | ||
if container_url.startswith("http://azurite:"): | ||
credential = { | ||
"account_name": "devstoreaccount1", | ||
"account_key": AZURITE_ACCOUNT_KEY, | ||
} | ||
else: | ||
credential = DefaultAzureCredential() | ||
credential = ManagedIdentityCredential() | ||
|
||
return ContainerClient.from_container_url(container_url, credential=credential) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters