mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14008 add webhook_headers to configuration.py
This commit is contained in:
parent
f58d80643c
commit
2f211034a9
@ -234,3 +234,11 @@ This parameter controls how frequently a failed job is retried, up to the maximu
|
|||||||
Default: `0` (retries disabled)
|
Default: `0` (retries disabled)
|
||||||
|
|
||||||
The maximum number of times a background task will be retried before being marked as failed.
|
The maximum number of times a background task will be retried before being marked as failed.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WEBHOOK_HEADERS
|
||||||
|
|
||||||
|
Default: {} (empty)
|
||||||
|
|
||||||
|
Default, optional user-supplied HTTP headers to be sent with webhook requests in addition to the HTTP content type.
|
||||||
|
@ -213,9 +213,9 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo
|
|||||||
verbose_name=_('additional headers'),
|
verbose_name=_('additional headers'),
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text=_(
|
help_text=_(
|
||||||
"User-supplied HTTP headers to be sent with the request in addition to the HTTP content type. Headers "
|
"User-supplied HTTP headers to be sent with the request in addition to the HTTP content type and those "
|
||||||
"should be defined in the format <code>Name: Value</code>. Jinja2 template processing is supported with "
|
"defined in configuration.py. Headers should be defined in the format <code>Name: Value</code>. Jinja2 "
|
||||||
"the same context as the request body (below)."
|
"template processing is supported with the same context as the request body (below)."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
body_template = models.TextField(
|
body_template = models.TextField(
|
||||||
@ -284,10 +284,12 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo
|
|||||||
"""
|
"""
|
||||||
Render additional_headers and return a dict of Header: Value pairs.
|
Render additional_headers and return a dict of Header: Value pairs.
|
||||||
"""
|
"""
|
||||||
if not self.additional_headers:
|
headers = get_config().WEBHOOK_HEADERS.update(self.additional_headers)
|
||||||
|
|
||||||
|
if not headers:
|
||||||
return {}
|
return {}
|
||||||
ret = {}
|
ret = {}
|
||||||
data = render_jinja2(self.additional_headers, context)
|
data = render_jinja2(headers, context)
|
||||||
for line in data.splitlines():
|
for line in data.splitlines():
|
||||||
header, value = line.split(':', 1)
|
header, value = line.split(':', 1)
|
||||||
ret[header.strip()] = value.strip()
|
ret[header.strip()] = value.strip()
|
||||||
|
@ -177,6 +177,7 @@ STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
|
|||||||
TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a')
|
TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a')
|
||||||
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
||||||
ENABLE_LOCALIZATION = getattr(configuration, 'ENABLE_LOCALIZATION', False)
|
ENABLE_LOCALIZATION = getattr(configuration, 'ENABLE_LOCALIZATION', False)
|
||||||
|
WEBHOOK_HEADERS = getattr(configuration, 'WEBHOOK_HEADERS', {})
|
||||||
|
|
||||||
# Check for hard-coded dynamic config parameters
|
# Check for hard-coded dynamic config parameters
|
||||||
for param in PARAMS:
|
for param in PARAMS:
|
||||||
|
Loading…
Reference in New Issue
Block a user