18
18
from code42cli .securitydata import date_helper as date_helper
19
19
from code42cli .securitydata .arguments .main import IS_INCREMENTAL_KEY
20
20
from code42cli .securitydata .arguments .search import SearchArguments
21
- from code42cli .securitydata .cursor_store import AEDCursorStore
21
+ from code42cli .securitydata .cursor_store import FileEventCursorStore
22
22
from code42cli .securitydata .logger_factory import get_error_logger
23
23
from code42cli .securitydata .options import ExposureType as ExposureTypeOptions
24
24
from code42cli .util import print_error , print_bold , is_interactive
@@ -37,15 +37,21 @@ def extract(output_logger, args):
37
37
args:
38
38
Command line args used to build up file event query filters.
39
39
"""
40
- handlers = _create_event_handlers (output_logger , args .is_incremental )
40
+ store = _create_cursor_store (args )
41
+ handlers = _create_event_handlers (output_logger , store )
41
42
profile = get_profile ()
42
43
sdk = _get_sdk (profile , args .is_debug_mode )
43
44
extractor = FileEventExtractor (sdk , handlers )
44
- _call_extract (extractor , args )
45
+ _call_extract (extractor , store , args )
45
46
_handle_result ()
46
47
47
48
48
- def _create_event_handlers (output_logger , is_incremental ):
49
+ def _create_cursor_store (args ):
50
+ if args .is_incremental :
51
+ return FileEventCursorStore ()
52
+
53
+
54
+ def _create_event_handlers (output_logger , cursor_store ):
49
55
handlers = FileEventHandlers ()
50
56
error_logger = get_error_logger ()
51
57
@@ -56,10 +62,9 @@ def handle_error(exception):
56
62
57
63
handlers .handle_error = handle_error
58
64
59
- if is_incremental :
60
- store = AEDCursorStore ()
61
- handlers .record_cursor_position = store .replace_stored_insertion_timestamp
62
- handlers .get_cursor_position = store .get_stored_insertion_timestamp
65
+ if cursor_store :
66
+ handlers .record_cursor_position = cursor_store .replace_stored_insertion_timestamp
67
+ handlers .get_cursor_position = cursor_store .get_stored_insertion_timestamp
63
68
64
69
def handle_response (response ):
65
70
response_dict = json .loads (response .text )
@@ -86,9 +91,9 @@ def _get_sdk(profile, is_debug_mode):
86
91
exit (1 )
87
92
88
93
89
- def _call_extract (extractor , args ):
94
+ def _call_extract (extractor , cursor_store , args ):
90
95
if not _determine_if_advanced_query (args ):
91
- _verify_begin_date (args . begin_date )
96
+ _verify_begin_date_requirements (args , cursor_store )
92
97
_verify_exposure_types (args .exposure_types )
93
98
filters = _create_filters (args )
94
99
extractor .extract (* filters )
@@ -116,23 +121,26 @@ def _verify_compatibility_with_advanced_query(key, val):
116
121
return True
117
122
118
123
119
- def _get_event_timestamp_filter (args ):
120
- try :
121
- return date_helper .create_event_timestamp_range (args .begin_date , args .end_date )
122
- except ValueError as ex :
123
- print_error (str (ex ))
124
- exit (1 )
125
-
126
-
127
- def _verify_begin_date (begin_date ):
128
- if not begin_date :
124
+ def _verify_begin_date_requirements (args , cursor_store ):
125
+ if _begin_date_is_required (args , cursor_store ) and not args .begin_date :
129
126
print_error (u"'begin date' is required." )
130
127
print (u"" )
131
128
print_bold (u"Try using '-b' or '--begin'. Use `-h` for more info." )
132
129
print (u"" )
133
130
exit (1 )
134
131
135
132
133
+ def _begin_date_is_required (args , cursor_store ):
134
+ if not args .is_incremental :
135
+ return True
136
+ required = cursor_store is not None and cursor_store .get_stored_insertion_timestamp () is None
137
+
138
+ # Ignore begin date when is incremental mode, it is not required, and it was passed an argument.
139
+ if not required and args .begin_date :
140
+ args .begin_date = None
141
+ return required
142
+
143
+
136
144
def _verify_exposure_types (exposure_types ):
137
145
if exposure_types is None :
138
146
return
@@ -143,13 +151,25 @@ def _verify_exposure_types(exposure_types):
143
151
exit (1 )
144
152
145
153
154
+ def _get_event_timestamp_filter (args ):
155
+ try :
156
+ return date_helper .create_event_timestamp_filter (args .begin_date , args .end_date )
157
+ except ValueError as ex :
158
+ print_error (str (ex ))
159
+ exit (1 )
160
+
161
+
146
162
def _handle_result ():
147
163
if is_interactive () and _EXCEPTIONS_OCCURRED :
148
164
print_error (u"View exceptions that occurred at [HOME]/.code42cli/log/code42_errors." )
149
165
150
166
151
167
def _create_filters (args ):
152
- filters = [_get_event_timestamp_filter (args )]
168
+ filters = []
169
+ event_timestamp_filter = _get_event_timestamp_filter (args )
170
+ if event_timestamp_filter :
171
+ filters .append (event_timestamp_filter )
172
+
153
173
not args .c42username or filters .append (DeviceUsername .eq (args .c42username ))
154
174
not args .actor or filters .append (Actor .eq (args .actor ))
155
175
not args .md5 or filters .append (MD5 .eq (args .md5 ))
0 commit comments