BjornPrime commented on code in PR #25965:
URL: https://github.com/apache/beam/pull/25965#discussion_r1242679621
##########
sdks/python/apache_beam/io/gcp/gcsio.py:
##########
@@ -185,40 +144,30 @@ def get_project_number(self, bucket):
bucket_metadata = self.get_bucket(bucket_name=bucket)
if bucket_metadata:
self.bucket_to_project_number[bucket] = bucket_metadata.projectNumber
- # else failed to load the bucket metadata due to HttpError
return self.bucket_to_project_number.get(bucket, None)
- def _set_rewrite_response_callback(self, callback):
- """For testing purposes only. No backward compatibility guarantees.
-
- Args:
- callback: A function that receives ``storage.RewriteResponse``.
- """
- self._rewrite_cb = callback
-
def get_bucket(self, bucket_name):
"""Returns an object bucket from its name, or None if it does not exist."""
try:
- request = storage.StorageBucketsGetRequest(bucket=bucket_name)
- return self.client.buckets.Get(request)
- except HttpError:
+ return self.client.lookup_bucket(bucket_name)
+ except NotFound:
return None
def create_bucket(self, bucket_name, project, kms_key=None, location=None):
"""Create and return a GCS bucket in a specific project."""
- encryption = None
- if kms_key:
- encryption = storage.Bucket.EncryptionValue(kms_key)
-
- request = storage.StorageBucketsInsertRequest(
- bucket=storage.Bucket(
- name=bucket_name, location=location, encryption=encryption),
- project=project,
- )
+
try:
- return self.client.buckets.Insert(request)
- except HttpError:
+ bucket = self.client.create_bucket(
+ bucket_or_name=bucket_name,
+ project=project,
+ location=location,
+ )
+ if kms_key:
+ bucket.default_kms_key_name(kms_key)
+ return self.get_bucket(bucket_name)
Review Comment:
Yeah, I think that's actually the best way to do it. Updating it 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]