@@ -139,15 +139,17 @@ def load(self) -> Credentials:
139139 """Load the credentials from keyring and URL from disk file."""
140140 default_config_dir = user_config_path ("airflow" , "Apache Software Foundation" )
141141 credential_path = os .path .join (default_config_dir , self .input_cli_config_file )
142- if os .path .exists (credential_path ) and self .client_kind == ClientKind .CLI :
143- with open (credential_path ) as f :
144- credentials = json .load (f )
145- self .api_url = credentials ["api_url" ]
146- self .api_token = keyring .get_password ("airflowctl" , f"api_token-{ self .api_environment } " )
142+ if os .path .exists (credential_path ):
143+ try :
144+ with open (credential_path ) as f :
145+ credentials = json .load (f )
146+ self .api_url = credentials ["api_url" ]
147+ self .api_token = keyring .get_password ("airflowctl" , f"api_token-{ self .api_environment } " )
148+ except FileNotFoundError :
149+ if self .client_kind == ClientKind .AUTH :
150+ # Saving the URL set from the Auth Commands if Kind is AUTH
151+ self .save ()
147152 return self
148- if self .client_kind == ClientKind .AUTH :
149- credentials = Credentials ()
150- return credentials
151153 raise AirflowCtlCredentialNotFoundException (f"No credentials found in { default_config_dir } " )
152154
153155
@@ -260,7 +262,7 @@ def version(self):
260262
261263# API Client Decorator for CLI Actions
262264@contextlib .contextmanager
263- def get_client (kind : ClientKind = ClientKind .CLI ):
265+ def get_client (kind : Literal [ ClientKind . CLI , ClientKind . AUTH ] = ClientKind .CLI ):
264266 """
265267 Get CLI API client.
266268
@@ -286,7 +288,7 @@ def get_client(kind: ClientKind = ClientKind.CLI):
286288
287289
288290def provide_api_client (
289- kind : ClientKind = ClientKind .CLI ,
291+ kind : Literal [ ClientKind . CLI , ClientKind . AUTH ] = ClientKind .CLI ,
290292) -> Callable [[Callable [PS , RT ]], Callable [PS , RT ]]:
291293 """
292294 Provide a CLI API Client to the decorated function.
0 commit comments