Skip to content

Commit c4c4ea8

Browse files
committed
Use headers instead of URL params for credentials
1 parent d884da2 commit c4c4ea8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

redash/query_runner/clickhouse.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ def _send_query(self, data, session_id=None, session_check=None):
9999
timeout = self.configuration.get("timeout", 30)
100100

101101
params = {
102-
"user": self.configuration.get("user", "default"),
103-
"password": self.configuration.get("password", ""),
104102
"database": self.configuration["dbname"],
105103
"default_format": "JSON",
106104
}
107105

106+
headers = {
107+
"x-clickhouse-user": self.configuration.get("user", "default"),
108+
"x-clickhouse-key": self.configuration.get("password", ""),
109+
}
110+
108111
if session_id:
109112
params["session_id"] = session_id
110113
params["session_check"] = "1" if session_check else "0"
@@ -119,6 +122,7 @@ def _send_query(self, data, session_id=None, session_check=None):
119122
timeout=timeout,
120123
params=params,
121124
verify=verify,
125+
headers=headers,
122126
)
123127

124128
if not r.ok:

tests/query_runner/test_clickhouse.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ def test_send_single_query(self, post_request):
104104
self.assertEqual(
105105
kwargs["params"],
106106
{
107-
"user": "default",
108-
"password": "",
109107
"database": "system",
110108
"default_format": "JSON",
111109
},
112110
)
111+
self.assertEqual(
112+
kwargs["headers"],
113+
{
114+
"x-clickhouse-user": "default",
115+
"x-clickhouse-key": "",
116+
},
117+
)
113118
self.assertEqual(kwargs["timeout"], 60)
114119

115120
@patch("requests.post")

0 commit comments

Comments
 (0)