Closes #4502: Enable configuration of proxies for outbound HTTP requests

This commit is contained in:
Jeremy Stretch
2020-04-30 14:59:13 -04:00
parent 6d1b881b4d
commit c0735151d6
6 changed files with 26 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import logging
import requests
from django.conf import settings
from django_rq import job
from jinja2.exceptions import TemplateError
@@ -69,7 +70,7 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
session.verify = webhook.ssl_verification
if webhook.ca_file_path:
session.verify = webhook.ca_file_path
response = session.send(prepared_request)
response = session.send(prepared_request, proxies=settings.HTTP_PROXIES)
if 200 <= response.status_code <= 299:
logger.info("Request succeeded; response status {}".format(response.status_code))

View File

@@ -124,6 +124,12 @@ EXEMPT_VIEW_PERMISSIONS = [
# 'ipam.prefix',
]
# HTTP proxies NetBox should use when sending outbound HTTP requests (e.g. for webhooks).
# HTTP_PROXIES = {
# 'http': 'http://10.10.1.10:3128',
# 'https': 'http://10.10.1.10:1080',
# }
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
# https://docs.djangoproject.com/en/stable/topics/logging/
LOGGING = {}

View File

@@ -77,6 +77,7 @@ DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BAS
EMAIL = getattr(configuration, 'EMAIL', {})
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None)
LOGGING = getattr(configuration, 'LOGGING', {})
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)

View File

@@ -28,7 +28,7 @@ def get_releases(pre_releases=False):
try:
logger.debug("Fetching new releases from {}".format(url))
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, proxies=settings.HTTP_PROXIES)
response.raise_for_status()
total_releases = len(response.json())