VictorPlusC commented on a change in pull request #16601:
URL: https://github.com/apache/beam/pull/16601#discussion_r794972798
##########
File path: sdks/python/apache_beam/runners/interactive/utils.py
##########
@@ -427,3 +430,34 @@ def create_var_in_main(name: str,
from apache_beam.runners.interactive import interactive_environment as ie
ie.current_env().watch({name: value})
return name, value
+
+
+def assert_bucket_exists(bucket_name):
+ # type: (str) -> None
+
+ """Asserts whether the specified GCS bucket with the name
+ bucket_name exists.
+
+ Logs an error and raises a ValueError if the bucket does not exist.
+
+ Logs a warning if the bucket cannot be verified to exist.
+ """
+ try:
+ from apitools.base.py.exceptions import HttpError
+ storage_client = storage.StorageV1(
+ credentials=auth.get_service_credentials(),
+ get_credentials=False,
+ http=get_new_http(),
+ response_encoding='utf8')
+ request = storage.StorageBucketsGetRequest(bucket=bucket_name)
+ storage_client.buckets.Get(request)
+ except HttpError as e:
+ if e.status_code == 404:
+ _LOGGER.error('%s bucket does not exist!', bucket_name)
+ raise ValueError('Invalid GCS bucket provided!')
+ else:
+ _LOGGER.warning(
+ 'HttpError - unable to verify whether bucket %s exists', bucket_name)
+ except ImportError as e:
+ _LOGGER.warning(
+ 'HttpError - unable to verify whether bucket %s exists', bucket_name)
Review comment:
Thanks for the catch, I've added this change now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]