Skip to content

Commit e408e80

Browse files
authored
V1 file event deprecation warnings (#384)
* V1 file event deprecation warnings * add true arg to option
1 parent 8a0eace commit e408e80

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

docs/userguides/v2apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Use the `--use-v2-file-events True` option with the `code42 profile create` or `
1212

1313
Use `code42 profile show` to check the status of this setting on your profile:
1414
```bash
15-
% code42 profile update --use-v2-file-events
15+
% code42 profile update --use-v2-file-events True
1616

1717
% code42 profile show
1818

src/code42cli/cmds/securitydata.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
from code42cli.output_formats import DataFrameOutputFormatter
3636
from code42cli.output_formats import FileEventsOutputFormat
3737
from code42cli.output_formats import FileEventsOutputFormatter
38+
from code42cli.util import deprecation_warning
3839
from code42cli.util import warn_interrupt
3940

4041
logger = get_main_cli_logger()
4142
MAX_EVENT_PAGE_SIZE = 10000
43+
DEPRECATION_TEXT = "(DEPRECATED): V1 file events are deprecated. Update your profile with `code42 profile update --use-v2-file-events True` to use the new V2 file event data model."
44+
4245
SECURITY_DATA_KEYWORD = "file events"
4346

4447

@@ -60,7 +63,7 @@ def callback(ctx, param, arg):
6063
if arg:
6164
if ctx.obj.profile.use_v2_file_events == "False":
6265
raise Code42CLIError(
63-
"Event action (--event-action) filter is incompatible with V1 file events. Upgrade your profile to use the V2 file event data model with `code42 profile update --use-v2-file-events`"
66+
"Event action (--event-action) filter is incompatible with V1 file events. Upgrade your profile to use the V2 file event data model with `code42 profile update --use-v2-file-events True`"
6467
)
6568
ctx.obj.search_filters.append(v2_filters.event.Action.is_in(arg))
6669
return arg
@@ -406,6 +409,10 @@ def search(
406409
**kwargs,
407410
):
408411
"""Search for file events."""
412+
413+
if state.profile.use_v2_file_events != "True":
414+
deprecation_warning(DEPRECATION_TEXT)
415+
409416
if format == FileEventsOutputFormat.CEF and columns:
410417
raise click.BadOptionUsage(
411418
"columns", "--columns option can't be used with CEF format."
@@ -501,6 +508,9 @@ def send_to(
501508
502509
HOSTNAME format: address:port where port is optional and defaults to 514.
503510
"""
511+
if state.profile.use_v2_file_events != "True":
512+
deprecation_warning(DEPRECATION_TEXT)
513+
504514
if use_checkpoint:
505515
cursor = _get_file_event_cursor_store(state.profile.name)
506516
checkpoint = _handle_timestamp_checkpoint(cursor.get(use_checkpoint), state)
@@ -542,6 +552,9 @@ def saved_search(state):
542552
@sdk_options()
543553
def _list(state, format=None):
544554
"""List available saved searches."""
555+
if state.profile.use_v2_file_events != "True":
556+
deprecation_warning(DEPRECATION_TEXT)
557+
545558
formatter = DataFrameOutputFormatter(format)
546559
response = state.sdk.securitydata.savedsearches.get(
547560
use_v2=state.profile.use_v2_file_events == "True"
@@ -557,6 +570,9 @@ def _list(state, format=None):
557570
@sdk_options()
558571
def show(state, search_id):
559572
"""Get the details of a saved search."""
573+
if state.profile.use_v2_file_events != "True":
574+
deprecation_warning(DEPRECATION_TEXT)
575+
560576
response = state.sdk.securitydata.savedsearches.get_by_id(
561577
search_id, use_v2=state.profile.use_v2_file_events == "True"
562578
)
@@ -590,7 +606,12 @@ def _construct_query(state, begin, end, saved_search, advanced_query, or_query):
590606
# if a checkpoint and _only_ --include-non-exposure is passed, the filter list will be empty, which isn't a
591607
# valid query, so in that case we want to fallback to retrieving all events. The checkpoint will
592608
# still cause the query results to only contain events after the checkpointed event.
593-
state.search_filters.append(RiskSeverity.exists())
609+
severity_filter = (
610+
v2_filters.risk.Severity.exists()
611+
if state.profile.use_v2_file_events == "True"
612+
else RiskSeverity.exists()
613+
)
614+
state.search_filters.append(severity_filter)
594615

595616
# construct a v2 model query if profile setting enabled
596617
if state.profile.use_v2_file_events == "True":

tests/cmds/test_securitydata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ def test_event_action_raises_exception_when_called_with_v2_settings_disabled(
14761476
)
14771477
assert result.exit_code == 1
14781478
assert (
1479-
"Event action (--event-action) filter is incompatible with V1 file events. Upgrade your profile to use the V2 file event data model with `code42 profile update --use-v2-file-events`"
1479+
"Event action (--event-action) filter is incompatible with V1 file events. Upgrade your profile to use the V2 file event data model with `code42 profile update --use-v2-file-events True`"
14801480
in result.output
14811481
)
14821482

0 commit comments

Comments
 (0)