Skip to content

Commit

Permalink
- Added TokenExpired retry support to paco_buckets.is_bucket_created()
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwater committed Nov 27, 2021
1 parent 34ed7e3 commit 35b3535
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/paco/config/paco_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,24 @@ def is_bucket_created(self, account_ctx, region):
"True if the S3 Bucket for the account and region exists"
bucket_name = self.get_bucket_name(account_ctx, region)
s3_client = account_ctx.get_aws_client('s3', region)
try:
s3_client.get_bucket_location(Bucket=bucket_name)
except ClientError as error:
if error.response['Error']['Code'] != 'NoSuchBucket':
raise error
else:
return False
retry_count = 0
while True:
try:
s3_client.get_bucket_location(Bucket=bucket_name)
except ClientError as error:
if error.response['Error']['Code'] == 'ExpiredToken':
retry_count += 1
s3_client = account_ctx.get_aws_client('s3', region, force=True)
print(f"paco_buckets: is_bucket_created: S3 Client Token Expired: Retry number {retry_count}")
if retry_count > 10:
print(f"paco_buckets: is_bucket_created: S3 client token refresh tried too many times, aborting.")
raise error
continue
elif error.response['Error']['Code'] != 'NoSuchBucket':
raise error
else:
return False
break
return True

def is_object_in_bucket(self, s3_key, account_ctx, region):
Expand Down

0 comments on commit 35b3535

Please sign in to comment.