diff options
author | Alexandre Flament <alex@al-f.net> | 2021-10-02 12:21:02 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-10-02 16:54:11 +0200 |
commit | 430babca253369d82e864500118f914a9420f74b (patch) | |
tree | bed242205b23585a485911a344dd478dce6a6f76 /searx/settings_defaults.py | |
parent | e39a03cc61e9792afb34084fb4d9973a61deecea (diff) | |
download | searxng-430babca253369d82e864500118f914a9420f74b.tar.gz searxng-430babca253369d82e864500118f914a9420f74b.zip |
SearXNG: environment variables
Diffstat (limited to 'searx/settings_defaults.py')
-rw-r--r-- | searx/settings_defaults.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 62625b912..9284f3050 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -41,6 +41,17 @@ STR_TO_BOOL = { } _UNDEFINED = object() +# compatibility +SEARX_ENVIRON_VARIABLES = { + 'SEARX_DISABLE_ETC_SETTINGS': 'SEARXNG_DISABLE_ETC_SETTINGS', + 'SEARX_SETTINGS_PATH': 'SEARXNG_SETTINGS_PATH', + 'SEARX_DEBUG': 'SEARXNG_DEBUG', + 'SEARX_PORT': 'SEARXNG_PORT', + 'SEARX_BIND_ADDRESS': 'SEARXNG_BIND_ADDRESS', + 'SEARX_SECRET': 'SEARXNG_SECRET', +} + + class SettingsValue: """Check and update a setting value @@ -87,7 +98,6 @@ class SettingsValue: self.check_type_definition(value) return value - class SettingsDirectoryValue(SettingsValue): """Check and update a setting value that is a directory path """ @@ -124,8 +134,8 @@ def apply_schema(settings, schema, path_list): SCHEMA = { 'general': { - 'debug': SettingsValue(bool, False, 'SEARX_DEBUG'), - 'instance_name': SettingsValue(str, 'searxng'), + 'debug': SettingsValue(bool, False, 'SEARXNG_DEBUG'), + 'instance_name': SettingsValue(str, 'SearXNG'), 'contact_url': SettingsValue((None, False, str), None), }, 'brand': { @@ -144,9 +154,9 @@ SCHEMA = { 'formats': SettingsValue(list, OUTPUT_FORMATS), }, 'server': { - 'port': SettingsValue((int,str), 8888, 'SEARX_PORT'), - 'bind_address': SettingsValue(str, '127.0.0.1', 'SEARX_BIND_ADDRESS'), - 'secret_key': SettingsValue(str, environ_name='SEARX_SECRET'), + 'port': SettingsValue((int,str), 8888, 'SEARXNG_PORT'), + 'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'), + 'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'), 'base_url': SettingsValue((False, str), False), 'image_proxy': SettingsValue(bool, False), 'http_protocol_version': SettingsValue(('1.0', '1.1'), '1.0'), @@ -201,5 +211,11 @@ SCHEMA = { } def settings_set_defaults(settings): + # compatibility with searx variables + for searx, searxng in SEARX_ENVIRON_VARIABLES.items(): + if searx in os.environ and searxng not in os.environ: + os.environ[searxng] = os.environ[searx] + logger.warning('%s uses value from %s', searxng, searx) + apply_schema(settings, SCHEMA, []) return settings |