Skip to content

Commit bf38b18

Browse files
committed
asn: Check for database file existance and writability
fixes #2566
1 parent 90ab0d9 commit bf38b18

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Please refer to the [NEWS](NEWS.md) for a list of changes which have an affect o
2929
#### Experts
3030
- `intelmq.bots.experts.asn_lookup.expert`:
3131
- Print URLs to stdout only in verbose mode (PR#2591 by Sebastian Wagner).
32+
- Check for database file existence and writability (fixes #2566).
3233
- Use database path matching to installation type (PR#2606 by Sebastian Wagner).
3334
- `intelmq.bots.experts.fake.expert`: Use database path matching to installation type (PR#2606 by Sebastian Wagner).
3435

intelmq/bots/experts/asn_lookup/expert.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import re
99
import sys
1010
import bz2
11-
import pathlib
1211
import requests
12+
from pathlib import Path
1313

1414
from intelmq import VAR_STATE_PATH
1515
from intelmq.lib.bot import ExpertBot
@@ -41,6 +41,8 @@ def init(self):
4141
self.logger.error("Read 'bots/experts/asn_lookup/README' and "
4242
"follow the procedure.")
4343
self.stop()
44+
if not Path(self.database).is_file:
45+
raise ValueError('Database file does not exist or is not a file.')
4446

4547
def process(self):
4648
event = self.receive_message()
@@ -113,6 +115,12 @@ def update_database(cls, verbose=False):
113115
if pyasn is None:
114116
raise MissingDependencyError("pyasn")
115117

118+
for database_path in set(bots.values()):
119+
if not Path(database_path).is_file:
120+
raise ValueError('Database file does not exist or is not a file.')
121+
elif not os.access(database_path, os.W_OK):
122+
raise ValueError('Database file is not writeable.')
123+
116124
try:
117125
if verbose:
118126
print("Searching for the latest database update...")
@@ -160,7 +168,7 @@ def update_database(cls, verbose=False):
160168
prefixes = pyasn.mrtx.parse_mrt_file(archive, print_progress=False, skip_record_on_error=True)
161169

162170
for database_path in set(bots.values()):
163-
database_dir = pathlib.Path(database_path).parent
171+
database_dir = Path(database_path).parent
164172
database_dir.mkdir(parents=True, exist_ok=True)
165173
pyasn.mrtx.dump_prefixes_to_file(prefixes, database_path)
166174

0 commit comments

Comments
 (0)