Skip to content

feat(password): add command to change AstrBot dashboard password#8272

Merged
Soulter merged 1 commit into
masterfrom
feat/cli-password
May 21, 2026
Merged

feat(password): add command to change AstrBot dashboard password#8272
Soulter merged 1 commit into
masterfrom
feat/cli-password

Conversation

@Soulter
Copy link
Copy Markdown
Member

@Soulter Soulter commented May 21, 2026

closes: #8268

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Introduce a password CLI command to interactively update the AstrBot dashboard password and optionally the dashboard username.

Enhancements:

  • Refactor dashboard password updates into a shared helper used by both the new password command and existing config commands to keep password state flags in sync.

Tests:

  • Add CLI tests covering the new password command, username update behavior, and the updated config password handling.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 21, 2026
@Soulter Soulter removed the request for review from advent259141 May 21, 2026 07:48
@dosubot dosubot Bot added the area:core The bug / feature is about astrbot's core, backend label May 21, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +22 to +27
new_password = click.prompt(
"New dashboard password",
hide_input=True,
confirmation_prompt=True,
)
validated_password = _validate_dashboard_password(new_password)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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,
)

@Soulter Soulter merged commit d15606d into master May 21, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]添加通过 cli 更新密码的功能

1 participant