Refactor CPE imports and add NVDCPEHandler for JSON feeds#19
Merged
Conversation
Refactored the legacy XML CPE dictionary import logic into dedicated handler classes, introducing an abstract base class and an XML-specific implementation. Also added a downloader class, preparing the codebase for cleaner separation of responsibilities and future format support.
Reworked import.py to use the new cpeimport classes, moving the import logic into the library for better structure and reuse. Simplified CLI flags by removing the redundant --update option (inverse of --replace and previously mis-handled) and converting toggle flags to booleans.
Add a handler class for the new NVD CPE Dictionary 2.0 format, laying the foundation for importing JSON feeds alongside the legacy imports.
Use NVDCPEHandler for CPE data provided as tar archives or single JSON files, while XML files continue to use XMLCPEHandler. File-type detection is based naively on the file extension; providing the wrong content type will raise exceptions in the handlers.
Contributor
Author
Testing legacy
|
Also make the relative path compatible with README.md that suggests running 'python3 ./bin/import.py'.
10762f1 to
04f1824
Compare
All scripts in bin/ already have proper shebangs; add executable permissions so they can be run directly.
Keep the example of the legacy format as we still support it. Update copyright years.
04f1824 to
037795f
Compare
Member
|
Awesome! I'll do some tests and merge it if everything is fine. Thanks a lot. That's a great contribution. |
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.
This PR refactors the legacy CPE dictionary import logic to be more extendable and adds support for the new NVD CPE Dictionary 2.0 JSON feeds.
CPEImportHandler.XMLCPEHandlerfor legacy XML parsing.CPEDownloaderfor downloading and uncompressing CPE dictionaries.NVDCPEHandlerto handle the new JSON format.README.md.import.py)--update.--downloadto boolean.Resolves #18