Skip to content

Commit

Permalink
Merge branch 'release/v3.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
royrusso committed Oct 7, 2019
2 parents 5cb7889 + 8166b24 commit 87a3791
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 15 deletions.
10 changes: 10 additions & 0 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
default_enable_ssl = False
default_ca_certs = None
default_verify_certs = True
default_client_key = None
default_client_cert = None
default_url = 'http://localhost:9200'
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")

Expand All @@ -24,6 +26,8 @@
application.config['CA_CERTS'] = os.environ.get('HQ_CA_CERTS', default_ca_certs)
application.config['HQ_VERIFY_CERTS'] = os.environ.get('HQ_VERIFY_CERTS', default_verify_certs)
application.config['DEBUG'] = os.environ.get('HQ_DEBUG', default_debug)
application.config['CLIENT_KEY'] = os.environ.get('CLIENT_KEY', default_client_key)
application.config['CLIENT_CERT'] = os.environ.get('CLIENT_CERT', default_client_cert)

if os.environ.get('HQ_DEBUG') == 'True':
config = find_config('logger_debug.json')
Expand Down Expand Up @@ -51,13 +55,19 @@
'Path to CA file or directory [default %s]' % default_ca_certs)
parser.add_option("-v", "--verify_certs", default=default_verify_certs,
help='Set to False when using self-signed certs.')
parser.add_option("-x", "--client_cert", default=default_client_cert,
help='Set to path of the client cert file.')
parser.add_option("-X", "--client_key", default=default_client_key,
help='Set to path of the client key file.')

options, _ = parser.parse_args()

application.config['DEFAULT_URL'] = os.environ.get('HQ_DEFAULT_URL', options.url)
application.config['ENABLE_SSL'] = os.environ.get('HQ_ENABLE_SSL', options.enable_ssl)
application.config['CA_CERTS'] = os.environ.get('HQ_CA_CERTS', options.ca_certs)
application.config['VERIFY_CERTS'] = os.environ.get('HQ_VERIFY_CERTS', options.verify_certs)
application.config['CLIENT_KEY'] = os.environ.get('CLIENT_KEY', options.client_key)
application.config['CLIENT_CERT'] = os.environ.get('CLIENT_CERT', options.client_cert)

if is_gunicorn:
if options.debug:
Expand Down
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
8 changes: 7 additions & 1 deletion elastichq/api/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ def post(self):
enable_ssl = current_app.config.get('ENABLE_SSL', False)
ca_certs = current_app.config.get('CA_CERTS', None)
verify_certs = current_app.config.get('VERIFY_CERTS', None)
client_key = current_app.config.get('CLIENT_KEY', None)
client_cert = current_app.config.get('CLIENT_CERT', None)

print(client_key)
print(client_cert)
response = ConnectionService().create_connection(ip=params['ip'], port=params.get('port', "9200"),
scheme=scheme, username=params.get('username', None),
password=params.get('password', None),
fail_on_exception=True,
enable_ssl=enable_ssl, ca_certs=ca_certs,
verify_certs=verify_certs)
verify_certs=verify_certs,
client_key=client_key,
client_cert=client_cert)

schema = ClusterDTO(many=False)
result = schema.dump(response)
Expand Down
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.3'
API_VERSION = 'v3.5.4'

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.3'
API_VERSION = '3.5.4'
SERVER_NAME = None

# cluster settings: specific settings for each cluster and how HQ should handle it.
Expand Down
16 changes: 11 additions & 5 deletions elastichq/service/ConnectionService.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def ping(self, ip, port, scheme='http'):
return False

def create_connection(self, ip, port, scheme='http', username=None, password=None, fail_on_exception=False,
enable_ssl=False, ca_certs=None, verify_certs=True):
enable_ssl=False, ca_certs=None, verify_certs=True, client_cert=None, client_key=None):
"""
Creates a connection with a cluster and place the connection inside of a connection pool, using the cluster_name as an alias.
:param client_cert:
:param client_key:
:param verify_certs:
:param ip:
:param port:
Expand All @@ -60,17 +62,19 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
is_basic_auth = True
password = urllib.parse.unquote(password)

client_cert_credentials = None if client_cert is None or client_key is None else (client_cert, client_key)

# determine version first
if is_basic_auth is True:
if enable_ssl:
response = requests.get(scheme + "://" + ip + ":" + port, auth=(username, password),
timeout=REQUEST_TIMEOUT, verify=ca_certs)
timeout=REQUEST_TIMEOUT, verify=ca_certs, cert=client_cert_credentials)
else:
response = requests.get(scheme + "://" + ip + ":" + port, auth=(username, password),
timeout=REQUEST_TIMEOUT)
else:
if enable_ssl:
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT, verify=ca_certs)
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT, verify=ca_certs, cert=client_cert_credentials)
else:
response = requests.get(scheme + "://" + ip + ":" + port, timeout=REQUEST_TIMEOUT)

Expand All @@ -85,7 +89,8 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
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))
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))
Expand All @@ -94,7 +99,8 @@ def create_connection(self, ip, port, scheme='http', username=None, password=Non
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'))
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
2 changes: 2 additions & 0 deletions elastichq/static/commons.0c5d691bc33f1cc1a9c6.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 87a3791

Please sign in to comment.