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 Username + Password Authentication for Trino Client (fixes #829) #1315

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 22 additions & 8 deletions querybook/server/lib/query_executor/clients/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(
self,
connection_string: str,
username: Optional[str] = None,
password: Optional[str] = None,
proxy_user: Optional[str] = None,
*args: Any,
**kwargs: Any,
Expand All @@ -61,14 +62,27 @@ def __init__(
host = trino_conf.host
port = 8080 if not trino_conf.port else trino_conf.port

connection = trino.dbapi.connect(
host=host,
port=port,
catalog=trino_conf.catalog,
schema=trino_conf.schema,
user=proxy_user or username,
http_scheme=trino_conf.protocol,
)
if username is not None and password is not None:
auth = trino.auth.BasicAuthentication(username, password)

connection = trino.dbapi.connect(
host=host,
port=port,
catalog=trino_conf.catalog,
schema=trino_conf.schema,
auth=auth,
user=proxy_user if proxy_user else username,
http_scheme=trino_conf.protocol,
)
else:
connection = trino.dbapi.connect(
host=host,
port=port,
catalog=trino_conf.catalog,
schema=trino_conf.schema,
user=proxy_user or username,
http_scheme=trino_conf.protocol,
)
rbb17 marked this conversation as resolved.
Show resolved Hide resolved
self._connection = connection
super(TrinoClient, self).__init__()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
),
),
("username", FormField(regex="\\w+")),
("impersonate", FormField(field_type=FormFieldType.Boolean)),
("password", FormField(hidden=True)),
(
"proxy_user_id",
FormField(
Expand Down