Skip to content

Commit bd65cd6

Browse files
authored
fix: Use new auth method for SDK (#55)
1 parent 4a7cd1e commit bd65cd6

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ project_urls =
2626
[options]
2727
packages = find:
2828
install_requires =
29-
firebolt-sdk
29+
firebolt-sdk>=0.8.0
3030
sqlalchemy>=1.0.0
3131
python_requires = >=3.6
3232
package_dir =

src/firebolt_db/firebolt_dialect.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import firebolt.db as dbapi
77
import sqlalchemy.types as sqltypes
8+
from firebolt.client.auth import UsernamePassword
89
from firebolt.db import Cursor
910
from sqlalchemy.engine import Connection as AlchemyConnection
1011
from sqlalchemy.engine import ExecutionContext, default
@@ -101,24 +102,22 @@ def __init__(
101102
def dbapi(cls) -> ModuleType:
102103
return dbapi
103104

104-
# Build firebolt-sdk compatible connection arguments.
105-
# URL format : firebolt://username:password@host:port/db_name
106105
def create_connect_args(self, url: URL) -> Tuple[List, Dict]:
106+
"""
107+
Build firebolt-sdk compatible connection arguments.
108+
URL format : firebolt://username:password@host:port/db_name
109+
"""
110+
parameters = dict(url.query)
111+
# parameters are all passed as a string, we need to convert
112+
# bool flag to boolean for SDK compatibility
113+
token_cache_flag = bool(strtobool(parameters.pop("use_token_cache", "True")))
107114
kwargs = {
108115
"database": url.host or None,
109-
"username": url.username or None,
110-
"password": url.password or None,
116+
"auth": UsernamePassword(url.username, url.password, token_cache_flag),
111117
"engine_name": url.database,
112118
}
113-
parameters = dict(url.query)
114119
if "account_name" in parameters:
115120
kwargs["account_name"] = parameters.pop("account_name")
116-
if "use_token_cache" in parameters:
117-
# parameters are all passed as a string, we need to convert it
118-
# to boolean for SDK compatibility
119-
kwargs["use_token_cache"] = bool(
120-
strtobool(parameters.pop("use_token_cache"))
121-
)
122121
self._set_parameters = parameters
123122
# If URL override is not provided leave it to the sdk to determine the endpoint
124123
if "FIREBOLT_BASE_URL" in os.environ:

tests/unit/test_firebolt_dialect.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ def test_create_connect_args(self, dialect: FireboltDialect):
3838
with mock.patch.dict(os.environ, {"FIREBOLT_BASE_URL": "test_url"}):
3939
result_list, result_dict = dialect.create_connect_args(u)
4040
assert result_dict["engine_name"] == "test_engine_name"
41-
assert result_dict["username"] == "test_user@email"
42-
assert result_dict["password"] == "test_password"
41+
assert result_dict["auth"].username == "test_user@email"
42+
assert result_dict["auth"].password == "test_password"
43+
assert result_dict["auth"]._use_token_cache is True
4344
assert result_dict["database"] == "test_db_name"
4445
assert result_dict["api_endpoint"] == "test_url"
46+
assert "username" not in result_dict
47+
assert "password" not in result_dict
4548
assert result_list == []
4649
# No endpoint override
4750
with mock.patch.dict(os.environ, {}, clear=True):
@@ -74,10 +77,9 @@ def test_create_connect_args_token_cache(
7477
)
7578
u = url.make_url(connection_url)
7679
result_list, result_dict = dialect.create_connect_args(u)
77-
assert (
78-
"use_token_cache" in result_dict
79-
), "use_token_cache was not parsed correctly from connection string"
80-
assert result_dict["use_token_cache"] == expected
80+
assert result_dict["auth"].username == "test_user@email"
81+
assert result_dict["auth"].password == "test_password"
82+
assert result_dict["auth"]._use_token_cache == expected
8183
assert dialect._set_parameters == {"param1": "1", "param2": "2"}
8284

8385
def test_do_execute(

0 commit comments

Comments
 (0)