Skip to content

Commit

Permalink
Use headers instead of URL params for credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnthe committed Jan 28, 2025
1 parent d03a2c4 commit 8fb45a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit 8fb45a7

Please sign in to comment.