From 5b8fba58e8f3dc2f154c8d38dfacca9aeef315db Mon Sep 17 00:00:00 2001 From: zicklam Date: Mon, 6 May 2019 13:12:41 +0200 Subject: [PATCH] Add "Disable SSL Verification" checkbox to webhook notification This commit will add a checkbox which will disable SSL verification on the generic webhook notification type. This is required when using self-signed certificates. --- awx/main/notifications/webhook_backend.py | 7 +++++-- .../client/src/notifications/notificationTemplates.form.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index 04135213ed..7c17c21723 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"}, + "webhook_no_verify_ssl": {"label": "Verify SSL", "type": "bool"}, "headers": {"label": "HTTP Headers", "type": "object"}} recipient_parameter = "url" sender_parameter = None - def __init__(self, headers, fail_silently=False, **kwargs): + def __init__(self, headers, webhook_no_verify_ssl=False, fail_silently=False, **kwargs): + self.webhook_no_verify_ssl = webhook_no_verify_ssl 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.webhook_no_verify_ssl)) 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/ui/client/src/notifications/notificationTemplates.form.js b/awx/ui/client/src/notifications/notificationTemplates.form.js index af32a6a186..51876a3cf6 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)' }, + webhook_no_verify_ssl: { + 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'),