Skip to content

Commit

Permalink
Allow to pass in anonymous access. (amundsen-io#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
thoean authored and Zachary Ruiz committed May 13, 2022
1 parent b69bae9 commit 39b8651
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion search/search_service/proxy/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, *,
if client:
self.elasticsearch = client
else:
self.elasticsearch = Elasticsearch(host, http_auth=(user, password))
http_auth = (user, password) if user else None
self.elasticsearch = Elasticsearch(host, http_auth=http_auth)

self.page_size = page_size

Expand Down
24 changes: 24 additions & 0 deletions search/tests/unit/proxy/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ def test_setup_client(self) -> None:
self.assertEqual(client.transport.hosts[0]['host'], "0.0.0.0")
self.assertEqual(client.transport.hosts[0]['port'], 9200)

@patch('search_service.proxy.elasticsearch.Elasticsearch', autospec=True)
def test_setup_client_with_username_and_password(self, elasticsearch_mock) -> None:
self.es_proxy = ElasticsearchProxy(
host='http://unit-test-host',
user='unit-test-user',
password='unit-test-pass'
)

elasticsearch_mock.assert_called_once()
elasticsearch_mock.assert_called_once_with(
'http://unit-test-host',
http_auth=('unit-test-user', 'unit-test-pass')
)

@patch('search_service.proxy.elasticsearch.Elasticsearch', autospec=True)
def test_setup_client_without_username(self, elasticsearch_mock) -> None:
self.es_proxy = ElasticsearchProxy(
host='http://unit-test-host',
user=''
)

elasticsearch_mock.assert_called_once()
elasticsearch_mock.assert_called_once_with('http://unit-test-host', http_auth=None)

@patch('search_service.proxy._proxy_client', None)
def test_setup_config(self) -> None:
es: ElasticsearchProxy = get_proxy_client()
Expand Down

0 comments on commit 39b8651

Please sign in to comment.