Skip to content

Commit

Permalink
support signed urls via connection string alone (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein authored Jul 20, 2024
1 parent 3bd3d09 commit 7f06dbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ResourceExistsError,
ResourceNotFoundError,
)
from azure.core.utils import parse_connection_string
from azure.storage.blob import (
BlobBlock,
BlobProperties,
Expand Down Expand Up @@ -1550,11 +1551,19 @@ async def _url(
"""
container_name, blob, version_id = self.split_path(path)

if self.connection_string:
args_dict = parse_connection_string(self.connection_string)
account_name = args_dict.get("accountname")
account_key = args_dict.get("accountkey")
else:
account_name = self.account_name
account_key = self.account_key

sas_token = generate_blob_sas(
account_name=self.account_name,
account_name=account_name,
container_name=container_name,
blob_name=blob,
account_key=self.account_key,
account_key=account_key,
permission=BlobSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(seconds=expires),
version_id=version_id,
Expand Down
20 changes: 20 additions & 0 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,26 @@ async def test_url_versioned(storage, mocker):
)


async def test_url_with_conn_str(mocker):
fs = AzureBlobFileSystem(connection_string=CONN_STR)
generate_blob_sas = mocker.patch("adlfs.spec.generate_blob_sas")

await fs._url("data/root/a/file.txt")
generate_blob_sas.assert_called_once_with(
account_name=ACCOUNT_NAME,
container_name="data",
blob_name="root/a/file.txt",
account_key=KEY,
permission=mocker.ANY,
expiry=mocker.ANY,
version_id=None,
content_disposition=None,
content_encoding=None,
content_language=None,
content_type=None,
)


def test_cp_file(storage):
fs = AzureBlobFileSystem(
account_name=storage.account_name, connection_string=CONN_STR
Expand Down

0 comments on commit 7f06dbd

Please sign in to comment.