Skip to content

Commit

Permalink
Adds argument to print vdb metadata (#180)
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
  • Loading branch information
prabhu authored Jul 16, 2024
1 parent b5c93d3 commit e0e3ec8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ options:
--download-image Downloaded pre-created vdb image to platform specific user_data_dir. Application vulnerabilities only.
--download-full-image
Downloaded pre-created vdb image to platform specific user_data_dir. All vulnerabilities including OS.
--print-vdb-metadata Display metadata about the current vdb in user_data_dir.
```
### CLI search
Expand Down
23 changes: 23 additions & 0 deletions vdb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def build_args():
dest="download_full_image",
help="Downloaded pre-created vdb image to platform specific user_data_dir. All vulnerabilities including OS.",
)
parser.add_argument(
"--print-vdb-metadata",
action="store_true",
default=False,
dest="print_vdb_metadata",
help="Display metadata about the current vdb in user_data_dir.",
)
return parser.parse_args()


Expand Down Expand Up @@ -240,13 +247,28 @@ def create_db_file_metadata(sources, cve_data_count, cve_index_count):
return metadata


def print_db_file_metadata(metadata_file):
if not os.path.exists(metadata_file):
return
with open(metadata_file, encoding="utf-8") as fp:
db_meta = json.load(fp)
table = Table(title="VDB Summary", show_lines=True, caption=f"Metadata file: {metadata_file}")
table.add_column("Property")
table.add_column("Value")
for k, v in db_meta.items():
table.add_row(k, str(v))
console.print(table)


def main():
"""Main function"""
args = build_args()
print(AT_LOGO)
if args.clean:
if os.path.exists(config.DATA_DIR):
shutil.rmtree(config.DATA_DIR, ignore_errors=True)
if args.print_vdb_metadata:
print_db_file_metadata(config.VDB_METADATA_FILE)
if args.download_image or args.download_full_image:
db_url = config.VDB_DATABASE_URL if args.download_full_image else config.VDB_APP_ONLY_DATABASE_URL
if ORAS_AVAILABLE:
Expand All @@ -256,6 +278,7 @@ def main():
config.DATA_DIR,
)
download_image(db_url, config.DATA_DIR)
print_db_file_metadata(config.VDB_METADATA_FILE)
else:
console.print(
"Oras library is not available. Install using 'pip install appthreat-vulnerability-db[oras]' and re-run this command.",
Expand Down

0 comments on commit e0e3ec8

Please sign in to comment.