44from cycode .cli .exceptions .custom_exceptions import AuthProcessError , HttpUnauthorizedError , NetworkError
55from cycode .cli .models import CliError , CliErrors , CliResult
66from cycode .cli .printers import ConsolePrinter
7+ from cycode .cli .sentry import add_breadcrumb , capture_exception
78from cycode .cli .user_settings .credentials_manager import CredentialsManager
9+ from cycode .cli .utils .jwt_utils import get_user_and_tenant_ids_from_access_token
810from cycode .cyclient import logger
911from cycode .cyclient .cycode_token_based_client import CycodeTokenBasedClient
1012
1517@click .pass_context
1618def auth_command (context : click .Context ) -> None :
1719 """Authenticates your machine."""
20+ add_breadcrumb ('auth' )
21+
1822 if context .invoked_subcommand is not None :
1923 # if it is a subcommand, do nothing
2024 return
@@ -37,9 +41,10 @@ def auth_command(context: click.Context) -> None:
3741@click .pass_context
3842def authorization_check (context : click .Context ) -> None :
3943 """Validates that your Cycode account has permission to work with the CLI."""
44+ add_breadcrumb ('check' )
45+
4046 printer = ConsolePrinter (context )
4147
42- passed_auth_check_res = CliResult (success = True , message = 'Cycode authentication verified' )
4348 failed_auth_check_res = CliResult (success = False , message = 'Cycode authentication failed' )
4449
4550 client_id , client_secret = CredentialsManager ().get_credentials ()
@@ -48,9 +53,21 @@ def authorization_check(context: click.Context) -> None:
4853 return
4954
5055 try :
51- if CycodeTokenBasedClient (client_id , client_secret ).get_access_token ():
52- printer .print_result (passed_auth_check_res )
56+ access_token = CycodeTokenBasedClient (client_id , client_secret ).get_access_token ()
57+ if not access_token :
58+ printer .print_result (failed_auth_check_res )
5359 return
60+
61+ user_id , tenant_id = get_user_and_tenant_ids_from_access_token (access_token )
62+ printer .print_result (
63+ CliResult (
64+ success = True ,
65+ message = 'Cycode authentication verified' ,
66+ data = {'user_id' : user_id , 'tenant_id' : tenant_id },
67+ )
68+ )
69+
70+ return
5471 except (NetworkError , HttpUnauthorizedError ):
5572 ConsolePrinter (context ).print_exception ()
5673
@@ -78,4 +95,6 @@ def _handle_exception(context: click.Context, e: Exception) -> None:
7895 if isinstance (e , click .ClickException ):
7996 raise e
8097
98+ capture_exception (e )
99+
81100 raise click .ClickException (str (e ))
0 commit comments