|
| 1 | +#### |
| 2 | +## We recommend to not edit this file. |
| 3 | +## Create separate files to overwrite the settings. |
| 4 | +## See `extra.py` as an example. |
| 5 | +#### |
| 6 | + |
| 7 | +from os import environ |
| 8 | +from os.path import abspath, dirname |
| 9 | + |
| 10 | +# For reference see https://netbox.readthedocs.io/en/stable/configuration/ |
| 11 | +# Based on https://github.com/netbox-community/netbox/blob/master/netbox/netbox/configuration.example.py |
| 12 | + |
| 13 | +# Read secret from file |
| 14 | +def _read_secret(secret_name, default=None): |
| 15 | + try: |
| 16 | + f = open("/run/secrets/" + secret_name, encoding="utf-8") |
| 17 | + except OSError: |
| 18 | + return default |
| 19 | + else: |
| 20 | + with f: |
| 21 | + return f.readline().strip() |
| 22 | + |
| 23 | + |
| 24 | +_BASE_DIR = dirname(dirname(abspath(__file__))) |
| 25 | + |
| 26 | +######################### |
| 27 | +# # |
| 28 | +# Required settings # |
| 29 | +# # |
| 30 | +######################### |
| 31 | + |
| 32 | +# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write |
| 33 | +# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name. |
| 34 | +# |
| 35 | +# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local'] |
| 36 | +ALLOWED_HOSTS = environ.get("ALLOWED_HOSTS", "*").split(" ") |
| 37 | + |
| 38 | +# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters: |
| 39 | +# https://docs.djangoproject.com/en/stable/ref/settings/#databases |
| 40 | +DATABASE = { |
| 41 | + "NAME": environ.get("DB_NAME", "netbox"), # Database name |
| 42 | + "USER": environ.get("DB_USER", ""), # PostgreSQL username |
| 43 | + "PASSWORD": _read_secret("db_password", environ.get("DB_PASSWORD", "")), |
| 44 | + # PostgreSQL password |
| 45 | + "HOST": environ.get("DB_HOST", "localhost"), # Database server |
| 46 | + "PORT": environ.get("DB_PORT", ""), # Database port (leave blank for default) |
| 47 | + "OPTIONS": {"sslmode": environ.get("DB_SSLMODE", "prefer")}, |
| 48 | + # Database connection SSLMODE |
| 49 | + "CONN_MAX_AGE": int(environ.get("DB_CONN_MAX_AGE", "300")), |
| 50 | + # Max database connection age |
| 51 | + "DISABLE_SERVER_SIDE_CURSORS": environ.get( |
| 52 | + "DB_DISABLE_SERVER_SIDE_CURSORS", |
| 53 | + "False", |
| 54 | + ).lower() |
| 55 | + == "true", |
| 56 | + # Disable the use of server-side cursors transaction pooling |
| 57 | +} |
| 58 | + |
| 59 | +# Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate |
| 60 | +# configuration exists for each. Full connection details are required in both sections, and it is strongly recommended |
| 61 | +# to use two separate database IDs. |
| 62 | +REDIS = { |
| 63 | + "tasks": { |
| 64 | + "HOST": environ.get("REDIS_HOST", "localhost"), |
| 65 | + "PORT": int(environ.get("REDIS_PORT", 6379)), |
| 66 | + "PASSWORD": _read_secret("redis_password", environ.get("REDIS_PASSWORD", "")), |
| 67 | + "DATABASE": int(environ.get("REDIS_DATABASE", 0)), |
| 68 | + "SSL": environ.get("REDIS_SSL", "False").lower() == "true", |
| 69 | + "INSECURE_SKIP_TLS_VERIFY": environ.get( |
| 70 | + "REDIS_INSECURE_SKIP_TLS_VERIFY", |
| 71 | + "False", |
| 72 | + ).lower() |
| 73 | + == "true", |
| 74 | + }, |
| 75 | + "caching": { |
| 76 | + "HOST": environ.get("REDIS_CACHE_HOST", environ.get("REDIS_HOST", "localhost")), |
| 77 | + "PORT": int(environ.get("REDIS_CACHE_PORT", environ.get("REDIS_PORT", 6379))), |
| 78 | + "PASSWORD": _read_secret( |
| 79 | + "redis_cache_password", |
| 80 | + environ.get("REDIS_CACHE_PASSWORD", environ.get("REDIS_PASSWORD", "")), |
| 81 | + ), |
| 82 | + "DATABASE": int(environ.get("REDIS_CACHE_DATABASE", 1)), |
| 83 | + "SSL": environ.get("REDIS_CACHE_SSL", environ.get("REDIS_SSL", "False")).lower() |
| 84 | + == "true", |
| 85 | + "INSECURE_SKIP_TLS_VERIFY": environ.get( |
| 86 | + "REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY", |
| 87 | + environ.get("REDIS_INSECURE_SKIP_TLS_VERIFY", "False"), |
| 88 | + ).lower() |
| 89 | + == "true", |
| 90 | + }, |
| 91 | +} |
| 92 | + |
| 93 | +# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file. |
| 94 | +# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and |
| 95 | +# symbols. NetBox will not run without this defined. For more information, see |
| 96 | +# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY |
| 97 | +SECRET_KEY = _read_secret("secret_key", environ.get("SECRET_KEY", "")) |
| 98 | + |
| 99 | +DEVELOPER = True |
0 commit comments