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

Commit 7a49e67

Browse files
author
Matthias Ekundayo
committed
added exception handling for presto when auth=basic
1 parent 63ff6c3 commit 7a49e67

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

data_diff/databases/presto.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ def __init__(self, **kw):
4040
if kw.get("schema"):
4141
self.default_schema = kw.get("schema")
4242

43-
if (
44-
"password" in kw and "auth" in kw and kw.get("auth") == "basic"
45-
): # if auth=basic, add basic authenticator for Presto
46-
kw["auth"] = prestodb.auth.BasicAuthentication(kw.get("user"), kw.get("password"))
47-
kw.pop("password")
43+
try:
44+
# checks if user and password are missing when auth=basic
45+
kw.get("auth") == "basic" and "user" in kw and "password" in kw
46+
# if auth=basic, add basic authenticator for Presto
47+
kw["auth"] = prestodb.auth.BasicAuthentication(kw.pop("user"), kw.pop("password"))
48+
except:
49+
raise ValueError("User or password cannot be missing if auth==basic")
4850

4951
if "cert" in kw: # if a certificate was specified in URI, verify session with cert
50-
cert = kw.get("cert")
51-
kw.pop("cert")
52+
cert = kw.pop("cert")
53+
5254
self._conn = prestodb.dbapi.connect(**kw)
5355
self._conn._http_session.verify = cert
5456

data_diff/databases/snowflake.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,22 @@ def __init__(self, *, schema: str, **kw):
3838

3939
assert '"' not in schema, "Schema name should not contain quotes!"
4040
if (
41-
"password" not in kw and "key" in kw
42-
): # if private keys are used instead of password for Snowflake connection, read in key from path specified and pass as "private_key" to connector.
41+
"key" in kw
42+
): # if private keys are used for Snowflake connection, read in key from path specified and pass as "private_key" to connector.
4343
with open(kw.get("key"), "rb") as key:
44-
p_key = serialization.load_pem_private_key(key.read(), password=None, backend=default_backend())
44+
p_key = serialization.load_pem_private_key(
45+
key.read(),
46+
password=None if not kw.get("password") else kw.pop("password"),
47+
backend=default_backend(),
48+
)
4549

46-
pkb = p_key.private_bytes(
50+
kw["private_key"] = p_key.private_bytes(
4751
encoding=serialization.Encoding.DER,
4852
format=serialization.PrivateFormat.PKCS8,
4953
encryption_algorithm=serialization.NoEncryption(),
5054
)
51-
self._conn = snowflake.connector.connect(private_key=pkb, schema=f'"{schema}"', **kw) # replaces password
5255

53-
else: # otherwise use password for connection
54-
self._conn = snowflake.connector.connect(schema=f'"{schema}"', **kw)
56+
self._conn = snowflake.connector.connect(schema=f'"{schema}"', **kw)
5557

5658
self.default_schema = schema
5759

0 commit comments

Comments
 (0)