From 53e6a19f90c125b8bfb99aa5da820d2525ef45b9 Mon Sep 17 00:00:00 2001 From: dlouseiro Date: Tue, 11 Jun 2024 13:39:09 +0200 Subject: [PATCH] Reapply "Use default authenticator from snowflake connector instead of None" This reverts commit 39bafbad0a86f26c52e2f861a10dc86519787fac. --- .../deserializers/snowflake_deserializer.py | 13 +++++++------ test/deserializers/test_snowflake_deserializer.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/diepvries/deserializers/snowflake_deserializer.py b/src/diepvries/deserializers/snowflake_deserializer.py index 8f7d6ea..1f8f1c7 100644 --- a/src/diepvries/deserializers/snowflake_deserializer.py +++ b/src/diepvries/deserializers/snowflake_deserializer.py @@ -5,9 +5,10 @@ from collections import defaultdict from dataclasses import asdict, dataclass from functools import cached_property -from typing import Dict, List, Literal, Optional, Type +from typing import Dict, List, Optional, Type from snowflake.connector import DictCursor, connect +from snowflake.connector.network import DEFAULT_AUTHENTICATOR from .. import TABLE_PREFIXES, FieldDataType, FixedPrefixLoggerAdapter, TableType from ..driving_key_field import DrivingKeyField @@ -32,15 +33,15 @@ class DatabaseConfiguration: warehouse: str account: str password: Optional[str] = None - authenticator: Optional[Literal["externalbrowser"]] = None + authenticator: Optional[str] = DEFAULT_AUTHENTICATOR def __post_init__(self): """Validate input for optional attributes.""" - if self.authenticator is None and not self.password: + if self.authenticator == DEFAULT_AUTHENTICATOR and not self.password: raise ValueError( - "Password was not provided. It is a mandatory attribute when an " - "authenticator is not specified. Empty passwords are only allowed " - "when `authenticator='externalbrowser'`." + f"Password was not provided. It is a mandatory attribute when the " + f"authenticator is not `{DEFAULT_AUTHENTICATOR}`. Empty passwords are " + f"only allowed when `authenticator='externalbrowser'`." ) diff --git a/test/deserializers/test_snowflake_deserializer.py b/test/deserializers/test_snowflake_deserializer.py index 141d2f6..73fb9c5 100644 --- a/test/deserializers/test_snowflake_deserializer.py +++ b/test/deserializers/test_snowflake_deserializer.py @@ -200,7 +200,7 @@ def test_deserialized_target_tables( def test_database_configuration_with_password_invalid_input(): - """Test `DatabaseConfiguration` without password nor an `authenticator`.""" + """Test `DatabaseConfiguration` - no password nor authenticator=externalbrowser.""" with pytest.raises(ValueError): _ = DatabaseConfiguration( database="some_db",