Skip to content

Commit

Permalink
Merge pull request #16 from astronomerio/Refactor-S3-Hook-To-Use-Logi…
Browse files Browse the repository at this point in the history
…n-and-Password-For-Access-Keys

Add S3Hook login and password support for keys
  • Loading branch information
andscoop authored Oct 9, 2017
2 parents 12e9dcf + 90d5aaa commit 0eb7862
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions airflow/hooks/S3_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ def __init__(
self.extra_params = self.s3_conn.extra_dejson
self.profile = self.extra_params.get('profile')
self.calling_format = None
self._creds_in_conn = 'aws_secret_access_key' in self.extra_params
self._creds_in_conn = any(['aws_secret_access_key' in self.extra_params,
self.s3_conn.password])
self._creds_in_config_file = 's3_config_file' in self.extra_params
self._default_to_boto = False
if self._creds_in_conn:
self._a_key = self.extra_params['aws_access_key_id']
self._s_key = self.extra_params['aws_secret_access_key']
self._a_key = self._get_access_key_id()
self._s_key = self._get_secret_access_key()
if 'calling_format' in self.extra_params:
self.calling_format = self.extra_params['calling_format']
elif self._creds_in_config_file:
Expand Down Expand Up @@ -135,6 +136,24 @@ def __setstate__(self, d):
self.__dict__.update(d)
self.__dict__['connection'] = self.get_conn()

def _get_access_key_id(self):
"""
Access key ID can be provided in extras or as connection login.
"""
access_key = self.extra_params.get('aws_access_key_id')
if access_key is not None:
return access_key
return self.s3_conn.login

def _get_secret_access_key(self):
"""
Secret access key can be provided in extras or as connection password.
"""
secret_key = self.extra_params.get('aws_secret_access_key')
if secret_key is not None:
return secret_key
return self.s3_conn.password

def _parse_s3_url(self, s3url):
warnings.warn(
'Please note: S3Hook._parse_s3_url() is now '
Expand Down

0 comments on commit 0eb7862

Please sign in to comment.