diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7a939..96b9a52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Bug that `put_directory` method in `cloud_storage.py`(GcsBucket) do not upload files that in directory +- Fix `list_folders` and `list_blobs` now logging bucket name and bucket path - [#184](https://github.com/PrefectHQ/prefect-gcp/pull/214) + ### Security ## 0.4.7 diff --git a/prefect_gcp/cloud_storage.py b/prefect_gcp/cloud_storage.py index 06b8ef0..0075300 100644 --- a/prefect_gcp/cloud_storage.py +++ b/prefect_gcp/cloud_storage.py @@ -870,7 +870,12 @@ async def list_blobs(self, folder: str = "") -> List["Blob"]: client = self.gcp_credentials.get_cloud_storage_client() bucket_path = self._join_bucket_folder(folder) - self.logger.info(f"Listing blobs in bucket {bucket_path}.") + if bucket_path is None: + self.logger.info(f"Listing blobs in bucket {self.bucket!r}.") + else: + self.logger.info( + f"Listing blobs in folder {bucket_path!r} in bucket {self.bucket!r}." + ) blobs = await run_sync_in_worker_thread( client.list_blobs, self.bucket, prefix=bucket_path ) @@ -903,12 +908,19 @@ async def list_folders(self, folder: str = "") -> List[str]: from prefect_gcp.cloud_storage import GcsBucket gcs_bucket = GcsBucket.load("my-bucket") - gcs_bucket.list_folders('years) + gcs_bucket.list_folders("years") ``` """ - bucket_path = self._join_bucket_folder() - self.logger.info(f"Listing folders in bucket {bucket_path}.") + # Beware of calling _join_bucket_folder twice, see note in method. + # However, we just want to use it to check if we are listing the root folder + bucket_path = self._join_bucket_folder(folder) + if bucket_path is None: + self.logger.info(f"Listing folders in bucket {self.bucket!r}.") + else: + self.logger.info( + f"Listing folders in {bucket_path!r} in bucket {self.bucket!r}." + ) blobs = await self.list_blobs(folder) # gets all folders with full path