Skip to content

Commit

Permalink
prefer aws creds set via env
Browse files Browse the repository at this point in the history
also, set aws access key id from default session, in the event that it 
wasn't set in psiturk's config files but was set in ones that boto 
prefers
  • Loading branch information
deargle committed May 3, 2021
1 parent 93f488f commit 5a69418
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion psiturk/amt_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ def setup_mturk_connection(self):
kwargs['aws_secret_access_key'] = aws_secret_access_key

self.mtc = boto3.client('mturk', **kwargs)

# aws access key might have been set via env var -- fetch it and
# set it to the psiturk config for dashboard use
self.config.set('AWS Access', 'aws_access_key_id',
boto3.DEFAULT_SESSION.get_credentials().access_key)

return True

def verify_aws_login(self):
Expand Down Expand Up @@ -325,7 +331,7 @@ def configure_hit(self, hit_config):
for qual_id in hit_config['block_qualification_ids']:
quals.append(dict(QualificationTypeId=qual_id,
Comparator='DoesNotExist'))

for advanced_qual in hit_config['advanced_qualifications']:
quals.append(dict(advanced_qual))

Expand Down
7 changes: 6 additions & 1 deletion psiturk/psiturk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def load_config(self):
self.set(bc['in_section'], bc['prefer_this'], os.environ.get(env_key))

# prefer environment
these_as_they_are = ['PORT', 'DATABASE_URL'] # heroku sets these
these_as_they_are = [
'PORT',
'DATABASE_URL',
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY'
]
for section in self.sections():
for config_var in self[section]:
config_var_upper = config_var.upper()
Expand Down

0 comments on commit 5a69418

Please sign in to comment.