44
55from c42eventextractor import FileEventHandlers
66from c42eventextractor .extractors import FileEventExtractor
7- from py42 import debug_level
8- from py42 import settings
9- from py42 .sdk import SDK
107from py42 .sdk .file_event_query .cloud_query import Actor
118from py42 .sdk .file_event_query .device_query import DeviceUsername
129from py42 .sdk .file_event_query .event_query import Source
2219from code42cli .securitydata .logger_factory import get_error_logger
2320from code42cli .securitydata .options import ExposureType as ExposureTypeOptions
2421from code42cli .util import print_error , print_bold , is_interactive
22+ from code42cli .sdk_client import create_sdk
2523
2624_EXCEPTIONS_OCCURRED = False
2725
@@ -41,7 +39,7 @@ def extract(output_logger, args):
4139 store = _create_cursor_store (args , profile )
4240 filters = _get_filters (args , store )
4341 handlers = _create_event_handlers (output_logger , store )
44- sdk = _get_sdk (profile , args .is_debug_mode )
42+ sdk = create_sdk (profile , args .is_debug_mode )
4543 extractor = FileEventExtractor (sdk , handlers )
4644 _call_extract (extractor , filters , args )
4745 _handle_result ()
@@ -85,12 +83,12 @@ def _verify_begin_date_requirements(args, cursor_store):
8583def _begin_date_is_required (args , cursor_store ):
8684 if not args .is_incremental :
8785 return True
88- required = cursor_store is not None and cursor_store .get_stored_insertion_timestamp () is None
86+ is_required = cursor_store and cursor_store .get_stored_insertion_timestamp () is None
8987
9088 # Ignore begin date when is incremental mode, it is not required, and it was passed an argument.
91- if not required and args .begin_date :
89+ if not is_required and args .begin_date :
9290 args .begin_date = None
93- return required
91+ return is_required
9492
9593
9694def _verify_exposure_types (exposure_types ):
@@ -122,7 +120,9 @@ def _create_filters(args):
122120
123121def _get_event_timestamp_filter (args ):
124122 try :
125- return date_helper .create_event_timestamp_filter (args .begin_date , args .end_date )
123+ begin_date = args .begin_date .strip ().split (" " ) if args .begin_date else None
124+ end_date = args .end_date .strip ().split (" " ) if args .end_date else None
125+ return date_helper .create_event_timestamp_filter (begin_date , end_date )
126126 except ValueError as ex :
127127 print_error (str (ex ))
128128 exit (1 )
@@ -153,20 +153,6 @@ def handle_response(response):
153153 return handlers
154154
155155
156- def _get_sdk (profile , is_debug_mode ):
157- if is_debug_mode :
158- settings .debug_level = debug_level .DEBUG
159- try :
160- password = profile .get_password ()
161- return SDK .create_using_local_account (profile .authority_url , profile .username , password )
162- except Exception :
163- print_error (
164- u"Invalid credentials or host address. "
165- u"Verify your profile is set up correctly and that you are supplying the correct password."
166- )
167- exit (1 )
168-
169-
170156def _call_extract (extractor , filters , args ):
171157 if args .advanced_query :
172158 extractor .extract_advanced (args .advanced_query )
0 commit comments