Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Snowflake support private_key_passphrase #469

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions data_diff/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ def set_connection(self):
credentials, conn_type = self._get_connection_creds()

if conn_type == "snowflake":
if credentials.get("authenticator") is not None or credentials.get("private_key_passphrase") is not None:
raise Exception("Federated authentication and key/pair with passphrase is not yet supported for Snowflake.")
if credentials.get("authenticator") is not None:
raise Exception("Federated authentication is not yet supported for Snowflake.")
conn_info = {
"driver": conn_type,
"user": credentials.get("user"),
Expand All @@ -498,6 +498,7 @@ def set_connection(self):
if credentials.get("password") is not None:
raise Exception("Cannot use password and key at the same time")
conn_info["key"] = credentials.get("private_key_path")
conn_info["private_key_passphrase"] = credentials.get("private_key_passphrase")
elif credentials.get("password") is not None:
conn_info["password"] = credentials.get("password")
else:
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dsnparse = "*"
click = "^8.1"
rich = "*"
toml = "^0.10.2"
sqeleton = "^0.0.7"
sqeleton = "0.0.8"
mysql-connector-python = {version="8.0.29", optional=true}
psycopg2 = {version="*", optional=true}
snowflake-connector-python = {version="^2.7.2", optional=true}
Expand Down
27 changes: 16 additions & 11 deletions tests/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ def test_set_connection_snowflake_success_key(self):
self.assertEqual(mock_self.connection.get("key"), expected_credentials["private_key_path"])
self.assertEqual(mock_self.requires_upper, True)

def test_set_connection_snowflake_success_key_and_passphrase(self):
expected_driver = "snowflake"
expected_credentials = {"user": "user", "private_key_path": "private_key_path", "private_key_passphrase": "private_key_passphrase"}
mock_self = Mock()
mock_self._get_connection_creds.return_value = (expected_credentials, expected_driver)

DbtParser.set_connection(mock_self)

self.assertIsInstance(mock_self.connection, dict)
self.assertEqual(mock_self.connection.get("driver"), expected_driver)
self.assertEqual(mock_self.connection.get("user"), expected_credentials["user"])
self.assertEqual(mock_self.connection.get("password"), None)
self.assertEqual(mock_self.connection.get("key"), expected_credentials["private_key_path"])
self.assertEqual(mock_self.connection.get("private_key_passphrase"), expected_credentials["private_key_passphrase"])
self.assertEqual(mock_self.requires_upper, True)

def test_set_connection_snowflake_no_key_or_password(self):
expected_driver = "snowflake"
expected_credentials = {"user": "user"}
Expand Down Expand Up @@ -199,17 +215,6 @@ def test_set_connection_snowflake_key_and_password(self):

self.assertNotIsInstance(mock_self.connection, dict)

def test_set_connection_snowflake_private_key_passphrase(self):
expected_driver = "snowflake"
expected_credentials = {"user": "user", "private_key_passphrase": "private_key_passphrase"}
mock_self = Mock()
mock_self._get_connection_creds.return_value = (expected_credentials, expected_driver)

with self.assertRaises(Exception):
DbtParser.set_connection(mock_self)

self.assertNotIsInstance(mock_self.connection, dict)

def test_set_connection_bigquery_success(self):
expected_driver = "bigquery"
expected_credentials = {
Expand Down