Skip to content

Commit d6fcce5

Browse files
committed
Support 'opensearch' as local host variation
Why these changes are being introduced: Previously, only the string 'localhost' would trigger the code path to setup an Opensearch connection to a locally running instance. This proved problematic when attempting to have a docker container (e.g. this TIM project) connect to another docker container (e.g. an Opensearch instance) because 'localhost' was pointing at the calling TIM container and could not see the other. By allowing the string 'opensearch' to also trigger the code path for a local connection, setting the host to 'opensearch', this allows using docker networks and/or container names where one container can make requests to opensearch on the host 'opensearch'. How this addresses that need: * both 'localhost' and 'opensearch' trigger a non SSL, non authenticated opensearch connection * this TIM project running as a container can access an Opensearch client on the 'opensearch' host Side effects of this change: * None; the simple string 'opensearch' would not resolve to an actual, AWS deployed Opensearch instance Relevant ticket(s): * None
1 parent 74a2377 commit d6fcce5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/test_opensearch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def test_configure_opensearch_client_for_localhost():
2525
assert str(result) == "<OpenSearch([{'host': 'localhost', 'port': '9200'}])>"
2626

2727

28+
def test_configure_opensearch_client_for_local_opensearch_host():
29+
result = tim_os.configure_opensearch_client("opensearch")
30+
assert str(result) == "<OpenSearch([{'host': 'opensearch', 'port': '9200'}])>"
31+
32+
2833
@mock.patch("boto3.session.Session")
2934
def test_configure_opensearch_client_for_aws(mocked_boto3_session): # noqa
3035
result = tim_os.configure_opensearch_client("fake-dev.us-east-1.es.amazonaws.com")

tim/opensearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def configure_opensearch_client(url: str) -> OpenSearch:
3434
Includes the appropriate AWS credentials configuration if the URL is not localhost.
3535
"""
3636
logger.info("OpenSearch request configurations: %s", REQUEST_CONFIG)
37-
if url == "localhost":
37+
if url in ["localhost", "opensearch"]:
3838
return OpenSearch(
3939
hosts=[{"host": url, "port": "9200"}],
4040
http_auth=("admin", "admin"),

0 commit comments

Comments
 (0)