2
2
from __future__ import absolute_import
3
3
import configparser
4
4
from dataclasses import asdict
5
- from datetime import date
5
+ from datetime import date , datetime
6
6
from enum import Enum
7
7
import requests
8
8
import time
32
32
CLI_CONFIGURE_SAVE_TO_SYSTEM , CLI_CONFIGURE_PROXY_HOST_HELP , CLI_CONFIGURE_PROXY_PORT_HELP , CLI_CONFIGURE_PROXY_PROTOCOL_HELP , \
33
33
CLI_GENERATE_PATH
34
34
from .cli_util import SafetyCLICommand , SafetyCLILegacyGroup , SafetyCLILegacyCommand , SafetyCLISubGroup , SafetyCLIUtilityCommand , handle_cmd_exception
35
- from safety .constants import CONFIG_FILE_USER , CONFIG_FILE_SYSTEM , EXIT_CODE_VULNERABILITIES_FOUND , EXIT_CODE_OK , EXIT_CODE_FAILURE
35
+ from safety .constants import BAR_LINE , CONFIG_FILE_USER , CONFIG_FILE_SYSTEM , EXIT_CODE_VULNERABILITIES_FOUND , EXIT_CODE_OK , EXIT_CODE_FAILURE
36
36
from safety .errors import InvalidCredentialError , SafetyException , SafetyError
37
37
from safety .formatter import SafetyFormatter
38
38
from safety .models import SafetyCLI
53
53
54
54
LOG = logging .getLogger (__name__ )
55
55
56
- DEPRECATION_DATE = date (2024 , 6 , 1 )
57
- OLD_COMMAND = "check"
58
- NEW_COMMAND = "scan"
59
- BAR_LINE = "+===========================================================================================================================================================================================+"
60
-
61
56
def get_network_telemetry ():
62
57
import psutil
63
58
import socket
@@ -240,37 +235,47 @@ def inner(ctx, *args, **kwargs):
240
235
241
236
return inner
242
237
243
-
244
- def print_deprecation_message ():
238
+ def print_deprecation_message (
239
+ old_command : str ,
240
+ deprecation_date : datetime ,
241
+ new_command : Optional [str ] = None
242
+ ) -> None :
245
243
"""
246
- Print a formatted deprecation message for the 'check' command.
244
+ Print a formatted deprecation message for a command.
247
245
248
246
This function uses the click library to output a visually distinct
249
- message in the console, warning users about the deprecation of the
250
- 'check' command. It includes information about the deprecation date
251
- and suggests an alternative command to use.
247
+ message in the console, warning users about the deprecation of a
248
+ specified command. It includes information about the deprecation date
249
+ and suggests an alternative command to use, if provided .
252
250
253
251
The message is formatted with colors and styles for emphasis:
254
252
- Yellow for the border and general information
255
253
- Red for the 'DEPRECATED' label
256
- - Green for the suggestion of the new command
254
+ - Green for the suggestion of the new command (if provided)
257
255
258
- No parameters are required, and the function doesn't return any value.
256
+ Parameters:
257
+ - old_command (str): The name of the deprecated command.
258
+ - deprecation_date (datetime): The date when the command will no longer be supported.
259
+ - new_command (str, optional): The name of the alternative command to suggest. Default is None.
259
260
"""
260
261
click .echo ("\n " )
261
262
click .echo (click .style (BAR_LINE , fg = "yellow" , bold = True ))
262
263
click .echo ("\n " )
263
264
click .echo (click .style ("DEPRECATED: " , fg = "red" , bold = True ) +
264
- click .style (f"this command (`{ OLD_COMMAND } `) has been DEPRECATED, and will be unsupported beyond { DEPRECATION_DATE .strftime ('%d %B %Y' )} ." , fg = "yellow" , bold = True ))
265
- click .echo ("\n " )
266
- click .echo (click .style ("We highly encourage switching to the new " , fg = "green" ) +
267
- click .style (f"`{ NEW_COMMAND } `" , fg = "green" , bold = True ) +
268
- click .style (" command which is easier to use, more powerful, and can be set up to mimick check if required." , fg = "green" ))
265
+ click .style (f"this command (`{ old_command } `) has been DEPRECATED, and will be unsupported beyond { deprecation_date .strftime ('%d %B %Y' )} ." , fg = "yellow" , bold = True ))
266
+
267
+ if new_command :
268
+ click .echo ("\n " )
269
+ click .echo (click .style ("We highly encourage switching to the new " , fg = "green" ) +
270
+ click .style (f"`{ new_command } `" , fg = "green" , bold = True ) +
271
+ click .style (" command which is easier to use, more powerful, and can be set up to mimic the deprecated command if required." , fg = "green" ))
272
+
269
273
click .echo ("\n " )
270
274
click .echo (click .style (BAR_LINE , fg = "yellow" , bold = True ))
271
275
click .echo ("\n " )
272
276
273
277
278
+
274
279
@cli .command (cls = SafetyCLILegacyCommand , utility_command = True , help = CLI_CHECK_COMMAND_HELP )
275
280
@proxy_options
276
281
@auth_options (stage = False )
@@ -336,7 +341,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
336
341
save_json , save_html , apply_remediations ,
337
342
auto_remediation_limit , no_prompt , json_version ):
338
343
"""
339
- [underline][DEPRECATED][/underline] `check` has been replaced by the `scan` command, and will be unsupported beyond 1 May 2024.Find vulnerabilities at a target file or enviroment.
344
+ [underline][DEPRECATED][/underline] `check` has been replaced by the `scan` command, and will be unsupported beyond 1 June 2024.Find vulnerabilities at a target file or enviroment.
340
345
"""
341
346
LOG .info ('Running check command' )
342
347
@@ -345,7 +350,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
345
350
is_silent_output = output in silent_outputs
346
351
prompt_mode = bool (not non_interactive and not stdin and not is_silent_output ) and not no_prompt
347
352
kwargs = {'version' : json_version } if output == 'json' else {}
348
- print_deprecation_message ()
353
+ print_deprecation_message ("check" , date ( 2024 , 6 , 1 ), new_command = "scan" )
349
354
try :
350
355
packages = get_packages (files , stdin )
351
356
@@ -427,7 +432,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
427
432
announcements , vulns , remediations , full_report , packages , fixes )
428
433
429
434
safety .save_report (save_html , 'safety-report.html' , html_report )
430
- print_deprecation_message ()
435
+ print_deprecation_message ("check" , date ( 2024 , 6 , 1 ), new_command = "scan" )
431
436
if exit_code and found_vulns :
432
437
LOG .info ('Exiting with default code for vulnerabilities found' )
433
438
sys .exit (EXIT_CODE_VULNERABILITIES_FOUND )
@@ -478,6 +483,7 @@ def license(ctx, db, output, cache, files):
478
483
"""
479
484
Find the open source licenses used by your Python dependencies.
480
485
"""
486
+ print_deprecation_message ("license" , date (2024 , 6 , 1 ), new_command = None )
481
487
LOG .info ('Running license command' )
482
488
packages = get_packages (files , False )
483
489
licenses_db = {}
@@ -504,6 +510,7 @@ def license(ctx, db, output, cache, files):
504
510
output_report = SafetyFormatter (output = output ).render_licenses (announcements , filtered_packages_licenses )
505
511
506
512
click .secho (output_report , nl = True )
513
+ print_deprecation_message ("license" , date (2024 , 6 , 1 ), new_command = None )
507
514
508
515
509
516
@cli .command (cls = SafetyCLILegacyCommand , utility_command = True , help = CLI_GENERATE_HELP )
0 commit comments