mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 19:08:38 -06:00
Misc cleanup
This commit is contained in:
parent
a95d97aaaf
commit
b9dfb1ddbc
@ -331,7 +331,7 @@ class RSSFeedWidget(DashboardWidget):
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
url=self.config['feed_url'],
|
url=self.config['feed_url'],
|
||||||
headers={'User-Agent': f'NetBox/{settings.RELEASE.version}'},
|
headers={'User-Agent': f'NetBox/{settings.RELEASE.version}'},
|
||||||
proxies=resolve_proxies(url=self.config['feed_url']),
|
proxies=resolve_proxies(url=self.config['feed_url'], context={'client': self}),
|
||||||
timeout=3
|
timeout=3
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
@ -89,7 +89,7 @@ def send_webhook(event_rule, model_name, event_type, data, timestamp, username,
|
|||||||
session.verify = webhook.ssl_verification
|
session.verify = webhook.ssl_verification
|
||||||
if webhook.ca_file_path:
|
if webhook.ca_file_path:
|
||||||
session.verify = webhook.ca_file_path
|
session.verify = webhook.ca_file_path
|
||||||
proxies = resolve_proxies(url=url, context={'webhook': webhook})
|
proxies = resolve_proxies(url=url, context={'client': webhook})
|
||||||
response = session.send(prepared_request, proxies=proxies)
|
response = session.send(prepared_request, proxies=proxies)
|
||||||
|
|
||||||
if 200 <= response.status_code <= 299:
|
if 200 <= response.status_code <= 299:
|
||||||
|
@ -117,7 +117,7 @@ EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
|
|||||||
FIELD_CHOICES = getattr(configuration, 'FIELD_CHOICES', {})
|
FIELD_CHOICES = getattr(configuration, 'FIELD_CHOICES', {})
|
||||||
FILE_UPLOAD_MAX_MEMORY_SIZE = getattr(configuration, 'FILE_UPLOAD_MAX_MEMORY_SIZE', 2621440)
|
FILE_UPLOAD_MAX_MEMORY_SIZE = getattr(configuration, 'FILE_UPLOAD_MAX_MEMORY_SIZE', 2621440)
|
||||||
GRAPHQL_MAX_ALIASES = getattr(configuration, 'GRAPHQL_MAX_ALIASES', 10)
|
GRAPHQL_MAX_ALIASES = getattr(configuration, 'GRAPHQL_MAX_ALIASES', 10)
|
||||||
HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None)
|
HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', {})
|
||||||
INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1'))
|
INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1'))
|
||||||
ISOLATED_DEPLOYMENT = getattr(configuration, 'ISOLATED_DEPLOYMENT', False)
|
ISOLATED_DEPLOYMENT = getattr(configuration, 'ISOLATED_DEPLOYMENT', False)
|
||||||
JINJA2_FILTERS = getattr(configuration, 'JINJA2_FILTERS', {})
|
JINJA2_FILTERS = getattr(configuration, 'JINJA2_FILTERS', {})
|
||||||
@ -209,7 +209,7 @@ for path in PROXY_ROUTERS:
|
|||||||
try:
|
try:
|
||||||
import_string(path)
|
import_string(path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImproperlyConfigured(f"Invalid proxy router path: {path}")
|
raise ImproperlyConfigured(f"Invalid path in PROXY_ROUTERS: {path}")
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -20,6 +20,15 @@ class DefaultProxyRouter:
|
|||||||
return urlparse(url).scheme
|
return urlparse(url).scheme
|
||||||
|
|
||||||
def route(self, url=None, protocol=None, context=None):
|
def route(self, url=None, protocol=None, context=None):
|
||||||
|
"""
|
||||||
|
Returns the appropriate proxy given a URL or protocol. Arbitrary context data may also be passed where
|
||||||
|
available.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The specific request URL for which the proxy will be used (if known)
|
||||||
|
protocol: The protocol in use (e.g. http or https) (if known)
|
||||||
|
context: Additional context to aid in proxy selection. May include e.g. the requesting client.
|
||||||
|
"""
|
||||||
if url and protocol is None:
|
if url and protocol is None:
|
||||||
protocol = self._get_protocol_from_url(url)
|
protocol = self._get_protocol_from_url(url)
|
||||||
if protocol and protocol in settings.HTTP_PROXIES:
|
if protocol and protocol in settings.HTTP_PROXIES:
|
||||||
@ -42,5 +51,5 @@ def resolve_proxies(url=None, protocol=None, context=None):
|
|||||||
|
|
||||||
for item in settings.PROXY_ROUTERS:
|
for item in settings.PROXY_ROUTERS:
|
||||||
router = import_string(item) if type(item) is str else item
|
router = import_string(item) if type(item) is str else item
|
||||||
if proxies := router.route(url=url, protocol=protocol, context=context):
|
if proxies := router().route(url=url, protocol=protocol, context=context):
|
||||||
return proxies
|
return proxies
|
||||||
|
Loading…
Reference in New Issue
Block a user