Skip to content

Commit 6ca9512

Browse files
committed
Make the config of updateable
Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
1 parent 0dd2c5b commit 6ca9512

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

vulnerabilities/data_source.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class InvalidConfigurationError(Exception):
7575

7676
@dataclasses.dataclass
7777
class DataSourceConfiguration:
78-
batch_size: int
78+
# batch_size: int
79+
pass
7980

8081

8182
class DataSource(ContextManager):
@@ -105,8 +106,9 @@ def __init__(
105106
:param config: Optional dictionary with subclass-specific configuration
106107
"""
107108
config = config or {}
109+
self.batch_size = batch_size
108110
try:
109-
self.config = self.__class__.CONFIG_CLASS(batch_size, **config)
111+
self.config = self.__class__.CONFIG_CLASS(**config)
110112
# These really should be declared in DataSourceConfiguration above but that would
111113
# prevent DataSource subclasses from declaring mandatory parameters (i.e. positional
112114
# arguments)
@@ -183,7 +185,7 @@ def batch_advisories(self, advisories: List[Advisory]) -> Set[Advisory]:
183185
advisories = advisories[:] # copy the list as we are mutating it in the loop below
184186

185187
while advisories:
186-
b, advisories = advisories[:self.config.batch_size], advisories[self.config.batch_size:]
188+
b, advisories = advisories[:self.batch_size], advisories[self.batch_size:]
187189
yield set(b)
188190

189191

vulnerabilities/import_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
2222
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2323

24+
import dataclasses
2425
import datetime
2526
import logging
2627
from typing import Dict
@@ -77,6 +78,7 @@ def run(self, cutoff_date: datetime.datetime = None) -> None:
7778
_process_updated_advisories(data_source)
7879

7980
self.importer.last_run = datetime.datetime.now(tz=datetime.timezone.utc)
81+
self.importer.data_source_cfg = dataclasses.asdict(data_source.config)
8082
self.importer.save()
8183

8284
logger.debug(f'Successfully finished import for {self.importer.name}.')

vulnerabilities/importers/rust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _load_advisories(self, files) -> Set[Advisory]:
6464
files = [f for f in files if not f.endswith('-0000.toml')] # skip temporary files
6565

6666
while files:
67-
batch, files = files[:self.config.batch_size], files[self.config.batch_size:]
67+
batch, files = files[:self.batch_size], files[self.batch_size:]
6868

6969
advisories = set()
7070

vulnerabilities/tests/test_import_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def updated_advisories(self):
4646

4747
def _yield_advisories(self, advisories):
4848
while advisories:
49-
b, advisories = advisories[:self.config.batch_size], advisories[self.config.batch_size:]
49+
b, advisories = advisories[:self.batch_size], advisories[self.batch_size:]
5050
yield b
5151

5252

0 commit comments

Comments
 (0)