Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Nov 27, 2023
1 parent 297604d commit 6b8d239
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions boto3/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,10 @@ def _create_crt_request_serializer(session, region_name):
)


def _create_crt_s3_client(session, config, region_name, credentials, **kwargs):
def _create_crt_s3_client(
session, config, region_name, credentials, lock, **kwargs
):
"""Create boto3 wrapper class to manage crt lock reference and S3 client."""
lock = acquire_crt_s3_process_lock(PROCESS_LOCK_NAME)
if lock is None:
# If we're unable to acquire the lock, we cannot
# use the CRT in this process and should default to
# the classic s3transfer manager.
return None

cred_wrapper = BotocoreCRTCredentialsWrapper(credentials)
cred_provider = cred_wrapper.to_crt_credentials_provider()
return CRTS3Client(
Expand All @@ -79,13 +74,20 @@ def _create_crt_s3_client(session, config, region_name, credentials, **kwargs):


def _initialize_crt_transfer_primatives(client, config):
lock = acquire_crt_s3_process_lock(PROCESS_LOCK_NAME)
if lock is None:
# If we're unable to acquire the lock, we cannot
# use the CRT in this process and should default to
# the classic s3transfer manager.
return None, None

session = Session()
region_name = client.meta.region_name
credentials = client._get_credentials()

serializer = _create_crt_request_serializer(session, region_name)
s3_client = _create_crt_s3_client(
session, config, region_name, credentials
session, config, region_name, credentials, lock
)
return serializer, s3_client

Expand Down Expand Up @@ -130,10 +132,14 @@ def is_crt_compatible_request(client, crt_s3_client):
if crt_s3_client is None:
return False

is_same_region = client.meta.region_name == crt_s3_client.region
boto3_creds = client._get_credentials()
if boto3_creds is None:
return False

is_same_identity = compare_identity(
client._get_credentials(), crt_s3_client.cred_provider
boto3_creds.get_frozen_credentials(), crt_s3_client.cred_provider
)
is_same_region = client.meta.region_name == crt_s3_client.region
return is_same_region and is_same_identity


Expand Down

0 comments on commit 6b8d239

Please sign in to comment.