diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4fa2a5bb80..3717d8672e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -14,6 +14,7 @@ Changelog * Fix: Page system check for on_delete actions of ForeignKeys was throwing false positives when page class decends from an abstract class (Alejandro Giacometti) * Fixed a regression where form builder submissions containing a number field would fail with a JSON serialisation error * Fix: Resizing an image with a focal point equal to the image size would result in a divide-by-zero error + * Fix: Elasticsearch configuration now supports specifying HTTP authentication parameters as part of the URL, and defaults to ports 80 (HTTP) and 443 (HTTPS) if port number not specified 0.8.1 (05.11.2014) diff --git a/docs/releases/0.8.2.rst b/docs/releases/0.8.2.rst index 7d043e5416..41f980ed5a 100644 --- a/docs/releases/0.8.2.rst +++ b/docs/releases/0.8.2.rst @@ -18,3 +18,13 @@ Bug fixes * Page system check for on_delete actions of ForeignKeys was throwing false positives when page class decends from an abstract class (Alejandro Giacometti) * Fixed a regression where form builder submissions containing a number field would fail with a JSON serialisation error * Resizing an image with a focal point equal to the image size would result in a divide-by-zero error + * Elasticsearch configuration now supports specifying HTTP authentication parameters as part of the URL, and defaults to ports 80 (HTTP) and 443 (HTTPS) if port number not specified + + +Upgrade considerations +====================== + +Port number must be specified when running Elasticsearch on port 9200 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In previous versions, an Elasticsearch connection URL in ``WAGTAILSEARCH_BACKENDS`` without an explicit port number (e.g. ``http://localhost/``) would be treated as port 9200 (the Elasticsearch default) whereas the correct behaviour would be to use the default http/https port of 80/443. This behaviour has now been fixed, so sites running Elasticsearch on port 9200 must now specify this explicitly - e.g. ``http://localhost:9200``. (Projects using the default settings, or the settings given in the Wagtail documentation, are unaffected.) diff --git a/wagtail/wagtailsearch/backends/elasticsearch.py b/wagtail/wagtailsearch/backends/elasticsearch.py index 6bdc06502a..02c17ab073 100644 --- a/wagtail/wagtailsearch/backends/elasticsearch.py +++ b/wagtail/wagtailsearch/backends/elasticsearch.py @@ -339,11 +339,19 @@ class ElasticSearch(BaseSearch): for url in self.es_urls: parsed_url = urlparse(url) + use_ssl = parsed_url.scheme == 'https' + port = parsed_url.port or (443 if use_ssl else 80) + + http_auth = None + if parsed_url.username is not None and parsed_url.password is not None: + http_auth = (parsed_url.username, parsed_url.password) + self.es_hosts.append({ 'host': parsed_url.hostname, - 'port': parsed_url.port or 9200, + 'port': port, 'url_prefix': parsed_url.path, - 'use_ssl': parsed_url.scheme == 'https', + 'use_ssl': use_ssl, + 'http_auth': http_auth, }) # Get ElasticSearch interface diff --git a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py index 5410e99430..b612f1ce3e 100644 --- a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py +++ b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py @@ -508,13 +508,29 @@ class TestBackendConfiguration(TestCase): def test_urls(self): # This test backwards compatibility with old URLS setting backend = self.ElasticSearch(params={ - 'URLS': ['http://localhost:12345', 'https://127.0.0.1:54321'], + 'URLS': [ + 'http://localhost:12345', + 'https://127.0.0.1:54321', + 'http://username:password@elasticsearch.mysite.com', + 'https://elasticsearch.mysite.com/hello', + ], }) - self.assertEqual(len(backend.es_hosts), 2) + self.assertEqual(len(backend.es_hosts), 4) self.assertEqual(backend.es_hosts[0]['host'], 'localhost') self.assertEqual(backend.es_hosts[0]['port'], 12345) self.assertEqual(backend.es_hosts[0]['use_ssl'], False) + self.assertEqual(backend.es_hosts[1]['host'], '127.0.0.1') self.assertEqual(backend.es_hosts[1]['port'], 54321) self.assertEqual(backend.es_hosts[1]['use_ssl'], True) + + self.assertEqual(backend.es_hosts[2]['host'], 'elasticsearch.mysite.com') + self.assertEqual(backend.es_hosts[2]['port'], 80) + self.assertEqual(backend.es_hosts[2]['use_ssl'], False) + self.assertEqual(backend.es_hosts[2]['http_auth'], ('username', 'password')) + + self.assertEqual(backend.es_hosts[3]['host'], 'elasticsearch.mysite.com') + self.assertEqual(backend.es_hosts[3]['port'], 443) + self.assertEqual(backend.es_hosts[3]['use_ssl'], True) + self.assertEqual(backend.es_hosts[3]['url_prefix'], '/hello')