Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make configurationparser use ready #386

Merged
merged 31 commits into from
Oct 9, 2023

Conversation

Miauwkeru
Copy link
Contributor

(DIS-2156)

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #386 (f09f244) into main (d3c195e) will increase coverage by 0.15%.
The diff coverage is 88.25%.

@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
+ Coverage   73.79%   73.95%   +0.15%     
==========================================
  Files         252      255       +3     
  Lines       20189    20289     +100     
==========================================
+ Hits        14899    15005     +106     
+ Misses       5290     5284       -6     
Flag Coverage Δ
unittests 73.95% <88.25%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
dissect/target/filesystem.py 83.71% <100.00%> (+0.15%) ⬆️
dissect/target/plugins/os/unix/etc.py 83.33% <83.33%> (ø)
dissect/target/plugins/general/config.py 94.28% <94.28%> (ø)
dissect/target/tools/shell.py 48.06% <25.00%> (-0.07%) ⬇️
dissect/target/filesystems/config.py 87.62% <87.62%> (ø)
dissect/target/helpers/configparser.py 89.13% <89.13%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Miauwkeru Miauwkeru marked this pull request as ready for review September 5, 2023 12:47


class ConfigurationTreePlugin(Plugin):
__namespace__ = "config_tree"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice UX to call this etc? So calling would be t.etc("/blah").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'd assume you would only be able to use it with the /etc directory. Now it can be used within any directory. You could theoretically even use it on windows machines (for their ini files and stuff)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, though you could still make an internal shortcut available for etc right? And use this name if you want to parse other paths.

class ConfigurationTreePlugin(Plugin):
__namespace__ = "config_tree"

def __call__(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we LRU cache this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into it

@@ -65,7 +70,7 @@ def __exit__(self, _, __, ___):


def test_parse_functions(target_unix: Target, etc_directory: VirtualFilesystem):
config_fs = ConfigurationFs(target_unix)
config_fs = ConfigurationFilesystem(target_unix)
entry: ConfigurationEntry = config_fs.get("/new/path/config", collapse=True)

assert entry.parser_items["help"] == "you"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make a nicer way to get configuration values? Perhaps just make the entry itself behave like a dictionary with __item__ and .get()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get would be hard to change, as it follows the api for FilesystemEntries. I can however use the __getitem__ to access the dictionary directly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could, but instead of raising a NotADirectoryError you'd just be returning the actual configuration value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NotADirectoryError is there when there is no value though...?

Copy link
Member

@Schamper Schamper Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I probably meant that instead of letting end values be entries as well, that those just return the actual values, instead of having to use .open(). Or instead of the if not path: return self, return the value. I'm not sure what my train of thought was anymore.

Maybe I'm still just unsure if the filesystem approach is a good UX/API experience. I feel like a "magic dictionary" filled with configuration options is a much nicer programming experience.

@@ -65,7 +70,7 @@ def __exit__(self, _, __, ___):


def test_parse_functions(target_unix: Target, etc_directory: VirtualFilesystem):
config_fs = ConfigurationFs(target_unix)
config_fs = ConfigurationFilesystem(target_unix)
entry: ConfigurationEntry = config_fs.get("/new/path/config", collapse=True)

assert entry.parser_items["help"] == "you"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could, but instead of raising a NotADirectoryError you'd just be returning the actual configuration value.

@Miauwkeru Miauwkeru requested a review from pyrco September 28, 2023 11:30
@Miauwkeru Miauwkeru force-pushed the DIS-2156_make-configurationparser-useful branch 3 times, most recently from 9da1b82 to e71a21f Compare September 28, 2023 13:19
@Miauwkeru Miauwkeru requested a review from Schamper October 3, 2023 12:33
@Miauwkeru Miauwkeru force-pushed the DIS-2156_make-configurationparser-useful branch from 14a69ca to f09f244 Compare October 9, 2023 14:01
@Miauwkeru Miauwkeru dismissed Schamper’s stale review October 9, 2023 14:42

Has been implemented and discussed

@Miauwkeru Miauwkeru merged commit 795cd7e into main Oct 9, 2023
@Miauwkeru Miauwkeru deleted the DIS-2156_make-configurationparser-useful branch October 9, 2023 14:43
Schamper added a commit that referenced this pull request Oct 27, 2023
(DIS-2156)

Co-authored-by: pyrco <[email protected]>
Co-authored-by: cecinestpasunepipe <[email protected]>
Co-authored-by: Erik Schamper <[email protected]>
Poeloe pushed a commit that referenced this pull request Feb 29, 2024
(DIS-2156)

Co-authored-by: pyrco <[email protected]>
Co-authored-by: cecinestpasunepipe <[email protected]>
Co-authored-by: Erik Schamper <[email protected]>
Zawadidone pushed a commit to Zawadidone/dissect.target that referenced this pull request Apr 5, 2024
(DIS-2156)

Co-authored-by: pyrco <[email protected]>
Co-authored-by: cecinestpasunepipe <[email protected]>
Co-authored-by: Erik Schamper <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants