11"""CLI/Commands - Retrieve authentication status."""
22
3- import os
4-
53import click
64
75from ...core import keyring
86from ...core .api .exceptions import ApiException
97from ...core .api .user import get_token_metadata , get_user_brief
108from .. import decorators , utils
11- from ..config import CredentialsReader
129from ..exceptions import handle_api_exceptions
1310from .main import main
1411
@@ -26,26 +23,17 @@ def _get_active_method(api_config):
2623def _get_api_key_source (opts ):
2724 """Determine where the API key was loaded from.
2825
29- Checks in priority order matching actual resolution:
30- CLI --api-key flag > CLOUDSMITH_API_KEY env var > credentials.ini.
26+ Uses the credential provider chain result attached by initialise_api.
3127 """
32- if not opts .api_key :
33- return {"configured" : False , "source" : None , "source_key" : None }
34-
35- env_key = os .environ .get ("CLOUDSMITH_API_KEY" )
36-
37- # If env var is set but differs from the resolved key, CLI flag won
38- if env_key and opts .api_key != env_key :
39- source , key = "CLI --api-key flag" , "cli_flag"
40- elif env_key :
41- suffix = env_key [- 4 :]
42- source , key = f"CLOUDSMITH_API_KEY env var (ends with ...{ suffix } )" , "env_var"
43- elif creds := CredentialsReader .find_existing_files ():
44- source , key = f"credentials.ini ({ creds [0 ]} )" , "credentials_file"
45- else :
46- source , key = "CLI --api-key flag" , "cli_flag"
47-
48- return {"configured" : True , "source" : source , "source_key" : key }
28+ credential = getattr (opts , "credential" , None )
29+ if credential :
30+ return {
31+ "configured" : True ,
32+ "source" : credential .source_detail or credential .source_name ,
33+ "source_key" : credential .source_name ,
34+ }
35+
36+ return {"configured" : False , "source" : None , "source_key" : None }
4937
5038
5139def _get_sso_status (api_host ):
0 commit comments