Skip to content

Commit

Permalink
Merge pull request iterative#1181 from jeepkd/fix-aws-env
Browse files Browse the repository at this point in the history
s3: fix dvc not loading AWS settings from environment variables
  • Loading branch information
efiop authored Oct 1, 2018
2 parents aea92e0 + 9528ad6 commit e63ae3d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions dvc/remote/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,13 @@ def __init__(self, project, config):
creds_conf = configobj.ConfigObj(credentialpath)
creds = creds_conf.get(self.profile, {})
else:
creds = {}
creds = self._get_aws_config_from_env()

self.creds = creds
self.region = creds.get('region', self.region)
self.aws_access_key_id = creds.get('aws_access_key_id', None)
self.aws_secret_access_key = creds.get('aws_secret_access_key', None)

self.region = os.getenv('AWS_DEFAULT_REGION', self.region)
self.aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID',
self.aws_access_key_id)
self.aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY',
self.aws_secret_access_key)

@property
def bucket(self):
return urlparse(self.url).netloc
Expand All @@ -89,6 +83,14 @@ def s3(self):
region_name=self.region)
return session.client('s3', endpoint_url=self.endpoint_url)

def _get_aws_config_from_env(self):
creds = {
'region': os.getenv('AWS_DEFAULT_REGION'),
'aws_access_key_id': os.getenv('AWS_ACCESS_KEY_ID'),
'aws_secret_access_key': os.getenv('AWS_SECRET_ACCESS_KEY'),
}
return {k: v for k, v in creds.items() if v is not None}

def get_etag(self, bucket, key):
try:
obj = self.s3.head_object(Bucket=bucket, Key=key)
Expand Down

0 comments on commit e63ae3d

Please sign in to comment.