Skip to content

Commit

Permalink
wasb hook: user defaultAzureCredentials instead of managedIdentity (#…
Browse files Browse the repository at this point in the history
…23394)

Co-authored-by: Sanjay Pillai <sanjaypillai11 [at] gmail.com>
  • Loading branch information
snjypl authored May 8, 2022
1 parent fcfaa83 commit 8f181c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions airflow/providers/microsoft/azure/hooks/wasb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from typing import Any, Dict, List, Optional

from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError
from azure.identity import ClientSecretCredential, ManagedIdentityCredential
from azure.identity import ClientSecretCredential, DefaultAzureCredential
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient, StorageStreamDownloader

from airflow.exceptions import AirflowException
Expand All @@ -46,7 +46,7 @@ class WasbHook(BaseHook):
passed to the `BlockBlockService()` constructor. For example, authenticate
using a SAS token by adding {"sas_token": "YOUR_TOKEN"}.
If no authentication configuration is provided, managed identity will be used (applicable
If no authentication configuration is provided, DefaultAzureCredential will be used (applicable
when using Azure compute infrastructure).
:param wasb_conn_id: Reference to the :ref:`wasb connection <howto/connection:wasb>`.
Expand Down Expand Up @@ -151,8 +151,8 @@ def get_conn(self) -> BlobServiceClient:
# Fall back to old auth (password) or use managed identity if not provided.
credential = conn.password
if not credential:
credential = ManagedIdentityCredential()
self.log.info("Using managed identity as credential")
credential = DefaultAzureCredential()
self.log.info("Using DefaultAzureCredential as credential")
return BlobServiceClient(
account_url=f"https://{conn.login}.blob.core.windows.net/",
credential=credential,
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/microsoft/azure/hooks/test_wasb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from unittest import mock

import pytest
from azure.identity import ManagedIdentityCredential
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient

from airflow.exceptions import AirflowException
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_shared_key_connection(self):
def test_managed_identity(self):
hook = WasbHook(wasb_conn_id=self.managed_identity_conn_id)
assert isinstance(hook.get_conn(), BlobServiceClient)
assert isinstance(hook.get_conn().credential, ManagedIdentityCredential)
assert isinstance(hook.get_conn().credential, DefaultAzureCredential)

@pytest.mark.parametrize(
argnames="conn_id_str, extra_key",
Expand Down

0 comments on commit 8f181c1

Please sign in to comment.