-
Notifications
You must be signed in to change notification settings - Fork 33
Restructure qmctl #839
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
base: main
Are you sure you want to change the base?
Restructure qmctl #839
Conversation
Reviewer's GuideRefactored qmctl into a clean, command-based architecture by introducing a command registry, extracting handlers into separate functions, and unifying argument parsing and error reporting. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @ArtiomDivak - I've reviewed your changes - here's some feedback:
Blocking issues:
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
General comments:
- Factor out the repeated container-exists and argument-validation logic into a decorator or helper to DRY up the multiple
exec_*
andshow_*
methods. - Replace the scattered
sys.exit(1)
calls by raising custom exceptions in command handlers and handling them centrally in the CLI entrypoint to simplify control flow. - Consider breaking each command into its own module or class rather than growing a single monolithic QMCTL class to better align with the intended clean, command-based architecture.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🔴 Security: 3 blocking issues
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
d60705a
to
355789e
Compare
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.
Hey @ArtiomDivak - I've reviewed your changes and they look great!
Blocking issues:
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🔴 Security: 4 blocking issues
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
@ArtiomDivak Did you try to run the tests through tmt locally?
Please refer that one all tier-0 testing are failing due to the changes
Line 139 in daec692
Refer [FMF](https://fmf.readthedocs.io/en/stable) for tmt test metadata specification |
9d4c8c3
to
11e2cf0
Compare
13020b1
to
60695cb
Compare
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.
Hey @ArtiomDivak - I've reviewed your changes and they look great!
Blocking issues:
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Security Issues
### Issue 1
<location> `tools/qmctl/qmctl:62` </location>
<issue_to_address>
**security (dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>
### Issue 2
<location> `tools/qmctl/qmctl:215` </location>
<issue_to_address>
**security (dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>
### Issue 3
<location> `tools/qmctl/qmctl:537` </location>
<issue_to_address>
**security (dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>
### Issue 4
<location> `tools/qmctl/qmctl:613` </location>
<issue_to_address>
**security (dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
8f0b6ba
to
654f8c2
Compare
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.
Added a few comments.
This PR is quite big, so I am not sure if it would be better to split it.
"""Initialize the QMCTL class. | ||
|
||
Args: | ||
config_path (str): The path to the container config file. |
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.
Type hints in the comments, e.g. the (str)
for config_path, are nice, but it would be more important to add type hints on your actual variables. In addition to readability, this also adds tooling support for IDEs such as auto-complete or suggesting operations.
For example, you can add types to your function params:
def __init__(
self,
config_path: str = "/usr/share/containers/systemd/qm.container",
verbose: bool = False,
container_name: str = "qm",
):
and the same to your variables:
self.config_path: str = config_path
self.container: str = container_name
self.verbose: bool = verbose
The big advantage here is that your IDE can now suggest operations. For example when using self.config_path
your IDE assumes its a string and can suggest operations such as lower()
.
@ArtiomDivak Could you add type hints?
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.
Added hints
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 only see type hints added to that specific code part I used as an example. I meant adding those for the whole code, every function parameter etc. Its also ok to not have type hints, but having a mix is off.
Reopening this thread.
6976bb6
to
86fe6e3
Compare
@@ -1,256 +1,448 @@ | |||
#!/usr/bin/env python | |||
# Licensed under the Apache License, Version 2.0 |
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.
please keep the license
tools/qmctl/qmctl
Outdated
if not command: | ||
self._print_output({"error": "No command provided to execute."}, output_json, pretty) | ||
sys.exit(1) | ||
def _check_exit_if_string_in_string(self, string, substring, message): |
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's just one if, don't think we need a new function.
tools/qmctl/qmctl
Outdated
self._print_output_and_exit( | ||
f"{msg} No output returned.") | ||
|
||
def _check_if_command_is_not_None(self, command, msg): |
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's just a if, I don't think we need this function.
This MR I added QMCTL class wich will be responsiable to run all the command function and return the result. Also added all the imports needed to all the file Signed-off-by: Artiom Divak <[email protected]>
ArgumentParserWithDefaults class automatically adds default values to the help text of arguments SubcommandInitializer is a generic class to initialize subparsers for command-line applications Signed-off-by: Artiom Divak <[email protected]>
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.
Please remove the __pycache__
(and maybe add it to .gitignore)
This commits adds the main function the init of the subcommand and the handle function for the subcommand with other vital function. Signed-off-by: Artiom Divak <[email protected]>
This MR refactors the qmctl file to improve its structure, making it easier to add new commands and debug in the future. The new design is heavily inspired by the clean, command-based architecture of the "ramalama" project, aiming for a more organized and maintainable codebase.
closes #838
Summary by Sourcery
Restructure qmctl to improve code organization and maintainability by adopting a command-based architecture
Enhancements: