File tree Expand file tree Collapse file tree 4 files changed +29
-8
lines changed
Expand file tree Collapse file tree 4 files changed +29
-8
lines changed Original file line number Diff line number Diff line change 1313_CLI_CLIENT_NAME = 'cli'
1414
1515
16- def try_report_activation (
16+ def _get_client_and_version (
17+ plugin_app_name : Optional [str ], plugin_app_version : Optional [str ]
18+ ) -> tuple [str , str ]:
19+ return plugin_app_name or _CLI_CLIENT_NAME , plugin_app_version or __version__
20+
21+
22+ def should_report_cli_activation (
23+ plugin_app_name : Optional [str ] = None ,
24+ plugin_app_version : Optional [str ] = None ,
25+ ) -> bool :
26+ client , version = _get_client_and_version (plugin_app_name , plugin_app_version )
27+ return configuration_manager .get_last_reported_activation_version (client ) != version
28+
29+
30+ def report_cli_activation (
1731 cycode_client : 'CycodeClientBase' ,
1832 plugin_app_name : Optional [str ] = None ,
1933 plugin_app_version : Optional [str ] = None ,
@@ -23,8 +37,7 @@ def try_report_activation(
2337 Failures are swallowed — activation tracking is non-critical.
2438 """
2539 try :
26- client = plugin_app_name or _CLI_CLIENT_NAME
27- version = plugin_app_version or __version__
40+ client , version = _get_client_and_version (plugin_app_name , plugin_app_version )
2841
2942 if configuration_manager .get_last_reported_activation_version (client ) == version :
3043 return
Original file line number Diff line number Diff line change 11import typer
22
3+ from cycode .cli .apps .activation_manager import should_report_cli_activation , report_cli_activation
34from cycode .cli .apps .auth .auth_manager import AuthManager
45from cycode .cli .exceptions .handle_auth_errors import handle_auth_exception
56from cycode .cli .logger import logger
67from cycode .cli .models import CliResult
8+ from cycode .cli .utils .get_api_client import get_scan_cycode_client
79
810
911def auth_command (ctx : typer .Context ) -> None :
@@ -23,6 +25,12 @@ def auth_command(ctx: typer.Context) -> None:
2325 auth_manager = AuthManager ()
2426 auth_manager .authenticate ()
2527
28+ plugin_app_name = ctx .obj .get ('plugin_app_name' )
29+ plugin_app_version = ctx .obj .get ('plugin_app_version' )
30+ if should_report_cli_activation (plugin_app_name , plugin_app_version ):
31+ scan_client = get_scan_cycode_client (ctx )
32+ report_cli_activation (scan_client .scan_cycode_client , plugin_app_name , plugin_app_version )
33+
2634 result = CliResult (success = True , message = 'Successfully logged into cycode' )
2735 printer .print_result (result )
2836 except Exception as err :
Original file line number Diff line number Diff line change 55import click
66import typer
77
8- from cycode .cli .apps .activation_manager import try_report_activation
98from cycode .cli .apps .sca_options import (
109 GradleAllSubProjectsOption ,
1110 MavenSettingsFileOption ,
@@ -141,10 +140,6 @@ def scan_command(
141140 scan_client = get_scan_cycode_client (ctx )
142141 ctx .obj ['client' ] = scan_client
143142
144- plugin_app_name = ctx .obj .get ('plugin_app_name' )
145- plugin_app_version = ctx .obj .get ('plugin_app_version' )
146- try_report_activation (scan_client .scan_cycode_client , plugin_app_name , plugin_app_version )
147-
148143 # Get remote URL from current working directory
149144 remote_url = _try_get_git_remote_url (os .getcwd ())
150145
Original file line number Diff line number Diff line change 22from typing import TYPE_CHECKING
33
44from cycode import __version__
5+ from cycode .cli .apps .activation_manager import should_report_cli_activation , report_cli_activation
56from cycode .cli .apps .auth .auth_common import get_authorization_info
67from cycode .cli .apps .status .models import CliStatus , CliSupportedModulesStatus
78from cycode .cli .consts import PROGRAM_NAME
@@ -22,7 +23,11 @@ def get_cli_status(ctx: 'Context') -> CliStatus:
2223 supported_modules_status = CliSupportedModulesStatus ()
2324 if is_authenticated :
2425 try :
26+ plugin_app_name = ctx .obj .get ('plugin_app_name' )
27+ plugin_app_version = ctx .obj .get ('plugin_app_version' )
2528 client = get_scan_cycode_client (ctx )
29+ if should_report_cli_activation (plugin_app_name , plugin_app_version ):
30+ report_cli_activation (client .scan_cycode_client , plugin_app_name , plugin_app_version )
2631 supported_modules_preferences = client .get_supported_modules_preferences ()
2732
2833 supported_modules_status .secret_scanning = supported_modules_preferences .secret_scanning
You can’t perform that action at this time.
0 commit comments