Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions airflow/contrib/hooks/slack_webhook_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -72,6 +74,7 @@ def __init__(self,
icon_url=None,
link_names=False,
proxy=None,
extra_options=None,
*args,
**kwargs
):
Expand All @@ -86,6 +89,7 @@ def __init__(self,
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):
"""
Expand Down Expand Up @@ -140,13 +144,13 @@ def execute(self):
"""
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)
9 changes: 7 additions & 2 deletions airflow/contrib/operators/slack_webhook_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -74,6 +76,7 @@ def __init__(self,
icon_emoji=None,
icon_url=None,
link_names=False,
extra_options=None,
proxy=None,
*args,
**kwargs):
Expand All @@ -92,6 +95,7 @@ def __init__(self,
self.link_names = link_names
self.proxy = proxy
self.hook = None
self.extra_options = extra_options

def execute(self, context):
"""
Expand All @@ -108,6 +112,7 @@ def execute(self, context):
self.icon_emoji,
self.icon_url,
self.link_names,
self.proxy
self.proxy,
self.extra_options
)
self.hook.execute()
3 changes: 2 additions & 1 deletion tests/contrib/hooks/test_slack_webhook_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
6 changes: 4 additions & 2 deletions tests/contrib/operators/test_slack_webhook_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -68,6 +69,7 @@ def test_execute(self):
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(
Expand All @@ -77,7 +79,7 @@ def test_assert_templated_fields(self):
)

template_fields = ['webhook_token', 'message', 'attachments', 'blocks', 'channel',
'username', 'proxy']
'username', 'proxy', 'extra_options']

self.assertEqual(operator.template_fields, template_fields)

Expand Down