Skip to content

Commit 15ed6e3

Browse files
samdyzonSam Dysontpdorseydesertaxle
authored
Enable DefaultAzureCredential authentication for Azure filesystem block (PrefectHQ#7513)
Co-authored-by: Sam Dyson <[email protected]> Co-authored-by: Terrence Dorsey <[email protected]> Co-authored-by: Alexander Streed <[email protected]> Co-authored-by: Alexander Streed <[email protected]>
1 parent 2cd49cf commit 15ed6e3

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

docs/concepts/filesystems.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ The `Azure` file system block enables interaction with Azure Datalake and Azure
105105
| azure_storage_tenant_id | Azure storage tenant ID. |
106106
| azure_storage_client_id | Azure storage client ID. |
107107
| azure_storage_client_secret | Azure storage client secret. |
108+
| azure_storage_anon | Anonymous authentication, disable to use `DefaultAzureCredential`. |
108109

109110

110111
To create a block:

src/prefect/filesystems.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,15 @@ class Azure(WritableFileSystem, WritableDeploymentStorage):
653653
title="Azure storage client secret",
654654
description="Equivalent to the AZURE_CLIENT_SECRET environment variable.",
655655
)
656+
azure_storage_anon: bool = Field(
657+
default=True,
658+
title="Azure storage anonymous connection",
659+
description=(
660+
"Set the 'anon' flag for ADLFS. This should be False for systems that"
661+
" require ADLFS to use DefaultAzureCredentials."
662+
),
663+
)
664+
656665
_remote_file_system: RemoteFileSystem = None
657666

658667
@property
@@ -680,6 +689,7 @@ def filesystem(self) -> RemoteFileSystem:
680689
settings["client_secret"] = (
681690
self.azure_storage_client_secret.get_secret_value()
682691
)
692+
settings["anon"] = self.azure_storage_anon
683693
self._remote_file_system = RemoteFileSystem(
684694
basepath=f"az://{self.bucket_path}", settings=settings
685695
)

tests/test_filesystems.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import prefect
99
from prefect.exceptions import InvalidRepositoryURLError
10-
from prefect.filesystems import GitHub, LocalFileSystem, RemoteFileSystem
11-
from prefect.testing.utilities import AsyncMock
10+
from prefect.filesystems import Azure, GitHub, LocalFileSystem, RemoteFileSystem
11+
from prefect.testing.utilities import AsyncMock, MagicMock
1212
from prefect.utilities.filesystem import tmpchdir
1313

1414
TEST_PROJECTS_DIR = prefect.__root_path__ / "tests" / "test-projects"
@@ -622,3 +622,52 @@ class p:
622622
await g.get_directory(local_path=tmp_dst)
623623

624624
assert any(".git" in f for f in os.listdir(tmp_dst)) == expect_git_objects
625+
626+
627+
class TestAzure:
628+
def test_init(self, monkeypatch):
629+
remote_storage_mock = MagicMock()
630+
monkeypatch.setattr("prefect.filesystems.RemoteFileSystem", remote_storage_mock)
631+
Azure(
632+
azure_storage_tenant_id="tenant",
633+
azure_storage_account_name="account",
634+
azure_storage_client_id="client_id",
635+
azure_storage_account_key="key",
636+
azure_storage_client_secret="secret",
637+
bucket_path="bucket",
638+
).filesystem
639+
remote_storage_mock.assert_called_once_with(
640+
basepath="az://bucket",
641+
settings={
642+
"account_name": "account",
643+
"account_key": "key",
644+
"tenant_id": "tenant",
645+
"client_id": "client_id",
646+
"client_secret": "secret",
647+
"anon": True,
648+
},
649+
)
650+
651+
def test_init_with_anon(self, monkeypatch):
652+
remote_storage_mock = MagicMock()
653+
monkeypatch.setattr("prefect.filesystems.RemoteFileSystem", remote_storage_mock)
654+
Azure(
655+
azure_storage_tenant_id="tenant",
656+
azure_storage_account_name="account",
657+
azure_storage_client_id="client_id",
658+
azure_storage_account_key="key",
659+
azure_storage_client_secret="secret",
660+
bucket_path="bucket",
661+
azure_storage_anon=False,
662+
).filesystem
663+
remote_storage_mock.assert_called_once_with(
664+
basepath="az://bucket",
665+
settings={
666+
"account_name": "account",
667+
"account_key": "key",
668+
"tenant_id": "tenant",
669+
"client_id": "client_id",
670+
"client_secret": "secret",
671+
"anon": False,
672+
},
673+
)

0 commit comments

Comments
 (0)