From 370a88295ee40513d4d634b32069b56407a3ce1e Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Tue, 18 Apr 2023 01:56:22 +0200 Subject: [PATCH 1/2] fix: return auth_type even if credentials are not in config Change `dbsqlcli.main.apply_credentials_from_cfg` to return 4 values even if `not cfg.get("credentials")` is true. This is so that the CLI can be used only with environment variables. - Fixes --- dbsqlcli/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbsqlcli/main.py b/dbsqlcli/main.py index 3672be7..41d5b4e 100644 --- a/dbsqlcli/main.py +++ b/dbsqlcli/main.py @@ -64,7 +64,7 @@ def apply_credentials_from_cfg(hostname, http_path, access_token, auth_type, cfg """ if not cfg.get("credentials"): - return hostname, http_path, access_token + return hostname, http_path, access_token, auth_type hostname = hostname or cfg.get("credentials", {}).get("host_name") http_path = http_path or cfg.get("credentials", {}).get("http_path") From bbc776aa534f2b7e6b4ad1d9da6953ef727bf31e Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Tue, 18 Apr 2023 22:21:07 +0000 Subject: [PATCH 2/2] add a test --- test/test_cli.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_cli.py b/test/test_cli.py index 4449dfa..d9e58f4 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -59,3 +59,14 @@ def test_blended_credentials_are_used(): assert http_path == HTTP_PATH assert access_token == "dapi_configRandomAccessKey" assert auth_type == AuthType.DATABRICKS_OAUTH.value + + +def test_passthrough_with_empty_config(): + host_name, http_path, access_token, auth_type = apply_credentials_from_cfg( + HOST_NAME, HTTP_PATH, ACCESS_TOKEN, AuthType.DATABRICKS_OAUTH.value, {} + ) + + assert host_name == HOST_NAME + assert http_path == HTTP_PATH + assert access_token == ACCESS_TOKEN + assert auth_type == AuthType.DATABRICKS_OAUTH.value