@@ -51,6 +51,12 @@ class ConnectionsPage(Page):
5151 "url" ,
5252 "http_path" ,
5353 ]
54+ encrypted_fields : typing .ClassVar [list [str ]] = [
55+ "project_pw_encrypted" ,
56+ "private_key" ,
57+ "private_key_passphrase" ,
58+ "service_account_key" ,
59+ ]
5460
5561 def render (self , project_code : str , ** _kwargs ) -> None :
5662 testgen .page_header (
@@ -95,25 +101,23 @@ def on_save_connection_clicked(updated_connection):
95101
96102 if updated_connection .get ("connect_by_key" ):
97103 updated_connection ["project_pw_encrypted" ] = ""
98- if is_pristine (updated_connection [ "private_key_passphrase" ] ):
104+ if is_pristine (updated_connection . get ( "private_key_passphrase" ) ):
99105 del updated_connection ["private_key_passphrase" ]
106+ elif updated_connection .get ("private_key_passphrase" ) == CLEAR_SENTINEL :
107+ updated_connection ["private_key_passphrase" ] = ""
108+
109+ if is_pristine (updated_connection .get ("private_key" )):
110+ del updated_connection ["private_key" ]
111+ else :
112+ updated_connection ["private_key" ] = base64 .b64decode (updated_connection ["private_key" ]).decode ()
100113 else :
101114 updated_connection ["private_key" ] = ""
102115 updated_connection ["private_key_passphrase" ] = ""
103116
104- if updated_connection .get ("private_key_passphrase" ) == CLEAR_SENTINEL :
105- updated_connection ["private_key_passphrase" ] = ""
106-
107- if is_pristine (updated_connection .get ("private_key" )):
108- del updated_connection ["private_key" ]
109- else :
110- updated_connection ["private_key" ] = base64 .b64decode (updated_connection ["private_key" ]).decode ()
111-
112- if is_pristine (updated_connection .get ("project_pw_encrypted" )):
113- del updated_connection ["project_pw_encrypted" ]
114-
115- if updated_connection .get ("project_pw_encrypted" ) == CLEAR_SENTINEL :
116- updated_connection ["project_pw_encrypted" ] = ""
117+ if is_pristine (updated_connection .get ("project_pw_encrypted" )):
118+ del updated_connection ["project_pw_encrypted" ]
119+ elif updated_connection .get ("project_pw_encrypted" ) == CLEAR_SENTINEL :
120+ updated_connection ["project_pw_encrypted" ] = ""
117121
118122 updated_connection ["sql_flavor" ] = self ._get_sql_flavor_from_value (updated_connection ["sql_flavor_code" ]).flavor
119123
@@ -204,6 +208,8 @@ def _sanitize_connection_input(self, connection: dict) -> dict:
204208 sanitized_value = value
205209 if isinstance (value , str ) and key in self .trim_fields :
206210 sanitized_value = value .strip ()
211+ if isinstance (value , str ) and key in self .encrypted_fields :
212+ sanitized_value = value if value != "" else None
207213 sanitized_connection_input [key ] = sanitized_value
208214 return sanitized_connection_input
209215
0 commit comments