No auth header sent if username/password fields are blank

This commit is contained in:
beeankha
2019-06-25 13:57:32 -04:00
parent 0a0b09b394
commit 99737937cd

View File

@@ -23,12 +23,12 @@ class WebhookBackend(AWXBaseEmailBackend):
recipient_parameter = "url" recipient_parameter = "url"
sender_parameter = None sender_parameter = None
def __init__(self, headers, http_method, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs): def __init__(self, http_method, headers, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs):
self.http_method = http_method self.http_method = http_method
self.disable_ssl_verification = disable_ssl_verification self.disable_ssl_verification = disable_ssl_verification
self.headers = headers self.headers = headers
self.username = username self.username = username
self.password = password if password != "" else None self.password = password
super(WebhookBackend, self).__init__(fail_silently=fail_silently) super(WebhookBackend, self).__init__(fail_silently=fail_silently)
def format_body(self, body): def format_body(self, body):
@@ -42,9 +42,11 @@ class WebhookBackend(AWXBaseEmailBackend):
raise ValueError("HTTP method must be either 'POST' or 'PUT'.") raise ValueError("HTTP method must be either 'POST' or 'PUT'.")
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:
if chosen_method is not None: auth = None
if self.username and self.password:
auth = (self.username, self.password)
r = chosen_method("{}".format(m.recipients()[0]), r = chosen_method("{}".format(m.recipients()[0]),
auth=(self.username, self.password), auth=auth,
json=m.body, json=m.body,
headers=self.headers, headers=self.headers,
verify=(not self.disable_ssl_verification)) verify=(not self.disable_ssl_verification))