7
7
import re
8
8
from os import environ
9
9
from os .path import abspath , dirname , join
10
+ from typing import Any , Callable
10
11
11
- # For reference see https://netbox.readthedocs.io/en/stable/configuration/
12
- # Based on https://github.com/netbox-community/netbox/blob/master/netbox/netbox/configuration.example.py
12
+ # For reference see https://docs.netbox.dev/en/stable/configuration/
13
+ # Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration_example.py
14
+
15
+ ###
16
+ # NetBox-Docker Helper functions
17
+ ###
13
18
14
19
# Read secret from file
15
- def _read_secret (secret_name , default = None ):
20
+ def _read_secret (secret_name : str , default : str | None = None ) -> str | None :
16
21
try :
17
22
f = open ('/run/secrets/' + secret_name , 'r' , encoding = 'utf-8' )
18
23
except EnvironmentError :
@@ -21,6 +26,25 @@ def _read_secret(secret_name, default = None):
21
26
with f :
22
27
return f .readline ().strip ()
23
28
29
+ # If the `map_fn` isn't defined, then the value that is read from the environment (or the default value if not found) is returned.
30
+ # If the `map_fn` is defined, then `map_fn` is invoked and the value (that was read from the environment or the default value if not found)
31
+ # is passed to it as a parameter. The value returned from `map_fn` is then the return value of this function.
32
+ # The `map_fn` is not invoked, if the value (that was read from the environment or the default value if not found) is None.
33
+ def _environ_get_and_map (variable_name : str , default : str | None = None , map_fn : Callable [[str ], Any | None ] = None ) -> Any | None :
34
+ env_value = environ .get (variable_name , default )
35
+
36
+ if env_value == None :
37
+ return env_value
38
+
39
+ if not map_fn :
40
+ return env_value
41
+
42
+ return map_fn (env_value )
43
+
44
+ _EQUALS_TRUE = lambda value : value .lower () == 'true'
45
+ _AS_INT = lambda value : int (value )
46
+ _SPLIT_ON_SPACE = lambda value : list (filter (None , value .split (' ' )))
47
+
24
48
_BASE_DIR = dirname (dirname (abspath (__file__ )))
25
49
26
50
#########################
@@ -46,9 +70,9 @@ def _read_secret(secret_name, default = None):
46
70
'PORT' : environ .get ('DB_PORT' , '' ), # Database port (leave blank for default)
47
71
'OPTIONS' : {'sslmode' : environ .get ('DB_SSLMODE' , 'prefer' )},
48
72
# Database connection SSLMODE
49
- 'CONN_MAX_AGE' : int ( environ . get ( 'DB_CONN_MAX_AGE' , '300' ) ),
73
+ 'CONN_MAX_AGE' : _environ_get_and_map ( 'DB_CONN_MAX_AGE' , '300' , _AS_INT ),
50
74
# Max database connection age
51
- 'DISABLE_SERVER_SIDE_CURSORS' : environ . get ('DB_DISABLE_SERVER_SIDE_CURSORS' , 'False' ). lower () == 'true' ,
75
+ 'DISABLE_SERVER_SIDE_CURSORS' : _environ_get_and_map ('DB_DISABLE_SERVER_SIDE_CURSORS' , 'False' , _EQUALS_TRUE ) ,
52
76
# Disable the use of server-side cursors transaction pooling
53
77
}
54
78
@@ -58,19 +82,19 @@ def _read_secret(secret_name, default = None):
58
82
REDIS = {
59
83
'tasks' : {
60
84
'HOST' : environ .get ('REDIS_HOST' , 'localhost' ),
61
- 'PORT' : int ( environ . get ( 'REDIS_PORT' , 6379 ) ),
85
+ 'PORT' : _environ_get_and_map ( 'REDIS_PORT' , 6379 , _AS_INT ),
62
86
'PASSWORD' : _read_secret ('redis_password' , environ .get ('REDIS_PASSWORD' , '' )),
63
- 'DATABASE' : int ( environ . get ( 'REDIS_DATABASE' , 0 ) ),
64
- 'SSL' : environ . get ('REDIS_SSL' , 'False' ). lower () == 'true' ,
65
- 'INSECURE_SKIP_TLS_VERIFY' : environ . get ('REDIS_INSECURE_SKIP_TLS_VERIFY' , 'False' ). lower () == 'true' ,
87
+ 'DATABASE' : _environ_get_and_map ( 'REDIS_DATABASE' , 0 , _AS_INT ),
88
+ 'SSL' : _environ_get_and_map ('REDIS_SSL' , 'False' , _EQUALS_TRUE ) ,
89
+ 'INSECURE_SKIP_TLS_VERIFY' : _environ_get_and_map ('REDIS_INSECURE_SKIP_TLS_VERIFY' , 'False' , _EQUALS_TRUE ) ,
66
90
},
67
91
'caching' : {
68
92
'HOST' : environ .get ('REDIS_CACHE_HOST' , environ .get ('REDIS_HOST' , 'localhost' )),
69
- 'PORT' : int ( environ . get ( 'REDIS_CACHE_PORT' , environ .get ('REDIS_PORT' , 6379 )) ),
93
+ 'PORT' : _environ_get_and_map ( 'REDIS_CACHE_PORT' , environ .get ('REDIS_PORT' , ' 6379' ), _AS_INT ),
70
94
'PASSWORD' : _read_secret ('redis_cache_password' , environ .get ('REDIS_CACHE_PASSWORD' , environ .get ('REDIS_PASSWORD' , '' ))),
71
- 'DATABASE' : int ( environ . get ( 'REDIS_CACHE_DATABASE' , 1 ) ),
72
- 'SSL' : environ . get ('REDIS_CACHE_SSL' , environ .get ('REDIS_SSL' , 'False' )). lower () == 'true' ,
73
- 'INSECURE_SKIP_TLS_VERIFY' : environ . get ('REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY' , environ .get ('REDIS_INSECURE_SKIP_TLS_VERIFY' , 'False' )). lower () == 'true' ,
95
+ 'DATABASE' : _environ_get_and_map ( 'REDIS_CACHE_DATABASE' , '1' , _AS_INT ),
96
+ 'SSL' : _environ_get_and_map ('REDIS_CACHE_SSL' , environ .get ('REDIS_SSL' , 'False' ), _EQUALS_TRUE ) ,
97
+ 'INSECURE_SKIP_TLS_VERIFY' : _environ_get_and_map ('REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY' , environ .get ('REDIS_INSECURE_SKIP_TLS_VERIFY' , 'False' ), _EQUALS_TRUE ) ,
74
98
},
75
99
}
76
100
@@ -87,160 +111,196 @@ def _read_secret(secret_name, default = None):
87
111
# #
88
112
#########################
89
113
90
- # Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
91
- # application errors (assuming correct email settings are provided).
92
- ADMINS = [
93
- # ['John Doe', 'jdoe@example.com'],
94
- ]
114
+ # # Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
115
+ # # application errors (assuming correct email settings are provided).
116
+ # ADMINS = [
117
+ # # ['John Doe', 'jdoe@example.com'],
118
+ # ]
95
119
96
120
# URL schemes that are allowed within links in NetBox
97
- ALLOWED_URL_SCHEMES = (
121
+ _DEFAULT_ALLOWED_URL_SCHEMES = (
98
122
'file' , 'ftp' , 'ftps' , 'http' , 'https' , 'irc' , 'mailto' , 'sftp' , 'ssh' , 'tel' , 'telnet' , 'tftp' , 'vnc' , 'xmpp' ,
99
123
)
124
+ ALLOWED_URL_SCHEMES = _environ_get_and_map ('ALLOWED_URL_SCHEMES' , ' ' .join (_DEFAULT_ALLOWED_URL_SCHEMES ), _SPLIT_ON_SPACE )
100
125
101
126
# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
102
127
# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
103
- BANNER_TOP = environ .get ('BANNER_TOP' , '' )
104
- BANNER_BOTTOM = environ .get ('BANNER_BOTTOM' , '' )
128
+ BANNER_TOP = environ .get ('BANNER_TOP' , None )
129
+ BANNER_BOTTOM = environ .get ('BANNER_BOTTOM' , None )
105
130
106
131
# Text to include on the login page above the login form. HTML is allowed.
107
- BANNER_LOGIN = environ .get ('BANNER_LOGIN' , '' )
132
+ BANNER_LOGIN = environ .get ('BANNER_LOGIN' , None )
108
133
109
134
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
110
135
# BASE_PATH = 'netbox/'
111
136
BASE_PATH = environ .get ('BASE_PATH' , '' )
112
137
113
138
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
114
- CHANGELOG_RETENTION = int ( environ . get ( 'CHANGELOG_RETENTION' , 90 ) )
139
+ CHANGELOG_RETENTION = _environ_get_and_map ( 'CHANGELOG_RETENTION' , None , _AS_INT )
115
140
116
141
# Maximum number of days to retain job results (scripts and reports). Set to 0 to retain job results in the database indefinitely. (Default: 90)
117
- JOBRESULT_RETENTION = int ( environ . get ( 'JOBRESULT_RETENTION ' , 90 ) )
142
+ JOBRESULT_RETENTION = _environ_get_and_map ( 'CHANGELOG_RETENTION ' , None , _AS_INT )
118
143
119
144
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
120
145
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
121
146
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
122
- CORS_ORIGIN_ALLOW_ALL = environ .get ('CORS_ORIGIN_ALLOW_ALL' , 'False' ).lower () == 'true'
123
- CORS_ORIGIN_WHITELIST = list (filter (None , environ .get ('CORS_ORIGIN_WHITELIST' , 'https://localhost' ).split (' ' )))
124
- CORS_ORIGIN_REGEX_WHITELIST = [re .compile (r ) for r in list (filter (None , environ .get ('CORS_ORIGIN_REGEX_WHITELIST' , '' ).split (' ' )))]
125
-
126
- # Cross-Site-Request-Forgery-Attack settings. If Netbox is sitting behind a reverse proxy, you might need to set the CSRF_TRUSTED_ORIGINS flag.
127
- # Django 4.0 requires to specify the URL Scheme in this setting. An example environment variable could be specified like:
128
- # CSRF_TRUSTED_ORIGINS=https://demo.netbox.dev http://demo.netbox.dev
129
- CSRF_TRUSTED_ORIGINS = list (filter (None , environ .get ('CSRF_TRUSTED_ORIGINS' , '' ).split (' ' )))
147
+ CORS_ORIGIN_ALLOW_ALL = _environ_get_and_map ('CORS_ORIGIN_ALLOW_ALL' , 'False' , _EQUALS_TRUE )
148
+ CORS_ORIGIN_WHITELIST = _environ_get_and_map ('CORS_ORIGIN_WHITELIST' , 'https://localhost' , _SPLIT_ON_SPACE )
149
+ CORS_ORIGIN_REGEX_WHITELIST = [re .compile (r ) for r in _environ_get_and_map ('CORS_ORIGIN_REGEX_WHITELIST' , '' , _SPLIT_ON_SPACE )]
130
150
131
151
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
132
- # sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
133
- # on a production system.
134
- DEBUG = environ .get ('DEBUG' , 'False' ).lower () == 'true'
152
+ # sensitive information about your installation. Only enable debugging while performing testing.
153
+ # Never enable debugging on a production system.
154
+ DEBUG = _environ_get_and_map ('DEBUG' , 'False' , _EQUALS_TRUE )
155
+
156
+ # This parameter serves as a safeguard to prevent some potentially dangerous behavior,
157
+ # such as generating new database schema migrations.
158
+ # Set this to True only if you are actively developing the NetBox code base.
159
+ DEVELOPER = _environ_get_and_map ('DEBUG' , 'False' , _EQUALS_TRUE )
135
160
136
161
# Email settings
137
162
EMAIL = {
138
163
'SERVER' : environ .get ('EMAIL_SERVER' , 'localhost' ),
139
- 'PORT' : int ( environ . get ( 'EMAIL_PORT' , 25 ) ),
164
+ 'PORT' : _environ_get_and_map ( 'EMAIL_PORT' , 25 , _AS_INT ),
140
165
'USERNAME' : environ .get ('EMAIL_USERNAME' , '' ),
141
166
'PASSWORD' : _read_secret ('email_password' , environ .get ('EMAIL_PASSWORD' , '' )),
142
- 'USE_SSL' : environ . get ('EMAIL_USE_SSL' , 'False' ). lower () == 'true' ,
143
- 'USE_TLS' : environ . get ('EMAIL_USE_TLS' , 'False' ). lower () == 'true' ,
167
+ 'USE_SSL' : _environ_get_and_map ('EMAIL_USE_SSL' , 'False' , _EQUALS_TRUE ) ,
168
+ 'USE_TLS' : _environ_get_and_map ('EMAIL_USE_TLS' , 'False' , _EQUALS_TRUE ) ,
144
169
'SSL_CERTFILE' : environ .get ('EMAIL_SSL_CERTFILE' , '' ),
145
170
'SSL_KEYFILE' : environ .get ('EMAIL_SSL_KEYFILE' , '' ),
146
- 'TIMEOUT' : int ( environ . get ( 'EMAIL_TIMEOUT' , 10 ) ), # seconds
171
+ 'TIMEOUT' : _environ_get_and_map ( 'EMAIL_TIMEOUT' , 10 , _AS_INT ), # seconds
147
172
'FROM_EMAIL' : environ .get ('EMAIL_FROM' , '' ),
148
173
}
149
174
150
175
# Enforcement of unique IP space can be toggled on a per-VRF basis. To enforce unique IP space within the global table
151
176
# (all prefixes and IP addresses not assigned to a VRF), set ENFORCE_GLOBAL_UNIQUE to True.
152
- ENFORCE_GLOBAL_UNIQUE = environ . get ('ENFORCE_GLOBAL_UNIQUE' , 'False' ). lower () == 'true'
177
+ ENFORCE_GLOBAL_UNIQUE = _environ_get_and_map ('ENFORCE_GLOBAL_UNIQUE' , None , _EQUALS_TRUE )
153
178
154
179
# Exempt certain models from the enforcement of view permissions. Models listed here will be viewable by all users and
155
180
# by anonymous users. List models in the form `<app>.<model>`. Add '*' to this list to exempt all models.
156
- EXEMPT_VIEW_PERMISSIONS = list (filter (None , environ .get ('EXEMPT_VIEW_PERMISSIONS' , '' ).split (' ' )))
181
+ EXEMPT_VIEW_PERMISSIONS = _environ_get_and_map ('EXEMPT_VIEW_PERMISSIONS' , '' , _SPLIT_ON_SPACE )
182
+
183
+ # HTTP proxies NetBox should use when sending outbound HTTP requests (e.g. for webhooks).
184
+ # HTTP_PROXIES = {
185
+ # 'http': 'http://10.10.1.10:3128',
186
+ # 'https': 'http://10.10.1.10:1080',
187
+ # }
188
+
189
+ # IP addresses recognized as internal to the system. The debugging toolbar will be available only to clients accessing
190
+ # NetBox from an internal IP.
191
+ INTERNAL_IPS = _environ_get_and_map ('INTERNAL_IPS' , '127.0.0.1 ::1' , _SPLIT_ON_SPACE )
157
192
158
193
# Enable GraphQL API.
159
- GRAPHQL_ENABLED = environ . get ('GRAPHQL_ENABLED' , 'True' ). lower () == 'true'
194
+ GRAPHQL_ENABLED = _environ_get_and_map ('GRAPHQL_ENABLED' , None , _EQUALS_TRUE )
160
195
161
- # Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
162
- # https://docs.djangoproject.com/en/stable/topics/logging/
163
- LOGGING = {}
196
+ # # Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
197
+ # # https://docs.djangoproject.com/en/stable/topics/logging/
198
+ # LOGGING = {}
199
+
200
+ # Automatically reset the lifetime of a valid session upon each authenticated request. Enables users to remain
201
+ # authenticated to NetBox indefinitely.
202
+ LOGIN_PERSISTENCE = _environ_get_and_map ('LOGIN_PERSISTENCE' , 'False' , _EQUALS_TRUE )
164
203
165
204
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
166
205
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
167
- LOGIN_REQUIRED = environ . get ('LOGIN_REQUIRED' , 'False' ). lower () == 'true'
206
+ LOGIN_REQUIRED = _environ_get_and_map ('LOGIN_REQUIRED' , 'False' , _EQUALS_TRUE )
168
207
169
208
# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
170
209
# re-authenticate. (Default: 1209600 [14 days])
171
- LOGIN_TIMEOUT = int ( environ . get ( 'LOGIN_TIMEOUT' , 1209600 ) )
210
+ LOGIN_TIMEOUT = _environ_get_and_map ( 'LOGIN_TIMEOUT' , 1209600 , _AS_INT )
172
211
173
212
# Setting this to True will display a "maintenance mode" banner at the top of every page.
174
- MAINTENANCE_MODE = environ . get ('MAINTENANCE_MODE' , 'False' ). lower () == 'true'
213
+ MAINTENANCE_MODE = _environ_get_and_map ('MAINTENANCE_MODE' , None , _EQUALS_TRUE )
175
214
176
215
# Maps provider
177
216
MAPS_URL = environ .get ('MAPS_URL' , None )
178
217
179
218
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
180
219
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
181
220
# all objects by specifying "?limit=0".
182
- MAX_PAGE_SIZE = int ( environ . get ( 'MAX_PAGE_SIZE' , 1000 ) )
221
+ MAX_PAGE_SIZE = _environ_get_and_map ( 'MAX_PAGE_SIZE' , None , _AS_INT )
183
222
184
223
# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
185
224
# the default value of this setting is derived from the installed location.
186
225
MEDIA_ROOT = environ .get ('MEDIA_ROOT' , join (_BASE_DIR , 'media' ))
187
226
188
227
# Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
189
- METRICS_ENABLED = environ . get ('METRICS_ENABLED' , 'False' ). lower () == 'true'
228
+ METRICS_ENABLED = _environ_get_and_map ('METRICS_ENABLED' , 'False' , _EQUALS_TRUE )
190
229
191
230
# Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM.
192
- NAPALM_USERNAME = environ .get ('NAPALM_USERNAME' , '' )
193
- NAPALM_PASSWORD = _read_secret ('napalm_password' , environ .get ('NAPALM_PASSWORD' , '' ))
231
+ NAPALM_USERNAME = environ .get ('NAPALM_USERNAME' , None )
232
+ NAPALM_PASSWORD = _read_secret ('napalm_password' , environ .get ('NAPALM_PASSWORD' , None ))
194
233
195
234
# NAPALM timeout (in seconds). (Default: 30)
196
- NAPALM_TIMEOUT = int ( environ . get ( 'NAPALM_TIMEOUT' , 30 ) )
235
+ NAPALM_TIMEOUT = _environ_get_and_map ( 'NAPALM_TIMEOUT' , None , _AS_INT )
197
236
198
- # NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
199
- # be provided as a dictionary.
200
- NAPALM_ARGS = {}
237
+ # # NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
238
+ # # be provided as a dictionary.
239
+ # NAPALM_ARGS = None
201
240
202
241
# Determine how many objects to display per page within a list. (Default: 50)
203
- PAGINATE_COUNT = int ( environ . get ( 'PAGINATE_COUNT' , 50 ) )
242
+ PAGINATE_COUNT = _environ_get_and_map ( 'PAGINATE_COUNT' , None , _AS_INT )
204
243
205
- # Enable installed plugins. Add the name of each plugin to the list.
206
- PLUGINS = []
244
+ # # Enable installed plugins. Add the name of each plugin to the list.
245
+ # PLUGINS = []
207
246
208
- # Plugins configuration settings. These settings are used by various plugins that the user may have installed.
209
- # Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
210
- PLUGINS_CONFIG = {
211
- }
247
+ # # Plugins configuration settings. These settings are used by various plugins that the user may have installed.
248
+ # # Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
249
+ # PLUGINS_CONFIG = {
250
+ # }
212
251
213
252
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
214
253
# prefer IPv4 instead.
215
- PREFER_IPV4 = environ .get ('PREFER_IPV4' , 'False' ).lower () == 'true'
254
+ PREFER_IPV4 = _environ_get_and_map ('PREFER_IPV4' , None , _EQUALS_TRUE )
255
+
256
+ # The default value for the amperage field when creating new power feeds.
257
+ POWERFEED_DEFAULT_AMPERAGE = _environ_get_and_map ('POWERFEED_DEFAULT_AMPERAGE' , None , _AS_INT )
258
+
259
+ # The default value (percentage) for the max_utilization field when creating new power feeds.
260
+ POWERFEED_DEFAULT_MAX_UTILIZATION = _environ_get_and_map ('POWERFEED_DEFAULT_MAX_UTILIZATION' , None , _AS_INT )
261
+
262
+ # The default value for the voltage field when creating new power feeds.
263
+ POWERFEED_DEFAULT_VOLTAGE = _environ_get_and_map ('POWERFEED_DEFAULT_VOLTAGE' , None , _AS_INT )
216
264
217
265
# Rack elevation size defaults, in pixels. For best results, the ratio of width to height should be roughly 10:1.
218
- RACK_ELEVATION_DEFAULT_UNIT_HEIGHT = int ( environ . get ( 'RACK_ELEVATION_DEFAULT_UNIT_HEIGHT' , 22 ) )
219
- RACK_ELEVATION_DEFAULT_UNIT_WIDTH = int ( environ . get ( 'RACK_ELEVATION_DEFAULT_UNIT_WIDTH' , 220 ) )
266
+ RACK_ELEVATION_DEFAULT_UNIT_HEIGHT = _environ_get_and_map ( 'RACK_ELEVATION_DEFAULT_UNIT_HEIGHT' , None , _AS_INT )
267
+ RACK_ELEVATION_DEFAULT_UNIT_WIDTH = _environ_get_and_map ( 'RACK_ELEVATION_DEFAULT_UNIT_WIDTH' , None , _AS_INT )
220
268
221
269
# Remote authentication support
222
- REMOTE_AUTH_ENABLED = environ . get ('REMOTE_AUTH_ENABLED' , 'False' ). lower () == 'true'
270
+ REMOTE_AUTH_ENABLED = _environ_get_and_map ('REMOTE_AUTH_ENABLED' , 'False' , _EQUALS_TRUE )
223
271
REMOTE_AUTH_BACKEND = environ .get ('REMOTE_AUTH_BACKEND' , 'netbox.authentication.RemoteUserBackend' )
224
272
REMOTE_AUTH_HEADER = environ .get ('REMOTE_AUTH_HEADER' , 'HTTP_REMOTE_USER' )
225
- REMOTE_AUTH_AUTO_CREATE_USER = environ .get ('REMOTE_AUTH_AUTO_CREATE_USER' , 'True' ).lower () == 'true'
226
- REMOTE_AUTH_DEFAULT_GROUPS = list (filter (None , environ .get ('REMOTE_AUTH_DEFAULT_GROUPS' , '' ).split (' ' )))
273
+ REMOTE_AUTH_AUTO_CREATE_USER = _environ_get_and_map ('REMOTE_AUTH_AUTO_CREATE_USER' , 'True' , _EQUALS_TRUE )
274
+ REMOTE_AUTH_DEFAULT_GROUPS = _environ_get_and_map ('REMOTE_AUTH_DEFAULT_GROUPS' , '' , _SPLIT_ON_SPACE )
275
+ # REMOTE_AUTH_DEFAULT_PERMISSIONS = {}
227
276
228
277
# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
229
278
# version check or use the URL below to check for release in the official NetBox repository.
230
- # https://api.github.com/repos/netbox-community/netbox/releases
231
279
RELEASE_CHECK_URL = environ .get ('RELEASE_CHECK_URL' , None )
280
+ # RELEASE_CHECK_URL = 'https://api.github.com/repos/netbox-community/netbox/releases'
232
281
233
282
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
234
283
# this setting is derived from the installed location.
235
284
REPORTS_ROOT = environ .get ('REPORTS_ROOT' , '/etc/netbox/reports' )
236
285
237
286
# Maximum execution time for background tasks, in seconds.
238
- RQ_DEFAULT_TIMEOUT = int ( environ . get ( 'RQ_DEFAULT_TIMEOUT' , 300 ) )
287
+ RQ_DEFAULT_TIMEOUT = _environ_get_and_map ( 'RQ_DEFAULT_TIMEOUT' , 300 , _AS_INT )
239
288
240
289
# The file path where custom scripts will be stored. A trailing slash is not needed. Note that the default value of
241
290
# this setting is derived from the installed location.
242
291
SCRIPTS_ROOT = environ .get ('SCRIPTS_ROOT' , '/etc/netbox/scripts' )
243
292
293
+ # The name to use for the csrf token cookie.
294
+ CSRF_COOKIE_NAME = environ .get ('CSRF_COOKIE_NAME' , 'csrftoken' )
295
+
296
+ # Cross-Site-Request-Forgery-Attack settings. If Netbox is sitting behind a reverse proxy, you might need to set the CSRF_TRUSTED_ORIGINS flag.
297
+ # Django 4.0 requires to specify the URL Scheme in this setting. An example environment variable could be specified like:
298
+ # CSRF_TRUSTED_ORIGINS=https://demo.netbox.dev http://demo.netbox.dev
299
+ CSRF_TRUSTED_ORIGINS = _environ_get_and_map ('CSRF_TRUSTED_ORIGINS' , '' , _SPLIT_ON_SPACE )
300
+
301
+ # The name to use for the session cookie.
302
+ SESSION_COOKIE_NAME = environ .get ('SESSION_COOKIE_NAME' , 'sessionid' )
303
+
244
304
# By default, NetBox will store session data in the database. Alternatively, a file path can be specified here to use
245
305
# local file storage instead. (This can be useful for enabling authentication on a standby instance with read-only
246
306
# database access.) Note that the user as which NetBox runs must have read and write permissions to this path.
0 commit comments