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

Use headers instead of URL params for ClickHouse credentials #7255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions redash/query_runner/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ def _send_query(self, data, session_id=None, session_check=None):
timeout = self.configuration.get("timeout", 30)

params = {
"user": self.configuration.get("user", "default"),
"password": self.configuration.get("password", ""),
"database": self.configuration["dbname"],
"default_format": "JSON",
}

headers = {
"x-clickhouse-user": self.configuration.get("user", "default"),
"x-clickhouse-key": self.configuration.get("password", ""),
}

if session_id:
params["session_id"] = session_id
params["session_check"] = "1" if session_check else "0"
Expand All @@ -119,6 +122,7 @@ def _send_query(self, data, session_id=None, session_check=None):
timeout=timeout,
params=params,
verify=verify,
headers=headers,
)

if not r.ok:
Expand Down
9 changes: 7 additions & 2 deletions tests/query_runner/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ def test_send_single_query(self, post_request):
self.assertEqual(
kwargs["params"],
{
"user": "default",
"password": "",
"database": "system",
"default_format": "JSON",
},
)
self.assertEqual(
kwargs["headers"],
{
"x-clickhouse-user": "default",
"x-clickhouse-key": "",
},
)
self.assertEqual(kwargs["timeout"], 60)

@patch("requests.post")
Expand Down
Loading