slack: Add validate_certs option in plugin (#46567)

This fix adds a configurable parameter for slack plugin.

Fixes: #45682

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/4420/head
Abhijeet Kasurde 2018-11-15 20:45:27 +05:30 committed by Matt Martz
parent 87d10b9b78
commit f0c290c930
1 changed files with 12 additions and 1 deletions

View File

@ -42,6 +42,16 @@ DOCUMENTATION = '''
ini: ini:
- section: callback_slack - section: callback_slack
key: username key: username
validate_certs:
description: validate the SSL certificate of the Slack server. (For HTTPS URLs)
version_added: "2.8"
env:
- name: SLACK_VALIDATE_CERTS
ini:
- section: callback_slack
key: validate_certs
default: True
type: bool
''' '''
import json import json
@ -100,6 +110,7 @@ class CallbackModule(CallbackBase):
self.channel = self.get_option('channel') self.channel = self.get_option('channel')
self.username = self.get_option('username') self.username = self.get_option('username')
self.show_invocation = (self._display.verbosity > 1) self.show_invocation = (self._display.verbosity > 1)
self.validate_certs = self.get_option('validate_certs')
if self.webhook_url is None: if self.webhook_url is None:
self.disabled = True self.disabled = True
@ -122,7 +133,7 @@ class CallbackModule(CallbackBase):
self._display.debug(data) self._display.debug(data)
self._display.debug(self.webhook_url) self._display.debug(self.webhook_url)
try: try:
response = open_url(self.webhook_url, data=data) response = open_url(self.webhook_url, data=data, validate_certs=self.validate_certs)
return response.read() return response.read()
except Exception as e: except Exception as e:
self._display.warning(u'Could not submit message to Slack: %s' % self._display.warning(u'Could not submit message to Slack: %s' %