Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support signed urls via connection string alone #478

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1541,11 +1542,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see what's going on here, looks good to me. One assumes the connected client also has this information, but since there's an upstream function to parse it, I don't see why we shouldn't use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thanks @martindurant for approving ... I hope maintainers will be able to take a look soon :)

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
Loading