@@ -70,6 +70,53 @@ def get_all_connections(self) -> dict:
7070 """Get all connection configurations."""
7171 ...
7272
73+ def _transform_private_key_raw (self , connection_dict : dict ) -> dict :
74+ """
75+ Transform private_key_raw to private_key_file for ConnectionContext compatibility.
76+
77+ The ConnectionContext dataclass doesn't have a private_key_raw field, so it gets
78+ filtered out by merge_with_config. To work around this, we write private_key_raw
79+ content to a temporary file and return it as private_key_file.
80+
81+ Args:
82+ connection_dict: Connection configuration dictionary
83+
84+ Returns:
85+ Modified connection dictionary with private_key_raw transformed to private_key_file
86+ """
87+ if "private_key_raw" not in connection_dict :
88+ return connection_dict
89+
90+ # Don't transform if private_key_file is already set
91+ if "private_key_file" in connection_dict :
92+ return connection_dict
93+
94+ import os
95+ import tempfile
96+
97+ try :
98+ # Create a temporary file with the private key content
99+ with tempfile .NamedTemporaryFile (
100+ mode = "w" , suffix = ".pem" , delete = False
101+ ) as f :
102+ f .write (connection_dict ["private_key_raw" ])
103+ temp_file_path = f .name
104+
105+ # Set restrictive permissions on the temporary file
106+ os .chmod (temp_file_path , 0o600 )
107+
108+ # Create a copy of the connection dict with the transformation
109+ result = connection_dict .copy ()
110+ result ["private_key_file" ] = temp_file_path
111+ del result ["private_key_raw" ]
112+
113+ return result
114+
115+ except Exception :
116+ # If transformation fails, return original dict
117+ # The error will be handled downstream
118+ return connection_dict
119+
73120
74121class LegacyConfigProvider (ConfigProvider ):
75122 """
@@ -113,7 +160,8 @@ def read_config(self) -> None:
113160 def get_connection_dict (self , connection_name : str ) -> dict :
114161 from snowflake .cli .api .config import get_connection_dict
115162
116- return get_connection_dict (connection_name )
163+ result = get_connection_dict (connection_name )
164+ return self ._transform_private_key_raw (result )
117165
118166 def get_all_connections (self ) -> dict :
119167 from snowflake .cli .api .config import get_all_connections
@@ -377,7 +425,8 @@ def get_connection_dict(self, connection_name: str) -> dict:
377425 Returns:
378426 Dictionary of connection parameters
379427 """
380- return self ._get_connection_dict_internal (connection_name )
428+ result = self ._get_connection_dict_internal (connection_name )
429+ return self ._transform_private_key_raw (result )
381430
382431 def _get_all_connections_dict (self ) -> Dict [str , Dict [str , Any ]]:
383432 """
0 commit comments