Skip to content

Commit

Permalink
Merge branch 'release/v3.5.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
royrusso committed Nov 15, 2019
2 parents 9cf1177 + d627782 commit c82f055
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
4 changes: 2 additions & 2 deletions elastichq/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TestSettings(BaseSettings):
# static
HQ_SITE_URL = 'http://elastichq.org'
HQ_GH_URL = 'https://github.com/ElasticHQ/elasticsearch-HQ'
API_VERSION = 'v3.5.7'
API_VERSION = 'v3.5.12'

ES_TEST_INDEX_NAME = 'cars'

Expand Down Expand Up @@ -105,7 +105,7 @@ class ProdSettings(BaseSettings):
# static
HQ_SITE_URL = 'http://elastichq.org'
HQ_GH_URL = 'https://github.com/ElasticHQ/elasticsearch-HQ'
API_VERSION = '3.5.7'
API_VERSION = '3.5.12'
SERVER_NAME = None

# cluster settings: specific settings for each cluster and how HQ should handle it.
Expand Down
47 changes: 34 additions & 13 deletions elastichq/service/ConnectionService.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import requests
from requests.exceptions import ConnectionError

from elastichq.common.utils import string_to_bool
from elastichq.model import ClusterModel
from elastichq.service.persistence import ClusterDBService
from ..globals import CONNECTIONS, LOG, REQUEST_TIMEOUT
from ..vendor.elasticsearch import Elasticsearch
from ..vendor.elasticsearch import Elasticsearch, RequestsHttpConnection
from ..vendor.elasticsearch.connections import ConnectionNotFoundException


Expand Down Expand Up @@ -54,6 +55,8 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
:return:
"""
try:
verify_certs = string_to_bool(verify_certs)
enable_ssl = string_to_bool(enable_ssl)
LOG.info('Verify: ' + str(verify_certs))
LOG.info('Cert File: ' + str(ca_certs))

Expand All @@ -76,7 +79,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
if verify_certs is False:
LOG.info("Verify Certs is False")
response = requests.get(scheme + "://" + ip + ":" + port, auth=(username, password),
timeout=REQUEST_TIMEOUT, verify=verify_certs,
timeout=REQUEST_TIMEOUT, verify=False,
cert=client_cert_credentials)
else:
LOG.info("Verify Certs is True")
Expand All @@ -93,7 +96,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
if verify_certs is False:
LOG.info("Verify Certs is False")
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT,
verify=verify_certs, cert=client_cert_credentials)
verify=False, cert=client_cert_credentials)
else:
LOG.info("Verify Certs is True")
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT,
Expand All @@ -103,7 +106,7 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT)

if response.status_code == 401:
message = "Unable to create connection! Server returned 401 - UNAUTHORIZED: " + scheme + "://" + ip +\
message = "Unable to create connection! Server returned 401 - UNAUTHORIZED: " + scheme + "://" + ip + \
":" + port
raise ConnectionNotAuthorized(message=message)

Expand All @@ -112,20 +115,38 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
# SAVE to Connection Pools
if is_basic_auth is True:
if enable_ssl:
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=verify_certs, ca_certs=ca_certs,
version=content.get('version').get('number'), http_auth=(username, password),
client_cert=client_cert, client_key=client_key)
if verify_certs is False:
LOG.info("Verify Certs is False")
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=False,
version=content.get('version').get('number'),
http_auth=(username, password), connection_class=RequestsHttpConnection)
else:
LOG.info("Verify Certs is True")
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=ca_certs, ca_certs=ca_certs,
version=content.get('version').get('number'),
http_auth=(username, password),
client_cert=client_cert, client_key=client_key)

else:
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
version=content.get('version').get('number'), http_auth=(username, password))

else:
if enable_ssl:
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=verify_certs, ca_certs=ca_certs,
version=content.get('version').get('number'),
client_cert=client_cert, client_key=client_key)
if verify_certs is False:
LOG.info("Verify Certs is False")
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=False,
version=content.get('version').get('number'),
connection_class=RequestsHttpConnection)
else:
LOG.info("Verify Certs is False")
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
use_ssl=True, verify_certs=ca_certs, ca_certs=ca_certs,
version=content.get('version').get('number'),
client_cert=client_cert, client_key=client_key)
else:
conn = Elasticsearch(hosts=[scheme + "://" + ip + ":" + port], maxsize=5,
version=content.get('version').get('number'))
Expand Down Expand Up @@ -178,7 +199,7 @@ def get_connection(self, cluster_name, create_if_missing=True):
Interface for cluster connection pool object. If a connection does not exist, it will attempt to create it,
using what is stored in the database. If it cannot find the connection
or cannot create one from the database, it will throw a ConnectionNotFoundException
:param cluster_name:
:param cluster_name:
:param create_if_missing: Will create the connection in the connection pool AND the persistence layer if it
does not exist.
:return:
Expand Down
8 changes: 5 additions & 3 deletions example/docker-compose-local-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use this file to build from local source. Note you have to 'docker system prune -a' on code changes or 'docker-compose build'
# Sample docker-compose file that will allow for connecting ES and HQ between separate containers
# Note that the container_name (elasticsearch) is used as a default connection url in the HQ settings.
# For pushing from local: https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html
################################################################################################################

version: '3'
Expand All @@ -10,13 +11,14 @@ services:
build:
context: ../
dockerfile: Dockerfile
image: elasticsearch-hq:develop
container_name: elastichq
environment:
- HQ_DEFAULT_URL=http://elasticsearch:9200
- HQ_DEBUG=True
# - HQ_ENABLE_SSL=True
# - HQ_VERIFY_CERTS=False
# - HQ_CA_CERTS=/usr/local/share/ca-certificates/MYCA.crt
- HQ_ENABLE_SSL=True
- HQ_VERIFY_CERTS=False
- HQ_CA_CERTS=/usr/local/share/ca-certificates/MYCA.crt
ports:
- 5000:5000
networks:
Expand Down

0 comments on commit c82f055

Please sign in to comment.