Allow asn_lookup --update-database to create a missing database file - #2724
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
Fixes certtools#2689. update_database() rejected the database file whenever it didn't already exist ('Database file does not exist or is not a file.'), even though the actual write further down (pyasn.mrtx.dump_prefixes_to_file) creates the file fresh and already creates the parent directory if needed. This blocked the documented first-time setup: the file has to be pre-created with 'whatever content' before the update would even attempt to run. Sibling expert bots with the same 'download and cache a database' pattern (domain_suffix, domain_valid, maxmind_geoip, recordedfuture_iprisk, tor_nodes) don't have this pre-existence check at all. Only reject an existing path that isn't a plain file, or an existing file that isn't writeable; a missing file is left to be created by the update itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2689.
Bug
ASNLookupExpertBot.update_database()rejects the database file whenever it doesn't already exist:But the actual write further down (
pyasn.mrtx.dump_prefixes_to_file) creates the file fresh, and the parent directory is already created if needed (database_dir.mkdir(parents=True, exist_ok=True), right before the write). So this check blocks the documented first-time setup: as reported, the file has to be pre-created with "whatever content" before--update-databasewill even attempt to run.Sibling expert bots with the same "download and cache a database" pattern (
domain_suffix,domain_valid,maxmind_geoip,recordedfuture_iprisk,tor_nodes) don't have this pre-existence check at all —asn_lookupis the outlier.Fix
Only reject a path that already exists and isn't a plain file, or an existing file that isn't writeable. A missing file is left alone — it's created by the update itself.
Test plan
TestASNLookupUpdateDatabasewith three cases: a missing database file is now allowed through (reaches the mocked network step instead of raising), an existing unwritable file is still rejected, and an existing directory at the database path is still rejected.intelmq.lib.utilsimportsgrpandfcntlunconditionally, so the package doesn't import at all on native Windows) — CI should confirm the added tests pass.