diff --git a/awx/main/migrations/0082_v360_webhook_http_method.py b/awx/main/migrations/0082_v360_webhook_http_method.py new file mode 100644 index 0000000000..3e81cfe4a9 --- /dev/null +++ b/awx/main/migrations/0082_v360_webhook_http_method.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + + +def add_webhook_notification_template_fields(apps, schema_editor): + # loop over all existing webhook notification templates + # and make sure they have the new "http_method", "username" + # and "password" fields + NotificationTemplate = apps.get_model('main', 'notificationtemplate') + webhooks = NotificationTemplate.objects.filter(notification_type='webhook') + for w in webhooks: + w.notification_configuration['http_method'] = 'POST' + w.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0081_v360_notify_on_start'), + ] + + operations = [ + migrations.RunPython(add_webhook_notification_template_fields, migrations.RunPython.noop), + ] diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index bb9c869b12..91a6f15118 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -43,7 +43,7 @@ class WebhookBackend(AWXBaseEmailBackend): chosen_method = getattr(requests, self.http_method.lower(), None) for m in messages: auth = None - if self.username: + if self.username or self.password: auth = (self.username, self.password) r = chosen_method("{}".format(m.recipients()[0]), auth=auth,