Skip to content

Commit

Permalink
chg: use scan to generate dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Sep 26, 2023
1 parent a10f0b7 commit bed2016
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
43 changes: 23 additions & 20 deletions bin/dump.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
#!/usr/bin/env python3

import argparse
import json
import logging
from typing import Optional

import logging.config
import redis

from vulnerabilitylookup.default import AbstractManager
from vulnerabilitylookup.default import get_config, get_homedir
from vulnerabilitylookup import VulnerabilityLookup
from vulnerabilitylookup.default import get_config, get_homedir, safe_create_dir

logging.config.dictConfig(get_config('logging'))

host = get_config('generic', 'storage_db_hostname')
port = get_config('generic', 'storage_db_port')

r = redis.Redis(host=host, port=port, decode_responses=True)
class Dump():

parser = argparse.ArgumentParser(
description="Dump vulnerability-lookup storage in NDJSON."
)
def __init__(self):
self.vl = VulnerabilityLookup()
self.root_dumps = get_homedir() / 'dumps'
safe_create_dir(self.root_dumps)

parser.add_argument(
"--feed", help="Feed to dump. Default is set to nvd.", default="nvd"
)

args = parser.parse_args()

index = f"index:{args.feed}"
def dump(self, feed: str, /) -> None:
dest_file = self.root_dumps / f'{feed}.json'
dest_file.unlink(missing_ok=True)
for vuln in self.vl.get_all(feed):
with dest_file.open('a') as f:
json.dump(vuln, f)


def main():
for cve in r.smembers(index):
cve_json = r.get(str(cve))
print(f'{cve_json}')
parser = argparse.ArgumentParser(
description="Dump vulnerability-lookup storage in NDJSON."
)
parser.add_argument(
"--feed", help="Feed to dump. Default is set to nvd.", default="nvd"
)
args = parser.parse_args()
d = Dump()
d.dump(args.feed)


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ start_website = "bin.start_website:main"
nvd = "bin.nvd_fetcher:main"
gsd_importer = "bin.gsd:main"
github_importer = "bin.github:main"
dump = "bin.dump:main"

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
2 changes: 1 addition & 1 deletion storage/kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ max-bitmap-to-string-mb 16
# If enabled, the cursor will be unsigned 64-bit integers.
# If disabled, the cursor will be a string.
# Default: no
redis-cursor-compatible no
redis-cursor-compatible yes

################################## TLS ###################################

Expand Down
7 changes: 7 additions & 0 deletions vulnerabilitylookup/vulnerabilitylookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def get_last(self, source: Optional[str]=None, number: Optional[int]=30):
to_return.append(vuln)
return to_return

def get_all(self, source: str, /):
"""This method will scan a complete source and yield the vulnerabilities.
It is up to the caller to handle the yielded entries as it will be a lot"""
for vuln_id, _ in self.storage.zscan_iter(f'index:{source}'):
if vuln := self.get_vulnerability(vuln_id):
yield vuln

def get_vendors(self):
return self.storage.smembers('vendors')

Expand Down

0 comments on commit bed2016

Please sign in to comment.