This is an automated email from the ASF dual-hosted git repository.
dimberman pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v1-10-test by this push:
new 33973ab Add extra options to fix SSL issue and be more flexible
(#9409)
33973ab is described below
commit 33973abb0e931f57dbcfdbd3d2bebb396465799e
Author: Ben Chen <[email protected]>
AuthorDate: Tue Jun 23 18:38:22 2020 +0200
Add extra options to fix SSL issue and be more flexible (#9409)
---
airflow/contrib/hooks/slack_webhook_hook.py | 10 +++++++---
airflow/contrib/operators/slack_webhook_operator.py | 9 +++++++--
tests/contrib/hooks/test_slack_webhook_hook.py | 3 ++-
tests/contrib/operators/test_slack_webhook_operator.py | 6 ++++--
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/airflow/contrib/hooks/slack_webhook_hook.py
b/airflow/contrib/hooks/slack_webhook_hook.py
index f3817b3..001973a 100644
--- a/airflow/contrib/hooks/slack_webhook_hook.py
+++ b/airflow/contrib/hooks/slack_webhook_hook.py
@@ -58,6 +58,8 @@ class SlackWebhookHook(HttpHook):
:type link_names: bool
:param proxy: Proxy to use to make the Slack webhook call
:type proxy: str
+ :param extra_options: Extra options for http hook
+ :type extra_options: dict
"""
def __init__(self,
@@ -72,6 +74,7 @@ class SlackWebhookHook(HttpHook):
icon_url=None,
link_names=False,
proxy=None,
+ extra_options=None,
*args,
**kwargs
):
@@ -86,6 +89,7 @@ class SlackWebhookHook(HttpHook):
self.icon_url = icon_url
self.link_names = link_names
self.proxy = proxy
+ self.extra_options = extra_options or {}
def _get_token(self, token, http_conn_id):
"""
@@ -140,13 +144,13 @@ class SlackWebhookHook(HttpHook):
"""
Remote Popen (actually execute the slack webhook call)
"""
- proxies = {}
+
if self.proxy:
# we only need https proxy for Slack, as the endpoint is https
- proxies = {'https': self.proxy}
+ self.extra_options.update({'proxies': {'https': self.proxy}})
slack_message = self._build_slack_message()
self.run(endpoint=self.webhook_token,
data=slack_message,
headers={'Content-type': 'application/json'},
- extra_options={'proxies': proxies})
+ extra_options=self.extra_options)
diff --git a/airflow/contrib/operators/slack_webhook_operator.py
b/airflow/contrib/operators/slack_webhook_operator.py
index 6169524..3b1bcfa 100644
--- a/airflow/contrib/operators/slack_webhook_operator.py
+++ b/airflow/contrib/operators/slack_webhook_operator.py
@@ -57,10 +57,12 @@ class SlackWebhookOperator(SimpleHttpOperator):
:type link_names: bool
:param proxy: Proxy to use to make the Slack webhook call
:type proxy: str
+ :param extra_options: Extra options for http hook
+ :type extra_options: dict
"""
template_fields = ['webhook_token', 'message', 'attachments', 'blocks',
'channel',
- 'username', 'proxy', ]
+ 'username', 'proxy', 'extra_options', ]
@apply_defaults
def __init__(self,
@@ -74,6 +76,7 @@ class SlackWebhookOperator(SimpleHttpOperator):
icon_emoji=None,
icon_url=None,
link_names=False,
+ extra_options=None,
proxy=None,
*args,
**kwargs):
@@ -92,6 +95,7 @@ class SlackWebhookOperator(SimpleHttpOperator):
self.link_names = link_names
self.proxy = proxy
self.hook = None
+ self.extra_options = extra_options
def execute(self, context):
"""
@@ -108,6 +112,7 @@ class SlackWebhookOperator(SimpleHttpOperator):
self.icon_emoji,
self.icon_url,
self.link_names,
- self.proxy
+ self.proxy,
+ self.extra_options
)
self.hook.execute()
diff --git a/tests/contrib/hooks/test_slack_webhook_hook.py
b/tests/contrib/hooks/test_slack_webhook_hook.py
index 13663c5..fea2d82 100644
--- a/tests/contrib/hooks/test_slack_webhook_hook.py
+++ b/tests/contrib/hooks/test_slack_webhook_hook.py
@@ -40,7 +40,8 @@ class TestSlackWebhookHook(unittest.TestCase):
'icon_emoji': ':hankey:',
'icon_url': 'https://airflow.apache.org/_images/pin_large.png',
'link_names': True,
- 'proxy': 'https://my-horrible-proxy.proxyist.com:8080'
+ 'proxy': 'https://my-horrible-proxy.proxyist.com:8080',
+ 'extra_options': {"verify": True}
}
expected_message_dict = {
'channel': _config['channel'],
diff --git a/tests/contrib/operators/test_slack_webhook_operator.py
b/tests/contrib/operators/test_slack_webhook_operator.py
index 81ba6b8..e42cb0e 100644
--- a/tests/contrib/operators/test_slack_webhook_operator.py
+++ b/tests/contrib/operators/test_slack_webhook_operator.py
@@ -39,7 +39,8 @@ class TestSlackWebhookOperator(unittest.TestCase):
'icon_emoji': ':hankey',
'icon_url': 'https://airflow.apache.org/_images/pin_large.png',
'link_names': True,
- 'proxy': 'https://my-horrible-proxy.proxyist.com:8080'
+ 'proxy': 'https://my-horrible-proxy.proxyist.com:8080',
+ 'extra_options': {"verify": True}
}
def setUp(self):
@@ -68,6 +69,7 @@ class TestSlackWebhookOperator(unittest.TestCase):
self.assertEqual(self._config['icon_url'], operator.icon_url)
self.assertEqual(self._config['link_names'], operator.link_names)
self.assertEqual(self._config['proxy'], operator.proxy)
+ self.assertEqual(self._config['extra_options'], operator.extra_options)
def test_assert_templated_fields(self):
operator = SlackWebhookOperator(
@@ -77,7 +79,7 @@ class TestSlackWebhookOperator(unittest.TestCase):
)
template_fields = ['webhook_token', 'message', 'attachments',
'blocks', 'channel',
- 'username', 'proxy']
+ 'username', 'proxy', 'extra_options']
self.assertEqual(operator.template_fields, template_fields)