diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index 04135213ed..7a68587621 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -15,11 +15,13 @@ logger = logging.getLogger('awx.main.notifications.webhook_backend') class WebhookBackend(AWXBaseEmailBackend): init_parameters = {"url": {"label": "Target URL", "type": "string"}, + "disable_ssl_verification": {"label": "Verify SSL", "type": "bool", "default": False}, "headers": {"label": "HTTP Headers", "type": "object"}} recipient_parameter = "url" sender_parameter = None - def __init__(self, headers, fail_silently=False, **kwargs): + def __init__(self, headers, disable_ssl_verification=False, fail_silently=False, **kwargs): + self.disable_ssl_verification = disable_ssl_verification self.headers = headers super(WebhookBackend, self).__init__(fail_silently=fail_silently) @@ -33,7 +35,8 @@ class WebhookBackend(AWXBaseEmailBackend): for m in messages: r = requests.post("{}".format(m.recipients()[0]), json=m.body, - headers=self.headers) + headers=self.headers, + verify=(not self.disable_ssl_verification)) if r.status_code >= 400: logger.error(smart_text(_("Error sending notification webhook: {}").format(r.text))) if not self.fail_silently: diff --git a/awx/main/tests/functional/test_notifications.py b/awx/main/tests/functional/test_notifications.py index b9fc394d12..5c2bf74d5a 100644 --- a/awx/main/tests/functional/test_notifications.py +++ b/awx/main/tests/functional/test_notifications.py @@ -28,7 +28,7 @@ def test_basic_parameterization(get, post, user, organization): description="test webhook", organization=organization.id, notification_type="webhook", - notification_configuration=dict(url="http://localhost", + notification_configuration=dict(url="http://localhost", disable_ssl_verification=False, headers={"Test": "Header"})), u) assert response.status_code == 201 @@ -81,7 +81,7 @@ def test_inherited_notification_templates(get, post, user, organization, project description="test webhook {}".format(nfiers), organization=organization.id, notification_type="webhook", - notification_configuration=dict(url="http://localhost", + notification_configuration=dict(url="http://localhost", disable_ssl_verification=False, headers={"Test": "Header"})), u) assert response.status_code == 201 @@ -143,7 +143,7 @@ def test_custom_environment_injection(post, user, organization): description="test webhook", organization=organization.id, notification_type="webhook", - notification_configuration=dict(url="https://example.org", + notification_configuration=dict(url="https://example.org", disable_ssl_verification=False, headers={"Test": "Header"})), u) assert response.status_code == 201 diff --git a/awx/ui/client/src/notifications/notificationTemplates.form.js b/awx/ui/client/src/notifications/notificationTemplates.form.js index af32a6a186..fa291d7654 100644 --- a/awx/ui/client/src/notifications/notificationTemplates.form.js +++ b/awx/ui/client/src/notifications/notificationTemplates.form.js @@ -399,6 +399,13 @@ export default ['i18n', function(i18n) { subForm: 'typeSubForm', ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' }, + disable_ssl_verification: { + label: i18n._('Disable SSL Verification'), + type: 'checkbox', + ngShow: "notification_type.value == 'webhook' ", + subForm: 'typeSubForm', + ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' + }, headers: { label: i18n._('HTTP Headers'), dataTitle: i18n._('HTTP Headers'),