mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-21 05:43:22 -07:00
- Allow users to set config values through environment variables.
- Fixes: https://github.com/Tautulli/Tautulli/issues/2309
This commit is contained in:
parent
76f6a2da6b
commit
27961e5282
1 changed files with 14 additions and 0 deletions
|
@ -487,6 +487,11 @@ class Config(object):
|
||||||
""" Cast any value in the config to the right type or use the default """
|
""" Cast any value in the config to the right type or use the default """
|
||||||
key, definition_type, section, ini_key, default = self._define(key)
|
key, definition_type, section, ini_key, default = self._define(key)
|
||||||
self.check_section(section)
|
self.check_section(section)
|
||||||
|
my_val = self._from_env(key, definition_type)
|
||||||
|
if my_val:
|
||||||
|
self._config[section][ini_key] = my_val
|
||||||
|
return my_val
|
||||||
|
|
||||||
try:
|
try:
|
||||||
my_val = definition_type(self._config[section][ini_key])
|
my_val = definition_type(self._config[section][ini_key])
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -494,6 +499,15 @@ class Config(object):
|
||||||
self._config[section][ini_key] = my_val
|
self._config[section][ini_key] = my_val
|
||||||
return my_val
|
return my_val
|
||||||
|
|
||||||
|
def _from_env(self, key, definition_type):
|
||||||
|
""" Get key from environment variables, if it exists """
|
||||||
|
val = os.environ.get(key)
|
||||||
|
try:
|
||||||
|
if val:
|
||||||
|
return definition_type(val)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
""" Make a copy of the stored config and write it to the configured file """
|
""" Make a copy of the stored config and write it to the configured file """
|
||||||
new_config = ConfigObj(encoding="UTF-8")
|
new_config = ConfigObj(encoding="UTF-8")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue