From 5b8fba58e8f3dc2f154c8d38dfacca9aeef315db Mon Sep 17 00:00:00 2001 From: zicklam Date: Mon, 6 May 2019 13:12:41 +0200 Subject: [PATCH 1/4] 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'), From 08d60d0b78e3054f2bc2c4880e80bb33af67ac67 Mon Sep 17 00:00:00 2001 From: zicklam Date: Mon, 6 May 2019 19:20:00 +0200 Subject: [PATCH 2/4] Update test_notification Template for webhooks - rename webhook_no_verify_ssl to disable_ssl_verification --- awx/main/notifications/webhook_backend.py | 8 ++++---- awx/main/tests/functional/test_notifications.py | 6 +++--- .../src/notifications/notificationTemplates.form.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index 7c17c21723..e4fdc7de4a 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -15,13 +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"}, + "disable_ssl_verification": {"label": "Verify SSL", "type": "bool"}, "headers": {"label": "HTTP Headers", "type": "object"}} recipient_parameter = "url" sender_parameter = None - def __init__(self, headers, webhook_no_verify_ssl=False, fail_silently=False, **kwargs): - self.webhook_no_verify_ssl = webhook_no_verify_ssl + 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) @@ -36,7 +36,7 @@ class WebhookBackend(AWXBaseEmailBackend): r = requests.post("{}".format(m.recipients()[0]), json=m.body, headers=self.headers, - verify=(not self.webhook_no_verify_ssl)) + 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 51876a3cf6..fa291d7654 100644 --- a/awx/ui/client/src/notifications/notificationTemplates.form.js +++ b/awx/ui/client/src/notifications/notificationTemplates.form.js @@ -399,7 +399,7 @@ export default ['i18n', function(i18n) { subForm: 'typeSubForm', ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' }, - webhook_no_verify_ssl: { + disable_ssl_verification: { label: i18n._('Disable SSL Verification'), type: 'checkbox', ngShow: "notification_type.value == 'webhook' ", From 0fb3851a2bb21dad9287ed8b838c67798413edca Mon Sep 17 00:00:00 2001 From: zicklam Date: Wed, 8 May 2019 08:21:04 +0200 Subject: [PATCH 3/4] webhook_notification set default for var 'disable_ssl_verification' --- awx/main/notifications/webhook_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index e4fdc7de4a..648da40df8 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -15,7 +15,7 @@ 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"}, + "disable_ssl_verification": {"label": "Verify SSL", "type": "bool", "default": false}, "headers": {"label": "HTTP Headers", "type": "object"}} recipient_parameter = "url" sender_parameter = None From 42f30e72b5e0871dee1dff2972906362da0a7168 Mon Sep 17 00:00:00 2001 From: zicklam Date: Wed, 8 May 2019 08:35:26 +0200 Subject: [PATCH 4/4] False is not false --- awx/main/notifications/webhook_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index 648da40df8..7a68587621 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -15,7 +15,7 @@ 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}, + "disable_ssl_verification": {"label": "Verify SSL", "type": "bool", "default": False}, "headers": {"label": "HTTP Headers", "type": "object"}} recipient_parameter = "url" sender_parameter = None