Skip to content

Commit

Permalink
fixed bucket location check
Browse files Browse the repository at this point in the history
  • Loading branch information
bw2 committed Jun 25, 2024
1 parent fc35968 commit 49c7732
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions step_pipeline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,28 @@ def check_gcloud_storage_region(gs_path, expected_regions=("US", "US-CENTRAL1"),

if bucket_name in BUCKET_LOCATION_CACHE:
location = BUCKET_LOCATION_CACHE[bucket_name]

else:
try:
client = _get_google_storage_client(gcloud_project=gcloud_project)
bucket = client.get_bucket(bucket_name)
location = bucket.location
#client = _get_google_storage_client(gcloud_project=gcloud_project)
#bucket = client.get_bucket(bucket_name)
#location = bucket.location
gsutil_output = subprocess.check_output(
f"gsutil ls -Lb gs://{bucket_name}",
shell=True,
stderr=subprocess.STDOUT,
encoding="UTF-8")

location = None
for line in gsutil_output.split("\n"):
line = line.strip()
if line.startswith("Location constraint"):
location = line.split(":")[-1].strip()
break
if location is None:
raise GoogleStorageException(f"ERROR: Could not determine gs://{bucket_name} bucket region."
f"gsutil ls -Lb gs://{bucket_name} returned:\n{gsutil_output}")

BUCKET_LOCATION_CACHE[bucket_name] = location
except Exception as e:
if not ignore_access_denied_exception or "access" not in str(e).lower():
Expand Down

0 comments on commit 49c7732

Please sign in to comment.