mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-13 20:37:44 +01:00
Compare commits
2 Commits
21407-ruff
...
21412-defe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5db8c04c64 | ||
|
|
0bb22dee0c |
@@ -200,6 +200,48 @@ REDIS = {
|
||||
!!! note
|
||||
It is permissible to use Sentinel for only one database and not the other.
|
||||
|
||||
### SSL Configuration
|
||||
|
||||
If you need to configure SSL/TLS for Redis beyond the basic `SSL`, `CA_CERT_PATH`, and `INSECURE_SKIP_TLS_VERIFY` options (for example, client certificates, a specific TLS version, or custom ciphers), you can pass additional parameters via the `KWARGS` key in either the `tasks` or `caching` subsection.
|
||||
|
||||
NetBox already maps `CA_CERT_PATH` to `ssl_ca_certs` and (for caching) `INSECURE_SKIP_TLS_VERIFY` to `ssl_cert_reqs`; only add `KWARGS` when you need to override or extend those settings (for example, to supply client certificates or restrict TLS version or ciphers).
|
||||
|
||||
* `KWARGS` - Optional dictionary of additional SSL/TLS (or other) parameters passed to the Redis client. These are passed directly to the underlying Redis client: for `tasks` to [redis-py](https://redis-py.readthedocs.io/en/stable/connections.html), and for `caching` to the [django-redis](https://github.com/jazzband/django-redis#configure-as-cache-backend) connection pool.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
REDIS = {
|
||||
'tasks': {
|
||||
'HOST': 'redis.example.com',
|
||||
'PORT': 1234,
|
||||
'SSL': True,
|
||||
'CA_CERT_PATH': '/etc/ssl/certs/ca.crt',
|
||||
'KWARGS': {
|
||||
'ssl_certfile': '/path/to/client-cert.pem',
|
||||
'ssl_keyfile': '/path/to/client-key.pem',
|
||||
'ssl_min_version': ssl.TLSVersion.TLSv1_2,
|
||||
'ssl_ciphers': 'HIGH:!aNULL',
|
||||
},
|
||||
},
|
||||
'caching': {
|
||||
'HOST': 'redis.example.com',
|
||||
'PORT': 1234,
|
||||
'SSL': True,
|
||||
'CA_CERT_PATH': '/etc/ssl/certs/ca.crt',
|
||||
'KWARGS': {
|
||||
'ssl_certfile': '/path/to/client-cert.pem',
|
||||
'ssl_keyfile': '/path/to/client-key.pem',
|
||||
'ssl_min_version': ssl.TLSVersion.TLSv1_2,
|
||||
'ssl_ciphers': 'HIGH:!aNULL',
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
!!! note
|
||||
If you use `ssl.TLSVersion` in your configuration (e.g. `ssl_min_version`), add `import ssl` at the top of your configuration file.
|
||||
|
||||
---
|
||||
|
||||
## SECRET_KEY
|
||||
|
||||
@@ -11,14 +11,10 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||
from django.core.validators import URLValidator
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rest_framework.utils import field_mapping
|
||||
from strawberry_django import pagination
|
||||
from strawberry_django.fields.field import StrawberryDjangoField
|
||||
|
||||
from core.exceptions import IncompatiblePluginError
|
||||
from netbox.config import PARAMS as CONFIG_PARAMS
|
||||
from netbox.constants import RQ_QUEUE_DEFAULT, RQ_QUEUE_HIGH, RQ_QUEUE_LOW
|
||||
from netbox.graphql.pagination import OffsetPaginationInput, apply_pagination
|
||||
from netbox.plugins import PluginConfig
|
||||
from netbox.registry import registry
|
||||
import storages.utils # type: ignore
|
||||
@@ -28,21 +24,6 @@ from utilities.string import trailing_slash
|
||||
from .monkey import get_unique_validators
|
||||
|
||||
|
||||
#
|
||||
# Monkey-patching
|
||||
#
|
||||
|
||||
# TODO: Remove this once #20547 has been implemented
|
||||
# Override DRF's get_unique_validators() function with our own (see bug #19302)
|
||||
field_mapping.get_unique_validators = get_unique_validators
|
||||
|
||||
# Override strawberry-django's OffsetPaginationInput class to add the `start` parameter
|
||||
pagination.OffsetPaginationInput = OffsetPaginationInput
|
||||
|
||||
# Patch StrawberryDjangoField to use our custom `apply_pagination()` method with support for cursor-based pagination
|
||||
StrawberryDjangoField.apply_pagination = apply_pagination
|
||||
|
||||
|
||||
#
|
||||
# Environment setup
|
||||
#
|
||||
@@ -408,6 +389,11 @@ if CACHING_REDIS_CA_CERT_PATH:
|
||||
CACHES['default']['OPTIONS'].setdefault('CONNECTION_POOL_KWARGS', {})
|
||||
CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS']['ssl_ca_certs'] = CACHING_REDIS_CA_CERT_PATH
|
||||
|
||||
# Merge in KWARGS for additional parameters
|
||||
if caching_redis_kwargs := REDIS['caching'].get('KWARGS'):
|
||||
CACHES['default']['OPTIONS'].setdefault('CONNECTION_POOL_KWARGS', {})
|
||||
CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS'].update(caching_redis_kwargs)
|
||||
|
||||
|
||||
#
|
||||
# Sessions
|
||||
@@ -817,6 +803,11 @@ if TASKS_REDIS_CA_CERT_PATH:
|
||||
RQ_PARAMS.setdefault('REDIS_CLIENT_KWARGS', {})
|
||||
RQ_PARAMS['REDIS_CLIENT_KWARGS']['ssl_ca_certs'] = TASKS_REDIS_CA_CERT_PATH
|
||||
|
||||
# Merge in KWARGS for additional parameters
|
||||
if tasks_redis_kwargs := TASKS_REDIS.get('KWARGS'):
|
||||
RQ_PARAMS.setdefault('REDIS_CLIENT_KWARGS', {})
|
||||
RQ_PARAMS['REDIS_CLIENT_KWARGS'].update(tasks_redis_kwargs)
|
||||
|
||||
# Define named RQ queues
|
||||
RQ_QUEUES = {
|
||||
RQ_QUEUE_HIGH: RQ_PARAMS,
|
||||
@@ -959,6 +950,26 @@ for plugin_name in PLUGINS:
|
||||
raise ImproperlyConfigured(f"events_pipline in plugin: {plugin_name} must be a list or tuple")
|
||||
|
||||
|
||||
#
|
||||
# Monkey-patching
|
||||
#
|
||||
|
||||
from rest_framework.utils import field_mapping # noqa: E402
|
||||
from strawberry_django import pagination # noqa: E402
|
||||
from strawberry_django.fields.field import StrawberryDjangoField # noqa: E402
|
||||
from netbox.graphql.pagination import OffsetPaginationInput, apply_pagination # noqa: E402
|
||||
|
||||
# TODO: Remove this once #20547 has been implemented
|
||||
# Override DRF's get_unique_validators() function with our own (see bug #19302)
|
||||
field_mapping.get_unique_validators = get_unique_validators
|
||||
|
||||
# Override strawberry-django's OffsetPaginationInput class to add the `start` parameter
|
||||
pagination.OffsetPaginationInput = OffsetPaginationInput
|
||||
|
||||
# Patch StrawberryDjangoField to use our custom `apply_pagination()` method with support for cursor-based pagination
|
||||
StrawberryDjangoField.apply_pagination = apply_pagination
|
||||
|
||||
|
||||
# UNSUPPORTED FUNCTIONALITY: Import any local overrides.
|
||||
try:
|
||||
from .local_settings import *
|
||||
|
||||
Reference in New Issue
Block a user