Show More
@@ -23,8 +23,10 b' import string' | |||
|
23 | 23 | from collections import OrderedDict |
|
24 | 24 | |
|
25 | 25 | import deform |
|
26 | import deform.widget | |
|
26 | 27 | import logging |
|
27 | 28 | import requests |
|
29 | import requests.adapters | |
|
28 | 30 | import colander |
|
29 | 31 | from celery.task import task |
|
30 | 32 | from requests.packages.urllib3.util.retry import Retry |
@@ -61,6 +63,15 b' WEBHOOK_URL_VARS = [' | |||
|
61 | 63 | URL_VARS = ', '.join('${' + x + '}' for x in WEBHOOK_URL_VARS) |
|
62 | 64 | |
|
63 | 65 | |
|
66 | def get_auth(settings): | |
|
67 | from requests.auth import HTTPBasicAuth | |
|
68 | username = settings.get('username') | |
|
69 | password = settings.get('password') | |
|
70 | if username and password: | |
|
71 | return HTTPBasicAuth(username, password) | |
|
72 | return None | |
|
73 | ||
|
74 | ||
|
64 | 75 | class WebhookHandler(object): |
|
65 | 76 | def __init__(self, template_url, secret_token, headers): |
|
66 | 77 | self.template_url = template_url |
@@ -188,6 +199,27 b' class WebhookSettingsSchema(colander.Sch' | |||
|
188 | 199 | placeholder='e.g. secret_token' |
|
189 | 200 | ), |
|
190 | 201 | ) |
|
202 | username = colander.SchemaNode( | |
|
203 | colander.String(), | |
|
204 | title=_('Username'), | |
|
205 | description=_('Optional username to authenticate the call.'), | |
|
206 | default='', | |
|
207 | missing='', | |
|
208 | widget=deform.widget.TextInputWidget( | |
|
209 | placeholder='e.g. admin' | |
|
210 | ), | |
|
211 | ) | |
|
212 | password = colander.SchemaNode( | |
|
213 | colander.String(), | |
|
214 | title=_('Password'), | |
|
215 | description=_('Optional password to authenticate the call.'), | |
|
216 | default='', | |
|
217 | missing='', | |
|
218 | widget=deform.widget.PasswordWidget( | |
|
219 | placeholder='e.g. secret.', | |
|
220 | redisplay=True, | |
|
221 | ), | |
|
222 | ) | |
|
191 | 223 | custom_header_key = colander.SchemaNode( |
|
192 | 224 | colander.String(), |
|
193 | 225 | title=_('Custom Header Key'), |
@@ -269,8 +301,8 b' class WebhookIntegrationType(Integration' | |||
|
269 | 301 | template_url = self.settings['url'] |
|
270 | 302 | |
|
271 | 303 | headers = {} |
|
272 |
head_key = self.settings |
|
|
273 |
head_val = self.settings |
|
|
304 | head_key = self.settings.get('custom_header_key') | |
|
305 | head_val = self.settings.get('custom_header_val') | |
|
274 | 306 | if head_key and head_val: |
|
275 | 307 | headers = {head_key: head_val} |
|
276 | 308 | |
@@ -305,12 +337,14 b' def post_to_webhook(url_calls, settings)' | |||
|
305 | 337 | |
|
306 | 338 | headers = headers or {} |
|
307 | 339 | call_headers.update(headers) |
|
340 | auth = get_auth(settings) | |
|
308 | 341 | |
|
309 |
log.debug('calling Webhook with method: %s', |
|
|
342 | log.debug('calling Webhook with method: %s, and auth:%s', | |
|
343 | call_method, auth) | |
|
310 | 344 | resp = call_method(url, json={ |
|
311 | 345 | 'token': token, |
|
312 | 346 | 'event': data |
|
313 | }, headers=call_headers) | |
|
347 | }, headers=call_headers, auth=auth) | |
|
314 | 348 | log.debug('Got Webhook response: %s', resp) |
|
315 | 349 | |
|
316 | 350 | resp.raise_for_status() # raise exception on a failed request |
General Comments 0
You need to be logged in to leave comments.
Login now