@@ -54,19 +54,27 @@ def get_connect_args(self) -> Dict[str, Any]:
5454 connect_args : Dict [str , Union [str , bytes ]] = {}
5555 if config .private_key :
5656 config .private_key = config .private_key .replace ("\\ n" , "\n " )
57- connect_args ["private_key" ] = config .private_key
58- if config .private_key_passphrase :
59- private_key_encoded = serialization .load_pem_private_key (
60- config .private_key .encode (),
61- password = config .private_key_passphrase .encode (), # pylint: disable=no-member
62- backend = default_backend (),
63- )
64- private_key = private_key_encoded .private_bytes (
65- encoding = serialization .Encoding .DER ,
66- format = serialization .PrivateFormat .PKCS8 ,
67- encryption_algorithm = serialization .NoEncryption (),
68- )
69- connect_args ["private_key" ] = private_key
57+
58+ # Determine password (None if no passphrase)
59+ password = (
60+ config .private_key_passphrase .encode ()
61+ if config .private_key_passphrase
62+ else None
63+ )
64+
65+ # Load and convert the private key to DER/PKCS8 format
66+ # This is required by Snowflake connector regardless of passphrase
67+ private_key_encoded = serialization .load_pem_private_key (
68+ config .private_key .encode (),
69+ password = password ,
70+ backend = default_backend (),
71+ )
72+ private_key = private_key_encoded .private_bytes (
73+ encoding = serialization .Encoding .DER ,
74+ format = serialization .PrivateFormat .PKCS8 ,
75+ encryption_algorithm = serialization .NoEncryption (),
76+ )
77+ connect_args ["private_key" ] = private_key
7078 return connect_args
7179
7280 def query_config (self , node : ExecutionNode ) -> SnowflakeQueryConfig :
0 commit comments