@@ -168,6 +168,11 @@ def input_cli_config_file(self) -> str:
168168 """Generate path for the CLI config file."""
169169 return f"{ self .api_environment } .json"
170170
171+ @staticmethod
172+ def token_key_for_environment (api_environment : str ) -> str :
173+ """Build the keyring/debug token key for a given environment name."""
174+ return f"api_token_{ api_environment } "
175+
171176 def save (self , skip_keyring : bool = False ):
172177 """
173178 Save the credentials to keyring and URL to disk as a file.
@@ -185,7 +190,7 @@ def save(self, skip_keyring: bool = False):
185190 with open (
186191 os .path .join (default_config_dir , f"debug_creds_{ self .input_cli_config_file } " ), "w"
187192 ) as f :
188- json .dump ({f"api_token_ { self .api_environment } " : self .api_token }, f )
193+ json .dump ({self .token_key_for_environment ( self . api_environment ) : self .api_token }, f )
189194 else :
190195 if skip_keyring :
191196 return
@@ -198,7 +203,11 @@ def save(self, skip_keyring: bool = False):
198203 for candidate in candidates :
199204 if hasattr (candidate , "_get_new_password" ):
200205 candidate ._get_new_password = _bounded_get_new_password
201- keyring .set_password ("airflowctl" , f"api_token_{ self .api_environment } " , self .api_token ) # type: ignore[arg-type]
206+ keyring .set_password (
207+ "airflowctl" ,
208+ self .token_key_for_environment (self .api_environment ),
209+ self .api_token , # type: ignore[arg-type]
210+ )
202211 except (NoKeyringError , NotImplementedError ) as e :
203212 log .error (e )
204213 raise AirflowCtlKeyringException (
@@ -229,11 +238,13 @@ def load(self) -> Credentials:
229238 )
230239 with open (debug_creds_path ) as df :
231240 debug_credentials = json .load (df )
232- self .api_token = debug_credentials .get (f"api_token_{ self .api_environment } " )
241+ self .api_token = debug_credentials .get (
242+ self .token_key_for_environment (self .api_environment )
243+ )
233244 else :
234245 try :
235246 self .api_token = keyring .get_password (
236- "airflowctl" , f"api_token_ { self .api_environment } "
247+ "airflowctl" , self .token_key_for_environment ( self . api_environment )
237248 )
238249 except ValueError as e :
239250 # Incorrect keyring password
0 commit comments