stale[bot] closed pull request #2488: [AIRFLOW-1342] enable S3Hook to use host
from connection
URL: https://github.com/apache/incubator-airflow/pull/2488
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/airflow/hooks/S3_hook.py b/airflow/hooks/S3_hook.py
index caaa575cc4..30118e086e 100644
--- a/airflow/hooks/S3_hook.py
+++ b/airflow/hooks/S3_hook.py
@@ -105,7 +105,9 @@ def __init__(
self._creds_in_conn = 'aws_secret_access_key' in self.extra_params
self._creds_in_config_file = 's3_config_file' in self.extra_params
self._default_to_boto = False
- if 'host' in self.extra_params:
+ if self.s3_conn.host is not None:
+ self.s3_host = self.s3_conn.host
+ elif 'host' in self.extra_params:
self.s3_host = self.extra_params['host']
if self._creds_in_conn:
self._a_key = self.extra_params['aws_access_key_id']
diff --git a/tests/core.py b/tests/core.py
index 923e0c3e86..11dcafafc7 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -23,6 +23,7 @@
import unittest
import multiprocessing
import mock
+from mock.mock import patch, MagicMock
from numpy.testing import assert_array_almost_equal
import tempfile
from datetime import datetime, time, timedelta
@@ -38,7 +39,7 @@
from airflow import configuration
from airflow.executors import SequentialExecutor, LocalExecutor
-from airflow.models import Variable
+from airflow.models import Variable, Connection
from tests.test_utils.fake_datetime import FakeDatetime
configuration.load_test_config()
@@ -2380,6 +2381,24 @@ def test_parse_s3_url(self):
("test", "this/is/not/a-real-key.txt"),
"Incorrect parsing of the s3 url")
+ def test_get_host_from_connection(self):
+ host_value = "some_host"
+ connection_obj = MagicMock(
+ spec_set=Connection,
+ host=host_value
+ )
+
+ with patch.object(
+ S3Hook,
+ "get_connection",
+ return_value=connection_obj) as mocked_get_connection,\
+ patch.object(
+ S3Hook,
+ "get_conn",
+ return_value=None) as mocked_get_coon:
+ hook = S3Hook()
+ self.assertEqual(host_value, hook.s3_host)
+
send_email_test = mock.Mock()
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services