Skip to content

Commit

Permalink
fix opendistro related renaming for sql-cli (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongnansu authored May 4, 2021
1 parent 16a989c commit aee3a60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions sql-cli/src/opensearch_sql_cli/opensearch_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@


class OpenSearchConnection:
"""OpenSearchConnection instances are used to set up and maintain client to Elasticsearch cluster,
as well as send user's SQL query to Elasticsearch.
"""OpenSearchConnection instances are used to set up and maintain client to OpenSearch cluster,
as well as send user's SQL query to OpenSearch.
"""

def __init__(self, endpoint=None, http_auth=None, use_aws_authentication=False, query_language="sql"):
Expand Down Expand Up @@ -85,20 +85,20 @@ def get_aes_client(self):

return aes_client

def get_open_distro_client(self):
def get_opensearch_client(self):
ssl_context = self.ssl_context = create_ssl_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

open_distro_client = OpenSearch(
opensearch_client = OpenSearch(
[self.endpoint],
http_auth=self.http_auth,
verify_certs=False,
ssl_context=ssl_context,
connection_class=RequestsHttpConnection,
)

return open_distro_client
return opensearch_client

def is_sql_plugin_installed(self, opensearch_client):
self.plugins = opensearch_client.cat.plugins(params={"s": "component", "v": "true"})
Expand All @@ -110,7 +110,7 @@ def set_connection(self, is_reconnect=False):
logging.captureWarnings(True)

if self.http_auth:
opensearch_client = self.get_open_distro_client()
opensearch_client = self.get_opensearch_client()

elif self.use_aws_authentication:
opensearch_client = self.get_aes_client()
Expand Down
12 changes: 6 additions & 6 deletions sql-cli/tests/test_opensearch_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from src.opensearch_sql_cli.opensearch_connection import OpenSearchConnection

INVALID_ENDPOINT = "http://invalid:9200"
OPEN_DISTRO_ENDPOINT = "https://opedistro:9200"
OPENSEARCH_ENDPOINT = "https://opensearch:9200"
AES_ENDPOINT = "https://fake.es.amazonaws.com"
AUTH = ("username", "password")

Expand Down Expand Up @@ -118,10 +118,10 @@ def test_reconnection_exception(self):
assert test_executor.set_connection(True)

def test_select_client(self):
od_test_executor = OpenSearchConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH)
od_test_executor = OpenSearchConnection(endpoint=OPENSEARCH_ENDPOINT, http_auth=AUTH)
aes_test_executor = OpenSearchConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True)

with mock.patch.object(od_test_executor, "get_open_distro_client") as mock_od_client, mock.patch.object(
with mock.patch.object(od_test_executor, "get_opensearch_client") as mock_od_client, mock.patch.object(
OpenSearchConnection, "is_sql_plugin_installed", return_value=True
):
od_test_executor.set_connection()
Expand All @@ -134,13 +134,13 @@ def test_select_client(self):
mock_aes_client.assert_called()

def test_get_od_client(self):
od_test_executor = OpenSearchConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH)
od_test_executor = OpenSearchConnection(endpoint=OPENSEARCH_ENDPOINT, http_auth=AUTH)

with mock.patch.object(OpenSearch, "__init__", return_value=None) as mock_es:
od_test_executor.get_open_distro_client()
od_test_executor.get_opensearch_client()

mock_es.assert_called_with(
[OPEN_DISTRO_ENDPOINT], http_auth=AUTH, verify_certs=False, ssl_context=od_test_executor.ssl_context,
[OPENSEARCH_ENDPOINT], http_auth=AUTH, verify_certs=False, ssl_context=od_test_executor.ssl_context,
connection_class=RequestsHttpConnection
)

Expand Down

0 comments on commit aee3a60

Please sign in to comment.