1+ from typing import Optional
12import logging
23from concurrent .futures import ThreadPoolExecutor
34from pathlib import Path
@@ -29,8 +30,13 @@ class Processor:
2930 plugin_id : str
3031 closed_map : list [str ]
3132
32- def __init__ (self , config : dict , ignore_last_run : bool = False ):
33- dburi = f'sqlite:///{ config ["mapping_database" ].get ("path" )} '
33+ def __init__ (self ,
34+ config : dict ,
35+ ignore_last_run : bool = False ,
36+ dburi : Optional [str ] = None ,
37+ ):
38+ if not dburi :
39+ dburi = f'sqlite:///{ config ["mapping_database" ].get ("path" )} '
3440
3541 # For situations where we will need to ignore the last_run variable,
3642 # This will pull it from the config, forcing the integration to use
@@ -124,7 +130,7 @@ def build_mapping_db_model(self,
124130 value = value [0 ]
125131 item [fields [key ]] = value
126132 # item = {fields[k]: v for k, v in issue.fields.items()}
127- item ['updated' ] = self .start_time
133+ item ['updated' ] = self .start_time . datetime
128134 item ['jira_id' ] = issue .key
129135 if not missing :
130136 log .debug (f'Adding { issue .key } to cache.' )
@@ -185,11 +191,11 @@ def upsert_task(self, s: Session, finding: dict) -> (int | None):
185191 # and return the jira issue id back to the caller.
186192 if sql :
187193 if finding .get ('integration_pid_updated' ) > self .last_run :
188- if sql .updated <= self .start_time :
194+ if arrow . get ( sql .updated , 'UTC' ) <= self .start_time :
189195 self .jira .api .issues .update (sql .jira_id ,
190196 fields = task .fields ,
191197 )
192- sql .updated = datetime .now ()
198+ sql .updated = datetime .utcnow ()
193199 s .commit ()
194200 log .info (f'Matched Task "{ sql .jira_id } " to '
195201 'SQL Cache and updated.' )
@@ -213,7 +219,7 @@ def upsert_task(self, s: Session, finding: dict) -> (int | None):
213219 if len (page .issues ) == 1 :
214220 sql = TaskMap (plugin_id = task .fields [self .plugin_id ],
215221 jira_id = page .issues [0 ].key ,
216- updated = datetime .now (),
222+ updated = datetime .utcnow (),
217223 )
218224 s .add (sql )
219225 s .commit ()
@@ -232,7 +238,7 @@ def upsert_task(self, s: Session, finding: dict) -> (int | None):
232238 resp = self .jira .api .issues .create (fields = task .fields )
233239 sql = TaskMap (plugin_id = task .fields [self .plugin_id ],
234240 jira_id = resp .key ,
235- updated = datetime .now ()
241+ updated = datetime .utcnow ()
236242 )
237243 s .add (sql )
238244 s .commit ()
@@ -271,7 +277,7 @@ def upsert_subtask(self,
271277 if sql :
272278 if not task .is_open :
273279 sql .is_open = task .is_open
274- sql .updated = datetime .now ()
280+ sql .updated = datetime .utcnow ()
275281 s .commit ()
276282 self .close_task (sql .jira_id )
277283 action = 'closed subtask'
@@ -313,7 +319,7 @@ def upsert_subtask(self,
313319 finding_id = task .fields [self .finding_id ],
314320 jira_id = page .issues [0 ].key ,
315321 is_open = task .is_open ,
316- updated = datetime .now (),
322+ updated = datetime .utcnow (),
317323 )
318324 s .add (sql )
319325 s .commit ()
@@ -341,7 +347,7 @@ def upsert_subtask(self,
341347 finding_id = task .fields [self .finding_id ],
342348 jira_id = resp .key ,
343349 is_open = task .is_open ,
344- updated = datetime .now (),
350+ updated = datetime .utcnow (),
345351 )
346352 s .add (sql )
347353 s .commit ()
@@ -419,11 +425,10 @@ def sync(self, cleanup: bool = True):
419425 """
420426 Tenable to Jira Synchronization method.
421427 """
422- self .start_time = datetime .now ()
423- ts = int (arrow .get (self .start_time ).timestamp ())
428+ self .start_time = arrow .utcnow ()
424429
425430 # Get the findings and the asset cleanup generators.
426- findings = self .tenable .get_generator ()
431+ findings = self .tenable .get_generator (self . start_time )
427432 asset_cleanup = self .tenable .get_asset_cleanup ()
428433
429434 # build the db cache
@@ -469,8 +474,8 @@ def sync(self, cleanup: bool = True):
469474 self .close_empty_tasks ()
470475
471476 # update the last_run timestamp with the time that we started the sync.
472- self .config ['tenable' ]['last_run' ] = ts
473- self .finished_time = datetime . now ()
477+ self .config ['tenable' ]['last_run' ] = int ( self . start_time . timestamp ())
478+ self .finished_time = arrow . utcnow ()
474479
475480 self .engine .dispose ()
476481 # Delete the mapping database.
0 commit comments