Skip to content

Commit

Permalink
Fix for Issue 13096 (#15390)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Lee <alex.lee@awtechconsulting.com>
  • Loading branch information
westford14 and Alex Lee authored Sep 16, 2024
1 parent b46c56c commit 11c0cf9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/integrations/prefect-azure/prefect_azure/blob_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,43 @@ async def write_path(self, path: str, content: bytes) -> None:
content: The content to be written.
"""
await self.upload_from_file_object(BytesIO(content), path)

@sync_compatible
async def list_blobs(self) -> List[str]:
"""
Lists blobs available within the specified Azure container.
Used to introspect your containers.
Returns:
A list of the blobs within your container.
Example:
List the blobs associated with a container.
```python
from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import AzureBlobStorageContainer
credentials = AzureBlobStorageCredentials(
connection_string="connection_string",
)
block = AzureBlobStorageContainer(
container_name="container",
credentials=credentials,
)
block.list_blobs()
```
"""
self.logger.info(
"Listing the blobs within container %s",
self.container_name,
)

async with self.credentials.get_container_client(
self.container_name
) as container_client:
blobs = container_client.list_blobs()
filenames = []
async for blob in blobs:
filenames.append(blob.name)
return filenames
10 changes: 10 additions & 0 deletions src/integrations/prefect-azure/tests/test_blob_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,13 @@ async def test_blob_storage_write_path(self, mock_blob_storage_credentials):
result = await container.read_path("prefect-write-path.txt")

assert result == b"write_path_works"

async def test_list_blobs(self, mock_blob_storage_credentials):
blob_container = AzureBlobStorageContainer(
container_name="container",
credentials=mock_blob_storage_credentials,
)

blob_result = await blob_container.list_blobs()

assert sorted(blob_result) == ["folder/prefect.txt"]

0 comments on commit 11c0cf9

Please sign in to comment.