1
1
import os
2
2
from enum import Enum
3
+ from logging import getLogger
3
4
from typing import Annotated
4
5
5
- from pydantic import Field , StringConstraints
6
+ from pydantic import AliasChoices , Field , StringConstraints
6
7
from pydantic_settings import BaseSettings , SettingsConfigDict
7
8
from snowflake .connector import SnowflakeConnection
8
9
from snowflake .connector import connect as _connect
9
10
11
+ logger = getLogger (__name__ )
12
+
10
13
11
14
class Authenticator (str , Enum ):
12
15
snowflake = "snowflake"
@@ -24,7 +27,7 @@ def __str__(self) -> str:
24
27
25
28
26
29
class SnowflakeSettings (BaseSettings ):
27
- model_config = SettingsConfigDict (env_prefix = "SNOWFLAKE_" )
30
+ model_config = SettingsConfigDict (env_prefix = "SNOWFLAKE_" , populate_by_name = True )
28
31
29
32
account : str = "snowflake-test"
30
33
user : str = "snowlfake"
@@ -33,7 +36,9 @@ class SnowflakeSettings(BaseSettings):
33
36
role : str = "snowlfake"
34
37
warehouse : str = "snowlfake"
35
38
authenticator : Authenticator | OktaDomain = Authenticator .snowflake
36
- schema_name : str | None = Field (default = None , validation_alias = "SNOWFLAKE_SCHEMA" )
39
+ schema_name : str | None = Field (
40
+ default = None , validation_alias = AliasChoices ("SNOWFLAKE_SCHEMA" )
41
+ )
37
42
private_key_file : str | None = None
38
43
private_key_password : str | None = None
39
44
application : str | None = None
@@ -47,8 +52,13 @@ def creds(self) -> dict[str, str | None]:
47
52
"role" : self .role ,
48
53
"warehouse" : self .warehouse ,
49
54
"authenticator" : str (self .authenticator ),
50
- "application" : self .application ,
51
55
}
56
+
57
+ if self .application is not None :
58
+ base_creds ["application" ] = self .application
59
+ else :
60
+ logger .warning ("No Snowflake application name provided!" )
61
+
52
62
if self .authenticator in (Authenticator .externalbrowser ):
53
63
return base_creds
54
64
if self .private_key_file is not None and os .path .exists (self .private_key_file ):
0 commit comments