Skip to content

Commit

Permalink
AzureBlobFileSystem.url: expose response content headers for pre-sign…
Browse files Browse the repository at this point in the history
…ed URLs (#451)
  • Loading branch information
pmrowla committed Feb 5, 2024
1 parent 18ea349 commit 576fb7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,16 @@ async def _cat_ranges(self, *args, batch_size=None, max_concurrency=None, **kwar
def url(self, path, expires=3600, **kwargs):
return sync(self.loop, self._url, path, expires, **kwargs)

async def _url(self, path, expires=3600, **kwargs):
async def _url(
self,
path,
expires=3600,
content_disposition=None,
content_encoding=None,
content_language=None,
content_type=None,
**kwargs,
):
"""Generate presigned URL to access path by HTTP
Parameters
Expand All @@ -1508,6 +1517,14 @@ async def _url(self, path, expires=3600, **kwargs):
the key path we are interested in
expires : int
the number of seconds this signature will be good for.
content_disposition : string
Response header value for Content-Disposition when this URL is accessed.
content_encoding: string
Response header value for Content-Encoding when this URL is accessed.
content_language: string
Response header value for Content-Language when this URL is accessed.
content_type: string
Response header value for Content-Type when this URL is accessed.
"""
container_name, blob, version_id = self.split_path(path)

Expand All @@ -1519,6 +1536,10 @@ async def _url(self, path, expires=3600, **kwargs):
permission=BlobSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(seconds=expires),
version_id=version_id,
content_disposition=content_disposition,
content_encoding=content_encoding,
content_language=content_language,
content_type=content_type,
)

async with self.service_client.get_blob_client(container_name, blob) as bc:
Expand Down Expand Up @@ -1683,6 +1704,10 @@ def download(self, rpath, lpath, recursive=False, **kwargs):
"""Alias of :ref:`FilesystemSpec.get`."""
return self.get(rpath, lpath, recursive=recursive, **kwargs)

def sign(self, path, expiration=100, **kwargs):
"""Create a signed URL representing the given path."""
return self.url(path, expires=expiration, **kwargs)

async def _get_file(
self,
rpath,
Expand Down
4 changes: 4 additions & 0 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,10 @@ async def test_url_versioned(storage, mocker):
permission=mocker.ANY,
expiry=mocker.ANY,
version_id=DEFAULT_VERSION_ID,
content_disposition=None,
content_encoding=None,
content_language=None,
content_type=None,
)


Expand Down

0 comments on commit 576fb7a

Please sign in to comment.