forked from zaclys/searxng
SearXNG: environment variables
This commit is contained in:
parent
e39a03cc61
commit
430babca25
2
Makefile
2
Makefile
|
@ -29,7 +29,7 @@ run: install
|
||||||
sleep 2 ; \
|
sleep 2 ; \
|
||||||
xdg-open http://127.0.0.1:8888/ ; \
|
xdg-open http://127.0.0.1:8888/ ; \
|
||||||
) &
|
) &
|
||||||
SEARX_DEBUG=1 ./manage pyenv.cmd python -m searx.webapp
|
SEARXNG_DEBUG=1 ./manage pyenv.cmd python -m searx.webapp
|
||||||
|
|
||||||
PHONY += install uninstall
|
PHONY += install uninstall
|
||||||
install uninstall:
|
install uninstall:
|
||||||
|
|
|
@ -74,7 +74,7 @@ Global Settings
|
||||||
instance_name: "SearXNG" # displayed name
|
instance_name: "SearXNG" # displayed name
|
||||||
contact_url: false # mailto:contact@example.com
|
contact_url: false # mailto:contact@example.com
|
||||||
|
|
||||||
``debug`` : ``$SEARX_DEBUG``
|
``debug`` : ``$SEARXNG_DEBUG``
|
||||||
Allow a more detailed log if you run SearXNG directly. Display *detailed* error
|
Allow a more detailed log if you run SearXNG directly. Display *detailed* error
|
||||||
messages in the browser too, so this must be deactivated in production.
|
messages in the browser too, so this must be deactivated in production.
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ Global Settings
|
||||||
directly using ``python searx/webapp.py``. Doesn't apply to SearXNG running on
|
directly using ``python searx/webapp.py``. Doesn't apply to SearXNG running on
|
||||||
Apache or Nginx.
|
Apache or Nginx.
|
||||||
|
|
||||||
``secret_key`` : ``$SEARX_SECRET``
|
``secret_key`` : ``$SEARXNG_SECRET``
|
||||||
Used for cryptography purpose.
|
Used for cryptography purpose.
|
||||||
|
|
||||||
``image_proxy`` :
|
``image_proxy`` :
|
||||||
|
|
|
@ -124,7 +124,7 @@ browser (:man:`xdg-open`)::
|
||||||
|
|
||||||
$ make run
|
$ make run
|
||||||
PYENV OK
|
PYENV OK
|
||||||
SEARX_DEBUG=1 ./manage.sh pyenv.cmd python ./searx/webapp.py
|
SEARXNG_DEBUG=1 ./manage.sh pyenv.cmd python ./searx/webapp.py
|
||||||
...
|
...
|
||||||
INFO:werkzeug: * Running on http://127.0.0.1:8888/ (Press CTRL+C to quit)
|
INFO:werkzeug: * Running on http://127.0.0.1:8888/ (Press CTRL+C to quit)
|
||||||
|
|
||||||
|
@ -210,15 +210,15 @@ by underline::
|
||||||
|
|
||||||
make search.checker.google_news
|
make search.checker.google_news
|
||||||
|
|
||||||
To see HTTP requests and more use SEARX_DEBUG::
|
To see HTTP requests and more use SEARXNG_DEBUG::
|
||||||
|
|
||||||
make SEARX_DEBUG=1 search.checker.google_news
|
make SEARXNG_DEBUG=1 search.checker.google_news
|
||||||
|
|
||||||
.. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
|
.. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
|
||||||
|
|
||||||
To filter out HTTP redirects (3xx_)::
|
To filter out HTTP redirects (3xx_)::
|
||||||
|
|
||||||
make SEARX_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
|
make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
|
||||||
...
|
...
|
||||||
Engine google news Checking
|
Engine google news Checking
|
||||||
https://news.google.com:443 "GET /search?q=life&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
|
https://news.google.com:443 "GET /search?q=life&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
|
||||||
|
|
2
manage
2
manage
|
@ -115,7 +115,7 @@ buildenv() {
|
||||||
export SEARX_SETTINGS_PATH
|
export SEARX_SETTINGS_PATH
|
||||||
(
|
(
|
||||||
set -e
|
set -e
|
||||||
SEARX_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \
|
SEARXNG_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \
|
||||||
| prefix_stdout "${_Blue}BUILDENV${_creset} "
|
| prefix_stdout "${_Blue}BUILDENV${_creset} "
|
||||||
)
|
)
|
||||||
return "${PIPESTATUS[0]}"
|
return "${PIPESTATUS[0]}"
|
||||||
|
|
|
@ -62,7 +62,7 @@ def logging_config_debug():
|
||||||
except ImportError:
|
except ImportError:
|
||||||
coloredlogs = None
|
coloredlogs = None
|
||||||
|
|
||||||
log_level = os.environ.get('SEARX_DEBUG_LOG_LEVEL', 'DEBUG')
|
log_level = os.environ.get('SEARXNG_DEBUG_LOG_LEVEL', 'DEBUG')
|
||||||
if coloredlogs and is_color_terminal():
|
if coloredlogs and is_color_terminal():
|
||||||
level_styles = {
|
level_styles = {
|
||||||
'spam': {'color': 'green', 'faint': True},
|
'spam': {'color': 'green', 'faint': True},
|
||||||
|
|
|
@ -41,6 +41,17 @@ STR_TO_BOOL = {
|
||||||
}
|
}
|
||||||
_UNDEFINED = object()
|
_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:
|
class SettingsValue:
|
||||||
"""Check and update a setting value
|
"""Check and update a setting value
|
||||||
|
@ -87,7 +98,6 @@ class SettingsValue:
|
||||||
self.check_type_definition(value)
|
self.check_type_definition(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class SettingsDirectoryValue(SettingsValue):
|
class SettingsDirectoryValue(SettingsValue):
|
||||||
"""Check and update a setting value that is a directory path
|
"""Check and update a setting value that is a directory path
|
||||||
"""
|
"""
|
||||||
|
@ -124,8 +134,8 @@ def apply_schema(settings, schema, path_list):
|
||||||
|
|
||||||
SCHEMA = {
|
SCHEMA = {
|
||||||
'general': {
|
'general': {
|
||||||
'debug': SettingsValue(bool, False, 'SEARX_DEBUG'),
|
'debug': SettingsValue(bool, False, 'SEARXNG_DEBUG'),
|
||||||
'instance_name': SettingsValue(str, 'searxng'),
|
'instance_name': SettingsValue(str, 'SearXNG'),
|
||||||
'contact_url': SettingsValue((None, False, str), None),
|
'contact_url': SettingsValue((None, False, str), None),
|
||||||
},
|
},
|
||||||
'brand': {
|
'brand': {
|
||||||
|
@ -144,9 +154,9 @@ SCHEMA = {
|
||||||
'formats': SettingsValue(list, OUTPUT_FORMATS),
|
'formats': SettingsValue(list, OUTPUT_FORMATS),
|
||||||
},
|
},
|
||||||
'server': {
|
'server': {
|
||||||
'port': SettingsValue((int,str), 8888, 'SEARX_PORT'),
|
'port': SettingsValue((int,str), 8888, 'SEARXNG_PORT'),
|
||||||
'bind_address': SettingsValue(str, '127.0.0.1', 'SEARX_BIND_ADDRESS'),
|
'bind_address': SettingsValue(str, '127.0.0.1', 'SEARXNG_BIND_ADDRESS'),
|
||||||
'secret_key': SettingsValue(str, environ_name='SEARX_SECRET'),
|
'secret_key': SettingsValue(str, environ_name='SEARXNG_SECRET'),
|
||||||
'base_url': SettingsValue((False, str), False),
|
'base_url': SettingsValue((False, str), False),
|
||||||
'image_proxy': SettingsValue(bool, False),
|
'image_proxy': SettingsValue(bool, False),
|
||||||
'http_protocol_version': SettingsValue(('1.0', '1.1'), '1.0'),
|
'http_protocol_version': SettingsValue(('1.0', '1.1'), '1.0'),
|
||||||
|
@ -201,5 +211,11 @@ SCHEMA = {
|
||||||
}
|
}
|
||||||
|
|
||||||
def settings_set_defaults(settings):
|
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, [])
|
apply_schema(settings, SCHEMA, [])
|
||||||
return settings
|
return settings
|
||||||
|
|
|
@ -35,12 +35,12 @@ def get_default_settings_path():
|
||||||
|
|
||||||
def get_user_settings_path():
|
def get_user_settings_path():
|
||||||
# find location of settings.yml
|
# find location of settings.yml
|
||||||
if 'SEARX_SETTINGS_PATH' in environ:
|
if 'SEARXNG_SETTINGS_PATH' in environ:
|
||||||
# if possible set path to settings using the
|
# if possible set path to settings using the
|
||||||
# enviroment variable SEARX_SETTINGS_PATH
|
# enviroment variable SEARXNG_SETTINGS_PATH
|
||||||
return check_settings_yml(environ['SEARX_SETTINGS_PATH'])
|
return check_settings_yml(environ['SEARXNG_SETTINGS_PATH'])
|
||||||
|
|
||||||
if environ.get('SEARX_DISABLE_ETC_SETTINGS', '').lower() in ('1', 'true'):
|
if environ.get('SEARXNG_DISABLE_ETC_SETTINGS', '').lower() in ('1', 'true'):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# if not, get it from searx code base or last solution from /etc/searx
|
# if not, get it from searx code base or last solution from /etc/searx
|
||||||
|
|
|
@ -2,11 +2,17 @@ import os
|
||||||
|
|
||||||
import aiounittest
|
import aiounittest
|
||||||
|
|
||||||
os.environ['SEARX_DEBUG'] = '1'
|
os.environ.pop('SEARX_DEBUG', None)
|
||||||
os.environ['SEARX_DEBUG_LOG_LEVEL'] = 'WARNING'
|
os.environ.pop('SEARX_DEBUG_LOG_LEVEL', None)
|
||||||
os.environ['SEARX_DISABLE_ETC_SETTINGS'] = '1'
|
os.environ.pop('SEARX_DISABLE_ETC_SETTINGS', None)
|
||||||
os.environ.pop('SEARX_SETTINGS_PATH', None)
|
os.environ.pop('SEARX_SETTINGS_PATH', None)
|
||||||
|
|
||||||
|
os.environ.pop('SEARXNG_SETTINGS_PATH', None)
|
||||||
|
|
||||||
|
os.environ['SEARXNG_DEBUG'] = '1'
|
||||||
|
os.environ['SEARXNG_DEBUG_LOG_LEVEL'] = 'WARNING'
|
||||||
|
os.environ['SEARXNG_DISABLE_ETC_SETTINGS'] = '1'
|
||||||
|
|
||||||
|
|
||||||
class SearxTestLayer:
|
class SearxTestLayer:
|
||||||
"""Base layer for non-robot tests."""
|
"""Base layer for non-robot tests."""
|
||||||
|
|
|
@ -35,10 +35,10 @@ class SearxRobotLayer():
|
||||||
# - debug mode: https://flask.palletsprojects.com/quickstart/#debug-mode
|
# - debug mode: https://flask.palletsprojects.com/quickstart/#debug-mode
|
||||||
# - Flask.run(..): https://flask.palletsprojects.com/api/#flask.Flask.run
|
# - Flask.run(..): https://flask.palletsprojects.com/api/#flask.Flask.run
|
||||||
|
|
||||||
os.environ['SEARX_DEBUG'] = '0'
|
os.environ['SEARXNG_DEBUG'] = '0'
|
||||||
|
|
||||||
# set robot settings path
|
# set robot settings path
|
||||||
os.environ['SEARX_SETTINGS_PATH'] = str(tests_path / 'robot' / 'settings_robot.yml')
|
os.environ['SEARXNG_SETTINGS_PATH'] = str(tests_path / 'robot' / 'settings_robot.yml')
|
||||||
|
|
||||||
# run the server
|
# run the server
|
||||||
self.server = subprocess.Popen( # pylint: disable=consider-using-with
|
self.server = subprocess.Popen( # pylint: disable=consider-using-with
|
||||||
|
@ -52,7 +52,7 @@ class SearxRobotLayer():
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.kill(self.server.pid, 9)
|
os.kill(self.server.pid, 9)
|
||||||
# remove previously set environment variable
|
# remove previously set environment variable
|
||||||
del os.environ['SEARX_SETTINGS_PATH']
|
del os.environ['SEARXNG_SETTINGS_PATH']
|
||||||
|
|
||||||
|
|
||||||
def run_robot_tests(tests):
|
def run_robot_tests(tests):
|
||||||
|
|
Loading…
Reference in New Issue