Skip to content

Commit

Permalink
Fix handle empty dates. (#72)
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Russell <caroline@appthreat.dev>
  • Loading branch information
cerrussell authored Oct 10, 2023
1 parent b04f9ec commit 7226f3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "appthreat-vulnerability-db"
version = "5.5.0"
version = "5.5.1"
description = "AppThreat's vulnerability database and package search library with a built-in file based storage. OSV, CVE, GitHub, npm are the primary sources of vulnerabilities."
authors = [
{name = "Team AppThreat", email = "cloud@appthreat.com"},
Expand Down
27 changes: 21 additions & 6 deletions vdb/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def convert_time(time_str):
if isinstance(time_str, dict):
time_str = time_str["value"]
return convert_time(time_str)

return dt if dt else time_str
return dt or time_str


class Vulnerability(object):
Expand Down Expand Up @@ -582,6 +581,24 @@ def __init__(

def to_dict(self):
"""Convert the object to dict"""
source_update_time = None
source_orig_time = None
if type(self.source_update_time) is datetime:
source_update_time = self.source_update_time.strftime(
"%Y-%m-%dT%H:%M:%S"
)
else:
new_time = convert_time(self.source_update_time)
source_update_time = new_time.strftime("%Y-%m-%dT%H:%M:%S") if (
type(new_time) is datetime) else None
if type(self.source_orig_time) is datetime:
source_orig_time = self.source_orig_time.strftime(
"%Y-%m-%dT%H:%M:%S"
)
else:
new_time = convert_time(self.source_orig_time)
source_orig_time = new_time.strftime("%Y-%m-%dT%H:%M:%S") if (
type(new_time) is datetime) else None
return {
"id": self.id,
"problem_type": self.problem_type
Expand All @@ -596,10 +613,8 @@ def to_dict(self):
"long_description": self.long_description,
"related_urls": self.related_urls,
"effective_severity": str(self.effective_severity),
"source_update_time": convert_time(self.source_update_time).
strftime("%Y-%m-%dT%H:%M:%S"),
"source_orig_time": convert_time(self.source_orig_time).
strftime("%Y-%m-%dT%H:%M:%S"),
"source_update_time": source_update_time,
"source_orig_time": source_orig_time,
"matched_by": self.matched_by,
}

Expand Down

0 comments on commit 7226f3f

Please sign in to comment.