Skip to content

Commit

Permalink
feat: use credential chain to prefer cli credential (#23)
Browse files Browse the repository at this point in the history
This PR replaces DefaultAzureCredential with a custom credential chain
that prefers the AzureCLI credential over the ManagedIdentityCredential
  • Loading branch information
jakevc authored Jul 28, 2024
1 parent 038f893 commit 723575c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions snakemake_storage_plugin_azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from typing import Iterable, List, Optional
from urllib.parse import urlparse

from azure.identity import DefaultAzureCredential
from azure.identity import (
AzureCliCredential,
ChainedTokenCredential,
EnvironmentCredential,
ManagedIdentityCredential,
)
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient
from snakemake_interface_storage_plugins.common import Operation
from snakemake_interface_storage_plugins.io import IOCacheStorageInterface, Mtime
Expand Down Expand Up @@ -81,8 +86,16 @@ def __post_init__(self):
test_credential
)
else:
# prefer azure cli credential,
# then managed identity,
# then environment
credential_chain = (
AzureCliCredential(),
ManagedIdentityCredential(),
EnvironmentCredential(),
)
self.blob_account_client = BlobServiceClient(
endpoint_url, credential=DefaultAzureCredential()
endpoint_url, credential=ChainedTokenCredential(*credential_chain)
)

def use_rate_limiter(self) -> bool:
Expand Down

0 comments on commit 723575c

Please sign in to comment.