-
Notifications
You must be signed in to change notification settings - Fork 786
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
1960 deserialize config #2043
1960 deserialize config #2043
Conversation
Creating AgentConfiguration object from dictionary makes sense because it doesn't couple the configuration to any specific serialization methods. Also, the json sent from the island doesn't match the config structure because it stores config in a dict under "config" key.
"supported_os" was removed from the schema in d079d74
The old config scheme stored timeouts as milliseconds, whereas the new one uses seconds. Seconds are more convenient because most python methods expecting timeouts are expecting floating-point seconds.
The variable name "os" conflicts with the name of Python's `os` library.
…tion Agent configuration construction
# TODO: This has been replaced by common.configuration.InvalidConfigurationError. Use that error | ||
# instead and remove this one. |
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.
Not in this PR?
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.
No, it's out of scope. Other components are still using the old ConfigService
and other components that still use this error. The TODO
is here because vulture can't tell which one is being used, so once everything is switched over to the new error, we don't want to forget to remove this one.
from .agent_sub_configurations import ( | ||
CustomPBAConfiguration, | ||
PluginConfiguration, | ||
ScanTargetConfiguration, | ||
ICMPScanConfiguration, | ||
TCPScanConfiguration, | ||
NetworkScanConfiguration, | ||
ExploitationOptionsConfiguration, | ||
ExploiterConfiguration, | ||
ExploitationConfiguration, | ||
PropagationConfiguration, |
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.
Why do we have both PluginConfiguration
and ExploiterConfiguration
dataclasses which have the same member variables (link to file with definitions)?
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.
Typehint was Mapping, when it was using and calling other methods with CustomPBAConfiguration
# makes it impossible to construct an invalid object | ||
try: | ||
AgentConfigurationSchema().dump(self) | ||
except Exception as err: |
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.
Are we expecting anything but MarshmallowError
?
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.
That I'm aware, it can raise MarshmallowError
, TypeError
, or ValueError
. It may raise others as well, I'm not sure.
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.
A better question is, "Is there any case where AgentConfigurationSchema().dump()
could raise an exception for any reason other than an invalid exception?" To my knowledge, there's not.
@@ -204,5 +204,4 @@ | |||
|
|||
|
|||
def build_default_agent_configuration() -> AgentConfiguration: | |||
schema = AgentConfigurationSchema() | |||
return schema.loads(DEFAULT_AGENT_CONFIGURATION_JSON) | |||
return AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) |
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.
We should probably specify the defaults in the marshmallow schema. We'll do it with validation, right?
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.
Yeah, #2004.
Move line 60 to f formatting from the old %s style
self, target_config: ScanTargetConfiguration | ||
) -> List[NetworkAddress]: | ||
ranges_to_scan = target_config.subnets | ||
inaccessible_subnets = target_config.inaccessible_subnets |
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.
What is the purpose of these variables? I'd rather we just use keyword arguments in compile_scan_target_list
call and pass them 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.
It keeps _scan_network()
a little shorter and easier to read. That was probably more important when we were using a dict. I could go either way. Feel free to fix it.
AgentConfiguration.from_json(json.dumps(invalid_dict)) | ||
|
||
|
||
def test_to_json(): |
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.
Maybe it's worth considering merging the serialization tests. Not only because from_json
and to_json
will be used in tandem, but also to avoid the maintenance of default configuration in json format
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 added DEFAULT_AGENT_CONFIGURATION
and removed DEFAULT_AGENT_CONFIGURATION_JSON
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.
Approved, but left some comments
It's easier to maintain object than a JSON string for the default configuration.
What does this PR do?
Use the
AgentConfiguration
object in the agent.PR Checklist
Was the CHANGELOG.md updated to reflect the changes?Was the documentation framework updated to reflect the changes?Testing Checklist
if applicable, add screenshots or log transcripts of the feature working