6
6
# Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration.example.py
7
7
8
8
# Read secret from file
9
- def read_secret (secret_name ):
9
+ def read_secret (secret_name , default = '' ):
10
10
try :
11
11
f = open ('/run/secrets/' + secret_name , 'r' , encoding = 'utf-8' )
12
12
except EnvironmentError :
13
- return ''
13
+ return default
14
14
else :
15
15
with f :
16
16
return f .readline ().strip ()
@@ -33,7 +33,7 @@ def read_secret(secret_name):
33
33
DATABASE = {
34
34
'NAME' : os .environ .get ('DB_NAME' , 'netbox' ), # Database name
35
35
'USER' : os .environ .get ('DB_USER' , '' ), # PostgreSQL username
36
- 'PASSWORD' : os .environ .get ('DB_PASSWORD' , read_secret ( 'db_password ' )),
36
+ 'PASSWORD' : read_secret ( 'db_password' , os .environ .get ('DB_PASSWORD' , ' ' )),
37
37
# PostgreSQL password
38
38
'HOST' : os .environ .get ('DB_HOST' , 'localhost' ), # Database server
39
39
'PORT' : os .environ .get ('DB_PORT' , '' ), # Database port (leave blank for default)
@@ -47,7 +47,7 @@ def read_secret(secret_name):
47
47
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
48
48
# symbols. NetBox will not run without this defined. For more information, see
49
49
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
50
- SECRET_KEY = os .environ .get ('SECRET_KEY' , read_secret ( 'secret_key ' ))
50
+ SECRET_KEY = read_secret ( 'secret_key' , os .environ .get ('SECRET_KEY' , ' ' ))
51
51
52
52
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
53
53
REDIS = {
@@ -62,15 +62,15 @@ def read_secret(secret_name):
62
62
'webhooks' : { # legacy setting, can be removed after Netbox seizes support for it
63
63
'HOST' : os .environ .get ('REDIS_HOST' , 'localhost' ),
64
64
'PORT' : int (os .environ .get ('REDIS_PORT' , 6379 )),
65
- 'PASSWORD' : os .environ .get ('REDIS_PASSWORD' , read_secret ( 'redis_password ' )),
65
+ 'PASSWORD' : read_secret ( 'redis_password' , os .environ .get ('REDIS_PASSWORD' , ' ' )),
66
66
'DATABASE' : int (os .environ .get ('REDIS_DATABASE' , 0 )),
67
67
'DEFAULT_TIMEOUT' : int (os .environ .get ('REDIS_TIMEOUT' , 300 )),
68
68
'SSL' : os .environ .get ('REDIS_SSL' , 'False' ).lower () == 'true' ,
69
69
},
70
70
'caching' : {
71
71
'HOST' : os .environ .get ('REDIS_CACHE_HOST' , os .environ .get ('REDIS_HOST' , 'localhost' )),
72
72
'PORT' : int (os .environ .get ('REDIS_CACHE_PORT' , os .environ .get ('REDIS_PORT' , 6379 ))),
73
- 'PASSWORD' : os .environ .get ('REDIS_CACHE_PASSWORD' , os .environ .get ('REDIS_PASSWORD' , read_secret ( 'redis_cache_password' ))),
73
+ 'PASSWORD' : read_secret ( 'redis_cache_password' , os .environ .get ('REDIS_CACHE_PASSWORD' , read_secret ( 'redis_password' , os .environ .get ('REDIS_PASSWORD' , '' ) ))),
74
74
'DATABASE' : int (os .environ .get ('REDIS_CACHE_DATABASE' , 1 )),
75
75
'DEFAULT_TIMEOUT' : int (os .environ .get ('REDIS_CACHE_TIMEOUT' , os .environ .get ('REDIS_TIMEOUT' , 300 ))),
76
76
'SSL' : os .environ .get ('REDIS_CACHE_SSL' , os .environ .get ('REDIS_SSL' , 'False' )).lower () == 'true' ,
@@ -124,7 +124,7 @@ def read_secret(secret_name):
124
124
'SERVER' : os .environ .get ('EMAIL_SERVER' , 'localhost' ),
125
125
'PORT' : int (os .environ .get ('EMAIL_PORT' , 25 )),
126
126
'USERNAME' : os .environ .get ('EMAIL_USERNAME' , '' ),
127
- 'PASSWORD' : os .environ .get ('EMAIL_PASSWORD' , read_secret ( 'email_password ' )),
127
+ 'PASSWORD' : read_secret ( 'email_password' , os .environ .get ('EMAIL_PASSWORD' , ' ' )),
128
128
'TIMEOUT' : int (os .environ .get ('EMAIL_TIMEOUT' , 10 )), # seconds
129
129
'FROM_EMAIL' : os .environ .get ('EMAIL_FROM' , '' ),
130
130
'USE_SSL' : os .environ .get ('EMAIL_USE_SSL' , 'False' ).lower () == 'true' ,
@@ -171,7 +171,7 @@ def read_secret(secret_name):
171
171
172
172
# Credentials that NetBox will use to access live devices.
173
173
NAPALM_USERNAME = os .environ .get ('NAPALM_USERNAME' , '' )
174
- NAPALM_PASSWORD = os .environ .get ('NAPALM_PASSWORD' , read_secret ( 'napalm_password ' ))
174
+ NAPALM_PASSWORD = read_secret ( 'napalm_password' , os .environ .get ('NAPALM_PASSWORD' , ' ' ))
175
175
176
176
# NAPALM timeout (in seconds). (Default: 30)
177
177
NAPALM_TIMEOUT = int (os .environ .get ('NAPALM_TIMEOUT' , 30 ))
0 commit comments