Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elasticsearch): disable verification #1469

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Changed

- Google Big Query: A simple status check that validates the private key's format has been implemented
- Elasticsearch: Host verification has been disabled to tolerate strict network configurations

## [3.23.25] 2024-01-17

Expand Down
5 changes: 1 addition & 4 deletions tests/elasticsearch/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ def pytest_generate_tests(metafunc):


def test_connector(mocker):
class ElasticsearchMock:
def search(self, index, body):
return {'hits': {'hits': [{'_source': {'yo': 'la'}}]}}

module = 'toucan_connectors.elasticsearch.elasticsearch_connector'
mock_es = mocker.patch(f'{module}.Elasticsearch')
mock_es.return_value = ElasticsearchMock()
mock_es.return_value.search.return_value = {'hits': {'hits': [{'_source': {'yo': 'la'}}]}}

con = ElasticsearchConnector(
name='test',
Expand Down
8 changes: 8 additions & 0 deletions toucan_connectors/elasticsearch/elasticsearch_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def _retrieve_data(self, data_source: ElasticsearchDataSource) -> pd.DataFrame:
connection_params.append(h)

esclient = Elasticsearch(connection_params)
# We need to set this flag as some customers force auth and refuse the connection if no auth
# header is present. Elasticsearch-py accepts 401/403s
# (https://github.com/elastic/elasticsearch-py/blob/v7.17.6/elasticsearch/transport.py#L586),
# but not connection errors. In consequence, we set the flag to True, which means that we
# couldn't figure out wether we are talking to Elasticsearch or not due to an auth error:
# https://github.com/elastic/elasticsearch-py/blob/v7.17.6/elasticsearch/transport.py#L216.
# If we are indded not talking to Elasticsearch, the query will fail later on.
esclient.transport._verified_elasticsearch = True
response = getattr(esclient, data_source.search_method)(
index=data_source.index, body=data_source.body
)
Expand Down