Skip to content

Commit

Permalink
Add start_time to SARIF output (#440)
Browse files Browse the repository at this point in the history
The SARIF output currently shows only the end_time of an innovation.
This change will also add start_time. It also moves these times into the
run object.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb committed Apr 24, 2024
1 parent 1bfc918 commit 256db8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions precli/core/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2024 Secure Saurce LLC
import datetime
import io
import logging
import os
Expand Down Expand Up @@ -28,6 +29,8 @@ def __init__(
self._parsers = parsers
self._artifacts = artifacts
self._init_logger(debug)
self._start_time = None
self._endt_time = None

def _init_logger(self, log_level=logging.INFO):
"""Initialize the logger.
Expand All @@ -54,6 +57,8 @@ def tool(self) -> Tool:

def invoke(self):
"""Invokes a run"""
self._start_time = datetime.datetime.now(datetime.UTC)

# if we have problems with a file, we'll remove it from the file_list
# and add it to the skipped list instead
new_artifacts = list(self._artifacts)
Expand Down Expand Up @@ -98,6 +103,15 @@ def invoke(self):
notes=sum(result.level == Level.NOTE for result in results),
)
self._results = results
self._end_time = datetime.datetime.now(datetime.UTC)

@property
def start_time(self):
return self._start_time

@property
def end_time(self):
return self._end_time

def parse_file(
self,
Expand Down
4 changes: 2 additions & 2 deletions precli/renderers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pathlib
import sys
import urllib.parse as urlparse
from datetime import datetime

import sarif_om
from jschema_to_python.to_json import to_json
Expand Down Expand Up @@ -116,7 +115,8 @@ def render(self, run: Run):
tool=sarif_om.Tool(driver=self.create_tool_component(run)),
invocations=[
sarif_om.Invocation(
end_time_utc=datetime.utcnow().strftime(TS_FORMAT),
start_time_utc=run.start_time.strftime(TS_FORMAT),
end_time_utc=run.end_time.strftime(TS_FORMAT),
execution_successful=True,
)
],
Expand Down

0 comments on commit 256db8c

Please sign in to comment.