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

add an option 'Skip TLS verification' to Elasticsearch query runnner #4416

Closed
wants to merge 6 commits into from
Closed
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
18 changes: 13 additions & 5 deletions redash/query_runner/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ def configuration_schema(cls):
"type": "string",
"title": "Basic Auth Password",
},
"skip_tls_verification": {
"type": "boolean",
"title": "Skip TLS verification",
"default": False
}
},
"order": ["server", "basic_auth_user", "basic_auth_password"],
"order": ["server", "basic_auth_user", "basic_auth_password", "skip_tls_verification"],

"secret": ["basic_auth_password"],
"required": ["server"],
}
Expand Down Expand Up @@ -92,11 +98,13 @@ def __init__(self, configuration):
if basic_auth_user and basic_auth_password:
self.auth = HTTPBasicAuth(basic_auth_user, basic_auth_password)

self.tls_verification = not self.configuration.get("skip_tls_verification", False)

def _get_mappings(self, url):
mappings = {}
error = None
try:
r = requests.get(url, auth=self.auth)
r = requests.get(url, auth=self.auth, verify=self.tls_verification)
r.raise_for_status()

mappings = r.json()
Expand Down Expand Up @@ -342,7 +350,7 @@ def collect_aggregations(
def test_connection(self):
try:
r = requests.get(
"{0}/_cluster/health".format(self.server_url), auth=self.auth
"{0}/_cluster/health".format(self.server_url), auth=self.auth, verify=self.tls_verification
)
r.raise_for_status()
except requests.HTTPError as e:
Expand All @@ -366,7 +374,7 @@ def _execute_simple_query(
self, url, auth, _from, mappings, result_fields, result_columns, result_rows
):
url += "&from={0}".format(_from)
r = requests.get(url, auth=self.auth)
r = requests.get(url, auth=self.auth, verify=self.tls_verification)
r.raise_for_status()

raw_result = r.json()
Expand Down Expand Up @@ -483,7 +491,7 @@ def run_query(self, query, user):

logger.debug("Using URL: %s", url)
logger.debug("Using query: %s", query_dict)
r = requests.get(url, json=query_dict, auth=self.auth)
r = requests.get(url, json=query_dict, auth=self.auth, verify=self.tls_verification)
r.raise_for_status()
logger.debug("Result: %s", r.json())

Expand Down