This repository was archived by the owner on Sep 7, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ def create_app(package_name='avresearcher', settings_override=None):
2626
2727 app .config .from_object ('avresearcher.settings' )
2828 app .config .from_object (settings_override )
29+ _check_es_config (app .config )
2930 _validate (app .config )
3031
3132 if app .config ['DEBUG' ] and app .config ['SENTRY_DSN' ]:
@@ -57,6 +58,25 @@ def load_user(user_id):
5758 return app
5859
5960
61+ def _check_es_config (config ):
62+ # Check whether we have ES_SEARCH_CONFIG and ES_LOG_CONFIG.
63+ # If not, set it from the deprecated ES_{SEARCH,LOG}_{HOST,PORT} settings.
64+
65+ for estype in ["SEARCH" , "LOG" ]:
66+ es_config = "ES_%s_CONFIG" % estype
67+ if es_config not in config :
68+ host = "ES_%s_HOST" % estype
69+ port = "ES_%s_PORT" % estype
70+ if host not in config or port not in config :
71+ raise ValueError ("need either %s setting or %s and %s"
72+ % (es_config , host , port ))
73+
74+ config [es_config ] = {
75+ "hosts" : [config [host ]],
76+ "port" : config [port ],
77+ }
78+
79+
6080def _validate (config ):
6181 # Settings validation: should catch common settings.py/local_settings.py
6282 # mistakes. Add rules as needed.
Original file line number Diff line number Diff line change 33SECRET_KEY = ''
44
55# ElasticSearch instance that contains the document collection(s).
6- ES_SEARCH_CONFIG = {'hosts' : ['localhost' ], 'port' : 9200 }
6+ # ES_SEARCH_CONFIG = {'hosts': ['localhost'], 'port': 9200}
77
88# To connect to an Elasticsearch instance via a secure (HTTPS) connection,
99# use a setting like the following. This works for ES_LOG_CONFIG, too.
1515# 'verify_certs': True, 'ca_certs': certifi.where()}
1616
1717# ElasticSearch instance used to store usage logs (clicks, queries, etc.).
18+ # This has the same format as ES_SEARCH_CONFIG; use the following to use the
19+ # same host for logging:
20+ #ES_LOG_CONFIG = ES_SEARCH_CONFIG
21+ #ES_LOG_INDEX = 'avresearcherxl_logs'
1822# To disable logs, use:
19- # ES_LOG_CONFIG = None
20- ES_LOG_CONFIG = ES_SEARCH_CONFIG # Same instance that holds the collections.
21- ES_LOG_INDEX = 'avresearcherxl_logs'
23+ #ES_LOG_CONFIG = None
2224
2325# User database URI
2426SQLALCHEMY_DATABASE_URI = 'mysql://user:pass@host/db'
Original file line number Diff line number Diff line change 1- from avresearcher .app import _validate
1+ from avresearcher .app import _check_es_config , _validate
22
33from copy import deepcopy
44
5- from nose .tools import assert_raises
5+ from nose .tools import assert_equal , assert_in , assert_raises
66
77
88config = {
2424}
2525
2626
27+ def test_check_es_config ():
28+ assert_raises (ValueError , _check_es_config , config )
29+
30+ c = deepcopy (config )
31+ c ["ES_SEARCH_HOST" ] = "localhost"
32+ c ["ES_SEARCH_PORT" ] = 9200
33+ c ["ES_LOG_HOST" ] = "loghost"
34+ c ["ES_LOG_PORT" ] = 9200
35+ _check_es_config (c )
36+
37+ assert_in ("ES_SEARCH_CONFIG" , c )
38+ assert_equal (c ["ES_SEARCH_CONFIG" ], {"hosts" : ["localhost" ], "port" : 9200 })
39+ assert_in ("ES_LOG_CONFIG" , c )
40+ assert_equal (c ["ES_LOG_CONFIG" ], {"hosts" : ["loghost" ], "port" : 9200 })
41+
42+ # Allow ES_LOG_CONFIG = None
43+ c ["ES_LOG_CONFIG" ] = None
44+ _check_es_config (c )
45+
46+
2747def test_validate ():
2848 _validate (config )
2949
You can’t perform that action at this time.
0 commit comments