anchore / vunnel

Tool for collecting vulnerability data from various sources (used to build the grype database)
Apache License 2.0
69 stars 25 forks source link

chore: replace frequenty used dict literals with data classes #644

Open willmurphyscode opened 1 month ago

willmurphyscode commented 1 month ago

For example:

https://github.com/anchore/vunnel/blob/c615dcae89ec4b84d7a51a62d77c69a6a496af9e/src/vunnel/utils/vulnerability.py#L16-L27 gets copy.deepcopy-ed around a lot, as a template for a dict literal. The code would be cleaner and have more useful type hinting if this were replaced with a data class.

Examples of copying https://github.com/anchore/vunnel/blob/c615dcae89ec4b84d7a51a62d77c69a6a496af9e/src/vunnel/utils/oval_parser.py#L160-L170

and https://github.com/anchore/vunnel/blob/c615dcae89ec4b84d7a51a62d77c69a6a496af9e/src/vunnel/providers/wolfi/parser.py#L103-L109

willmurphyscode commented 1 month ago

We want to make sure that whatever solution we use is not vulnerable to crashing because a field is added, so maybe skipping straight to data classes is the wrong approach. I'll research some additional approaches.