Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich vdb file metadata #179

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions vdb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,45 @@ def print_results(results):
console.print(table)


def create_db_file_metadata(sources, cve_data_count, cve_index_count):
"""Method to create the vdb file metadata"""
metadata = {
"created_utc": datetime.now(tz=timezone.utc).isoformat(
timespec="seconds"
),
"cve_data_count": cve_data_count,
"cve_index_count": cve_index_count,
"sources": [s.__class__.__name__ for s in sources],
}
include_list = []
ignore_list = []
# Collect injected metadata from environment variables
for name, value in os.environ.items():
if value is None:
continue
if name.startswith("VDB_METADATA_"):
if value in ("true", "1"):
value = True
elif value in ("false", "0"):
value = False
metadata[name.replace("VDB_METADATA_", "").lower()] = value
elif name.startswith("VDB_IGNORE_") and value in ("true", "1"):
ignore_list.append(name.replace("VDB_IGNORE_", "").lower())
elif name.startswith("VDB_EXCLUDE_") and value in ("true", "1"):
ignore_list.append(name.replace("VDB_EXCLUDE_", "").lower())
elif name.startswith("VDB_INCLUDE_") and value in ("true", "1"):
include_list.append(name.replace("VDB_INCLUDE_", "").lower())
if include_list:
metadata["include_list"] = include_list
if ignore_list:
metadata["ignore_list"] = ignore_list
if os.getenv("NVD_START_YEAR"):
metadata["start_year"] = os.getenv("NVD_START_YEAR")
if os.getenv("GITHUB_PAGE_COUNT"):
metadata["github_page_count"] = os.getenv("GITHUB_PAGE_COUNT")
return metadata


def main():
"""Main function"""
args = build_args()
Expand Down Expand Up @@ -247,17 +286,9 @@ def main():
# Create metadata about the database
with open(config.VDB_METADATA_FILE, mode="w", encoding="utf-8") as meta_file:
json.dump(
{
"created_utc": datetime.now(tz=timezone.utc).isoformat(
timespec="seconds"
),
"cve_data_count": cve_data_count,
"cve_index_count": cve_index_count,
"sources": [s.__class__.__name__ for s in sources],
},
create_db_file_metadata(sources, cve_data_count, cve_index_count),
meta_file,
)

if args.search:
if db_lib.needs_update():
console.print(
Expand Down