Skip to content

Commit

Permalink
fixtest: files present don't interfere with aws credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Mar 5, 2024
1 parent 4621ab8 commit a466395
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_aws_credentials(aws_credentials):
'AWS_SESSION_TOKEN': 'testing',
'AWS_DEFAULT_REGION': 'us-east-1',
}
assert secrets.aws_credentials() == expected
assert secrets.aws_credentials(skip_files=True) == expected

@pytest.mark.parametrize("green", (False, True))
@pytest.mark.parametrize("num_threads", (0, 5, 20))
Expand Down
2 changes: 2 additions & 0 deletions cloudfiles/cloudfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ def download(path):
num_threads = self.num_threads
if self.protocol == "file":
num_threads = 1
elif self.protocol == "mem":
num_threads = 0

results = schedule_jobs(
fns=( partial(download, path) for path in paths ),
Expand Down
15 changes: 8 additions & 7 deletions cloudfiles/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def google_credentials(bucket = ''):

AWS_CREDENTIALS_CACHE:CredentialCacheType = defaultdict(dict)
aws_credentials_path = secretpath('aws-secret.json')
def aws_credentials(bucket = '', service = 'aws'):
def aws_credentials(bucket = '', service = 'aws', skip_files=False):
global AWS_CREDENTIALS_CACHE

if service == 's3':
Expand All @@ -115,12 +115,13 @@ def aws_credentials(bucket = '', service = 'aws'):
paths = [ secretpath('{}-{}-secret.json'.format(bucket, service)) ] + paths

aws_credentials = {}
aws_credentials_path = secretpath(default_file_path)
for aws_credentials_path in paths:
if os.path.exists(aws_credentials_path):
with open(aws_credentials_path, 'r') as f:
aws_credentials = json.loads(f.read())
break
if not skip_files:
aws_credentials_path = secretpath(default_file_path)
for aws_credentials_path in paths:
if os.path.exists(aws_credentials_path):
with open(aws_credentials_path, 'r') as f:
aws_credentials = json.loads(f.read())
break

if not aws_credentials:
# did not find any secret json file, will try to find it in environment variables
Expand Down

0 comments on commit a466395

Please sign in to comment.