feat(password): add command to change AstrBot dashboard password#8272
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
cmd_passwordcommand tightly couples tocmd_conf’s internal helpers (e.g.,_set_dashboard_password,_validate_dashboard_*); consider moving these shared utilities into a dedicated module (e.g.,config_utils) so commands don’t depend on each other’s private APIs. - In
cmd_password.password, you strip whitespace from the username but not the password; if leading/trailing whitespace in passwords should be preserved or explicitly rejected, it may be worth making that behavior clear and consistent via either trimming or explicit validation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `cmd_password` command tightly couples to `cmd_conf`’s internal helpers (e.g., `_set_dashboard_password`, `_validate_dashboard_*`); consider moving these shared utilities into a dedicated module (e.g., `config_utils`) so commands don’t depend on each other’s private APIs.
- In `cmd_password.password`, you strip whitespace from the username but not the password; if leading/trailing whitespace in passwords should be preserved or explicitly rejected, it may be worth making that behavior clear and consistent via either trimming or explicit validation.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.
Code Review
This pull request introduces a new password CLI command to manage AstrBot dashboard credentials, allowing users to update their password and optionally their username directly from the terminal. The implementation includes refactoring the configuration logic into a reusable _set_dashboard_password helper to ensure consistency in password hashing and state flag updates. Additionally, a new test suite has been added to verify the command's functionality and its integration with existing configuration settings. Feedback was provided to enhance the user experience of the password command by integrating input validation directly into the click.prompt call.
| new_password = click.prompt( | ||
| "New dashboard password", | ||
| hide_input=True, | ||
| confirmation_prompt=True, | ||
| ) | ||
| validated_password = _validate_dashboard_password(new_password) |
There was a problem hiding this comment.
Using the value_proc argument in click.prompt allows for immediate validation of the password input. This improves the user experience by allowing click to automatically re-prompt the user if the validation fails, rather than exiting the command entirely. Note that for the retry behavior to work automatically, the validator should ideally raise click.UsageError or ValueError.
| new_password = click.prompt( | |
| "New dashboard password", | |
| hide_input=True, | |
| confirmation_prompt=True, | |
| ) | |
| validated_password = _validate_dashboard_password(new_password) | |
| validated_password = click.prompt( | |
| "New dashboard password", | |
| hide_input=True, | |
| confirmation_prompt=True, | |
| value_proc=_validate_dashboard_password, | |
| ) |
closes: #8268
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add a CLI command to change the AstrBot dashboard password and reuse shared helpers for updating password-related config state.
New Features:
passwordCLI command to interactively update the AstrBot dashboard password and optionally the dashboard username.Enhancements:
Tests: