Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1969575

Browse files
authoredJul 6, 2022
adjust checkpoint filters when you want to retrieve all events (#380)
* adjust checkpoint filters when you want to retrieve all events * Bugfix: only returning 10,000 events on first run * move checkpoint None -> empty-string check to _get_all_file_events() * release prep 1.14.3
1 parent ddb86a7 commit 1969575

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed
 

‎CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11+
## 1.14.3 - 2022-07-06
12+
13+
### Fixed
14+
15+
- Bug where the `code42 security-data search` command using a checkpoint and only the `--include-non-exposure` filter resulted in invalid page tokens.
16+
- Bug where `code42 security-data search` would only return 10,000 events on the first search when using a new checkpoint.
17+
1118
## 1.14.2 - 2022-06-17
1219

1320
### Fixed

‎src/code42cli/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.14.2"
1+
__version__ = "1.14.3"

‎src/code42cli/click_ext/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from py42.exceptions import Py42ForbiddenError
1414
from py42.exceptions import Py42HTTPError
1515
from py42.exceptions import Py42InvalidEmailError
16+
from py42.exceptions import Py42InvalidPageTokenError
1617
from py42.exceptions import Py42InvalidPasswordError
1718
from py42.exceptions import Py42InvalidRuleOperationError
1819
from py42.exceptions import Py42InvalidUsernameError
@@ -84,6 +85,7 @@ def invoke(self, ctx):
8485
Py42UpdateClosedCaseError,
8586
Py42UsernameMustBeEmailError,
8687
Py42InvalidEmailError,
88+
Py42InvalidPageTokenError,
8789
Py42InvalidPasswordError,
8890
Py42InvalidUsernameError,
8991
Py42ActiveLegalHoldError,

‎src/code42cli/cmds/securitydata.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import datetime
21
from pprint import pformat
32

43
import click
@@ -478,13 +477,9 @@ def _construct_query(state, begin, end, saved_search, advanced_query, or_query):
478477

479478
if not state.search_filters:
480479
# if a checkpoint and _only_ --include-non-exposure is passed, the filter list will be empty, which isn't a
481-
# valid query, so in that case we want to fallback to a 90 day (max event age) date range. The checkpoint will
480+
# valid query, so in that case we want to fallback to retrieving all events. The checkpoint will
482481
# still cause the query results to only contain events after the checkpointed event.
483-
_90_days = datetime.datetime.utcnow() - datetime.timedelta(days=90)
484-
timestamp = convert_datetime_to_timestamp(_90_days)
485-
state.search_filters.append(
486-
create_time_range_filter(f.EventTimestamp, timestamp, None)
487-
)
482+
state.search_filters.append(RiskSeverity.exists())
488483
query = FileEventQuery(*state.search_filters)
489484
query.page_size = MAX_EVENT_PAGE_SIZE
490485
query.sort_direction = "asc"
@@ -493,6 +488,8 @@ def _construct_query(state, begin, end, saved_search, advanced_query, or_query):
493488

494489

495490
def _get_all_file_events(state, query, checkpoint=""):
491+
if checkpoint is None:
492+
checkpoint = ""
496493
try:
497494
response = state.sdk.securitydata.search_all_file_events(
498495
query, page_token=checkpoint

‎tests/cmds/test_securitydata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas
55
import py42.sdk.queries.fileevents.filters as f
66
import pytest
7+
from py42.exceptions import Py42InvalidPageTokenError
78
from py42.sdk.queries.fileevents.file_event_query import FileEventQuery
89
from py42.sdk.queries.fileevents.filters import RiskIndicator
910
from py42.sdk.queries.fileevents.filters import RiskSeverity
@@ -327,6 +328,17 @@ def test_search_and_send_to_when_advanced_query_passed_non_existent_filename_rai
327328
assert "Could not open file: not_a_file" in result.stdout
328329

329330

331+
@search_and_send_to_test
332+
def test_search_and_send_to_when_given_invalid_page_token_raises_error(
333+
runner, cli_state, custom_error, file_event_cursor_with_eventid_checkpoint, command
334+
):
335+
cli_state.sdk.securitydata.search_all_file_events.side_effect = (
336+
Py42InvalidPageTokenError(custom_error, TEST_FILE_EVENT_ID_2)
337+
)
338+
result = runner.invoke(cli, [*command, "--use-checkpoint", "test"], obj=cli_state)
339+
assert f'Invalid page token: "{TEST_FILE_EVENT_ID_2}"' in result.output
340+
341+
330342
@advanced_query_incompat_test_params
331343
def test_search_with_advanced_query_and_incompatible_argument_errors(
332344
runner, arg, cli_state

0 commit comments

Comments
 (0)
Please sign in to comment.