-
Notifications
You must be signed in to change notification settings - Fork 54
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
||
|
||
class ConfigurationTreePlugin(Plugin): | ||
__namespace__ = "config_tree" |
There was a problem hiding this comment.
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")
.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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__( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
8a15ef5
to
11e5728
Compare
9da1b82
to
e71a21f
Compare
Also converts it to bytesio at the `open` of the filesystem entry
This allows an analyst to make it into a dict on command. otherwise, just ask `as_dict()` on a ConfigurationEntry
14a69ca
to
f09f244
Compare
Has been implemented and discussed
(DIS-2156) Co-authored-by: pyrco <[email protected]> Co-authored-by: cecinestpasunepipe <[email protected]> Co-authored-by: Erik Schamper <[email protected]>
(DIS-2156) Co-authored-by: pyrco <[email protected]> Co-authored-by: cecinestpasunepipe <[email protected]> Co-authored-by: Erik Schamper <[email protected]>
(DIS-2156) Co-authored-by: pyrco <[email protected]> Co-authored-by: cecinestpasunepipe <[email protected]> Co-authored-by: Erik Schamper <[email protected]>
(DIS-2156)