Fix plugins where _target is not provided and add tests to check that all TargetRecordDescriptor records are instanciated with the _target field - #1902
Open
william-billaud wants to merge 7 commits into
Conversation
…d modify pytest configuration to fail when this warning is encounter
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.
Fix plugins where _target is not provided and add tests to check that all TargetRecordDescriptor records are instanciated with the _target field
In some plugins, the _target field is not provided when creating records. Thus the resulting records does not have some important field :
hostname,domainand_source.Enforcing of this rule is up to the reviewer, which is not perfecte
Proposed Changes
Create a new warning
DissectWarningand a subclassMissingTargetInRecordWarning. When a record is initiated without the _target, a warning is created using the warnings.warn function.When test are executed, these warning are considerered as error and will make the test fails.
On normal execution, this is up to of how the warning filter are configured. By default "print the first occurrence of matching warnings for each location (module + line number) where the warning is issued".
The warning will be printed on stderr using the logger configuration when (logging.captureWarnings(True))[https://github.com/fox-it/dissect.target/blob/d1c70c59217792237a5ff31a378c892bc5aa800b/dissect/target/tools/utils/logging.py#L93] is defined.
This is the case for dissect.target tools. but it will ignore the
--quietflag as the log level is only defined for thedissectlogger, and notpy.warnings, but this is something that can be easily changed.Main change
targetobject where they are instanced. Value can be None so it should not break anything.target-diiftool : use the src target as _target.record_kwargs.get("_target")check is already present, we just define another branch.Other possibilities
I have also testes the following solution, without success (mainly with the help of an LLM)
IMO the warning option is the less complex regarding the current code base, and does not add a lot of noise to end users, unless they encounter a case no detected in tests.
It's also possible to raise an error/depreciation warning and enforce presence of this field in a later release.
Checklist
Relates also to Normalize "source"/"path" record field, containing path of the file (or registry key) used to generate a specific record. #1892, as a similar strategy could be used to detect undefined
source