mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 02:47:35 -02:30
Add migration file to define http_method explicitly
This commit is contained in:
26
awx/main/migrations/0082_v360_webhook_http_method.py
Normal file
26
awx/main/migrations/0082_v360_webhook_http_method.py
Normal file
@@ -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),
|
||||||
|
]
|
||||||
@@ -43,7 +43,7 @@ class WebhookBackend(AWXBaseEmailBackend):
|
|||||||
chosen_method = getattr(requests, self.http_method.lower(), None)
|
chosen_method = getattr(requests, self.http_method.lower(), None)
|
||||||
for m in messages:
|
for m in messages:
|
||||||
auth = None
|
auth = None
|
||||||
if self.username:
|
if self.username or self.password:
|
||||||
auth = (self.username, self.password)
|
auth = (self.username, self.password)
|
||||||
r = chosen_method("{}".format(m.recipients()[0]),
|
r = chosen_method("{}".format(m.recipients()[0]),
|
||||||
auth=auth,
|
auth=auth,
|
||||||
|
|||||||
Reference in New Issue
Block a user