mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Add migration file to define http_method explicitly
This commit is contained in:
parent
37e73acb62
commit
7580491f1a
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)
|
||||
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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user