Skip to content

Commit

Permalink
config: add elasticsearch config for openshift
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo authored and topless committed Jan 28, 2019
1 parent 268caea commit 8ccf233
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions invenio_app_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import absolute_import, print_function

import os
from datetime import timedelta

from flask import request
Expand Down Expand Up @@ -92,6 +93,38 @@ def _(x):
"""Identity function used to trigger string extraction."""
return x

def _parse_env_bool(var_name, default=None):
if str(os.environ.get(var_name)).lower() == 'true':
return True
elif str(os.environ.get(var_name)).lower() == 'false':
return False
return default

# Search
# ======
ELASTICSEARCH_HOST = os.environ.get('ELASTICSEARCH_HOST', 'localhost')
ELASTICSEARCH_PORT = int(os.environ.get('ELASTICSEARCH_PORT', '9200'))
ELASTICSEARCH_USER = os.environ.get('ELASTICSEARCH_USER')
ELASTICSEARCH_PASSWORD = os.environ.get('ELASTICSEARCH_PASSWORD')
ELASTICSEARCH_URL_PREFIX = os.environ.get('ELASTICSEARCH_URL_PREFIX', '')
ELASTICSEARCH_USE_SSL = _parse_env_bool('ELASTICSEARCH_USE_SSL')
ELASTICSEARCH_VERIFY_CERTS = _parse_env_bool('ELASTICSEARCH_VERIFY_CERTS')

es_host_params = {
'host': ELASTICSEARCH_HOST,
'port': ELASTICSEARCH_PORT,
}
if ELASTICSEARCH_USER and ELASTICSEARCH_PASSWORD:
es_host_params['http_auth'] = (ELASTICSEARCH_USER, ELASTICSEARCH_PASSWORD)
if ELASTICSEARCH_URL_PREFIX:
es_host_params['url_prefix'] = ELASTICSEARCH_URL_PREFIX
if ELASTICSEARCH_USE_SSL is not None:
es_host_params['use_ssl'] = ELASTICSEARCH_USE_SSL
if ELASTICSEARCH_VERIFY_CERTS is not None:
es_host_params['verify_certs'] = ELASTICSEARCH_VERIFY_CERTS

SEARCH_ELASTIC_HOSTS = [es_host_params]
"""Elasticsearch hosts configuration."""

# Rate limiting
# =============
Expand Down

0 comments on commit 8ccf233

Please sign in to comment.