Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Elasticsearch CA configurable #1250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/signals/apps/search/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: MPL-2.0
# Copyright (C) 2019 - 2021 Gemeente Amsterdam
from ssl import create_default_context

from django.apps import AppConfig


Expand All @@ -13,5 +15,9 @@ def ready(self):

from .settings import app_settings

ssl_context = None
if app_settings.CONNECTION['CA_BUNDLE']:
ssl_context = create_default_context(cafile=app_settings.CONNECTION['CA_BUNDLE'])

host = app_settings.CONNECTION['HOST'] or 'localhost'
connections.create_connection(hosts=[host, ])
connections.create_connection(hosts=[host, ], ssl_context=ssl_context)
3 changes: 2 additions & 1 deletion app/signals/apps/search/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CONNECTION=dict(
HOST='http://127.0.0.1:9200',
INDEX='signals',
CA_BUNDLE=None,
),
)

Expand All @@ -27,7 +28,7 @@ def user_settings(self):

def __getattr__(self, attr):
if attr not in self.defaults:
raise AttributeError('Invalid SEARCH setting: {}'.format(attr))
raise AttributeError('Cannot retrieve non-existing SEARCH setting: {}'.format(attr))

try:
val = self.user_settings[attr]
Expand Down
1 change: 1 addition & 0 deletions app/signals/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def is_super_user(user):
'CONNECTION': {
'HOST': os.getenv('ELASTICSEARCH_HOST', 'elastic-index.service.consul:9200'),
'INDEX': os.getenv('ELASTICSEARCH_INDEX', 'signals'),
'CA_BUNDLE': os.getenv('ELASTICSEARCH_CA_BUNDLE', None)
},
}

Expand Down