Skip to content

Conversation

@magogosora
Copy link
Contributor

@magogosora magogosora commented Feb 3, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Added GetUser subcommand to the admin CLI to fetch a user's info from a broker or cluster.
  • Improvements

    • End-to-end user retrieval enabled across client, admin, and broker.
    • get_user now returns an optional result; callers and CLI handle missing users.
    • Centralized target-selection for admin commands and clearer command descriptions.
  • Bug Fixes

    • Admin user requests now route to the proper handler.
    • Copy-users flow more robustly handles missing users and reports warnings.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@magogosora 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Feb 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

Adds a GetUser admin flow: broker-side GetUserRequestHandler and wiring, remoting header, MQ client API and admin impl support returning Option, CLI GetUser subcommand, and a Target abstraction for broker/cluster selection.

Changes

Cohort / File(s) Summary
Broker processor & handler
rocketmq-broker/src/processor/admin_broker_processor.rs, rocketmq-broker/src/processor/admin_broker_processor/get_user_request_handler.rs
Wires new GetUserRequestHandler into AdminBrokerProcessor; adds get_user() handler (placeholder SystemError response) and routes AuthGetUser requests to it.
List users rename
rocketmq-broker/src/processor/admin_broker_processor/list_users_request_handler.rs
Renames list_users_requestlist_users and updates invocation site.
Remoting headers
rocketmq-remoting/src/protocol/header.rs, rocketmq-remoting/src/protocol/header/get_user_request_headers.rs
Adds get_user_request_headers module and GetUserRequestHeader (username field, serde + codec derives).
Client API & admin impl
rocketmq-client/src/implementation/mq_client_api_impl.rs, rocketmq-client/src/admin/default_mq_admin_ext_impl.rs, rocketmq-client/src/admin/mq_admin_ext_async.rs
Adds MQClientAPIImpl::get_user(...) that sends AuthGetUser and returns Option<UserInfo>; updates DefaultMQAdminExtImpl::get_user and trait to return Option<UserInfo>.
Admin CLI: getUser command
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands.rs, .../get_user_sub_command.rs, .../copy_users_sub_command.rs
Adds GetUser subcommand and GetUserSubCommand implementation (broker/cluster targets); updates copy logic to handle Option<UserInfo>.
Target abstraction & refactor
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/target.rs, .../list_users_sub_command.rs, .../commands.rs
Introduces Target enum utility and centralizes broker/cluster target parsing; refactors ListUsersSubCommand to use it and adds private target module.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as GetUserSubCommand
    participant AdminExt as MQAdminExt
    participant AdminImpl as DefaultMQAdminExtImpl
    participant ClientAPI as MQClientAPIImpl
    participant Remoting as RemotingClient
    participant Broker as AdminBrokerProcessor
    participant Handler as GetUserRequestHandler

    CLI->>AdminExt: get_user(broker_addr, username)
    AdminExt->>AdminImpl: get_user(broker_addr, username)
    AdminImpl->>ClientAPI: get_user(broker_addr, username, timeout)
    ClientAPI->>Remoting: send AuthGetUser (with GetUserRequestHeader)
    Remoting->>Broker: deliver AuthGetUser
    Broker->>Handler: get_user(channel, ctx, request_code, request)
    Handler-->>Broker: RemotingCommand (response)
    Broker-->>Remoting: response
    Remoting-->>ClientAPI: response
    ClientAPI->>AdminImpl: Option<UserInfo>
    AdminImpl-->>AdminExt: Option<UserInfo]
    AdminExt-->>CLI: Option<UserInfo]
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • mxsm
  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🐰
I hopped from CLI down to wire and thread,
A username traced where remoting led.
Brokers and clients hummed a tiny tune,
I asked for a user — maybe none, maybe soon. 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.21% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Most changes are in-scope, but the PR includes refactoring (Target abstraction, list_users_request_handler method rename) that exceeds the stated goal of implementing GetUserSubCommand and may impact other modules beyond the feature scope. Clarify whether the Target abstraction refactoring and ListUsersSubCommand updates are part of issue #5662 or if they should be separated into distinct PRs for better change isolation.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: implement GetUserSubCommand (#5662)' accurately and concisely describes the main feature being added: implementation of the GetUserSubCommand, with direct reference to the related issue.
Linked Issues check ✅ Passed The PR implements all core coding requirements from issue #5662: GetUser command accepts username input, supports cluster/broker address targeting, retrieves user information, displays user details (username, user type, status), and never displays passwords in output.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Fix all issues with AI agents
In
`@rocketmq-broker/src/processor/admin_broker_processor/get_user_request_handler.rs`:
- Around line 1-9: This file is missing the Apache 2.0 license header; add the
standard Apache 2.0 copyright header (starting with "// Copyright 2023 The
RocketMQ Rust Authors" and the full license boilerplate) at the very top of the
file, above the first use statements (e.g. above "use
crate::broker_runtime::BrokerRuntimeInner;") so the header appears before any
code or imports in get_user_request_handler.rs; ensure the header matches the
repository's existing files exactly.
- Around line 20-34: Update the commented decode line in the get_user function
to reference the correct request header type: replace the commented use of
ListUsersRequestHeader with GetUserRequestHeader so it reads the intended call
to request.decode_command_custom_header::<GetUserRequestHeader>()?; locate this
in the get_user method where the commented request_header line appears and
adjust the type name only.

In `@rocketmq-client/src/implementation/mq_client_api_impl.rs`:
- Around line 313-349: In get_user, when matching ResponseCode::Success and
response.get_body() is None you currently call mq_client_err! with
response.code() (a success code); change this to return a proper non-success
error instead of reporting a success code — e.g. construct the error with a
meaningful failure code (use ResponseCode::SystemError or another appropriate
non-success enum variant) and a clear message like "missing response body for
user '<username>'", or alternatively mirror list_users and return an explicit
"not found"/empty result type; update the error construction site (the closure
passed to ok_or_else) so mq_client_err! is called with the chosen non-success
code and descriptive remark before attempting UserInfo::decode.

In
`@rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands.rs`:
- Around line 77-82: Update the CLI help text for the GetUser command so it
matches the issue description: change the about string on the GetUser command
attribute (the enum variant GetUser in auth_commands.rs with #[command(name =
"getUser", ...)]) from "Get user." to "Get user from cluster" (keep long_about
as-is).

In
`@rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands/get_user_sub_command.rs`:
- Around line 98-101: The cluster-target branch (Target::ClusterName) calls
print_users(&user_info) without first printing the header, causing inconsistent
output; update the Target::ClusterName handling in get_user_sub_command.rs to
call print_header() before print_users(&user_info) (mirror what the
broker-target branch does with print_header() and print_user()), and make the
same change at the other similar cluster-handling site later in the file so both
occurrences print the header before printing users.
🧹 Nitpick comments (1)
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/target.rs (1)

45-76: Consider adding edge case tests for normalization.

The tests cover the main scenarios well. Consider adding tests for edge cases handled by normalize:

  • Whitespace-only cluster name: Target::new(&Some(" ".into()), &None) should error
  • Empty string broker address: Target::new(&None, &Some("".into())) should error

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 23.29317% with 191 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.50%. Comparing base (56810e4) to head (d9a31fc).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
...src/commands/auth_commands/get_user_sub_command.rs 17.85% 115 Missing ⚠️
...mq-client/src/implementation/mq_client_api_impl.rs 0.00% 24 Missing ⚠️
...admin_broker_processor/get_user_request_handler.rs 0.00% 15 Missing ⚠️
...c/commands/auth_commands/copy_users_sub_command.rs 0.00% 11 Missing ⚠️
...etmq-client/src/admin/default_mq_admin_ext_impl.rs 0.00% 9 Missing ⚠️
...tmq-broker/src/processor/admin_broker_processor.rs 0.00% 6 Missing ⚠️
...c/commands/auth_commands/list_users_sub_command.rs 0.00% 5 Missing ⚠️
...ketmq-admin-core/src/admin/default_mq_admin_ext.rs 0.00% 4 Missing ⚠️
...min_broker_processor/list_users_request_handler.rs 0.00% 1 Missing ⚠️
.../rocketmq-admin-core/src/commands/auth_commands.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6041      +/-   ##
==========================================
- Coverage   40.54%   40.50%   -0.04%     
==========================================
  Files         881      884       +3     
  Lines      122549   122760     +211     
==========================================
+ Hits        49682    49726      +44     
- Misses      72867    73034     +167     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM - All CI checks passed ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
rocketmq-broker/src/processor/admin_broker_processor/list_users_request_handler.rs (1)

34-47: ⚠️ Potential issue | 🟠 Major

AuthListUsers still always fails (SystemError).

This handler returns a hard-coded SystemError, so any AuthListUsers request will fail even though the client/admin APIs exist. If list-users is intended to work, please implement the retrieval via the authentication metadata manager and return a Success response with an encoded body. If it is intentionally unsupported, consider routing to the “not supported” response instead of SystemError for consistency.

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands/copy_users_sub_command.rs (1)

182-193: ⚠️ Potential issue | 🟠 Major

Handle Ok(None) when deciding create vs update.
With the new Option return, Ok(None) means the user doesn’t exist on the target; the current is_err() check routes those cases to update, which will likely fail or silently skip creation.

🔧 Suggested fix
-        let copy_result = if target_user_result.is_err() {
-            default_mqadmin_ext
-                .create_user_with_user_info(target_broker.into(), user_info.clone())
-                .await
-        } else {
-            default_mqadmin_ext
-                .update_user_with_user_info(target_broker.into(), user_info.clone())
-                .await
-        };
+        let copy_result = match target_user_result {
+            Ok(Some(_)) => {
+                default_mqadmin_ext
+                    .update_user_with_user_info(target_broker.into(), user_info.clone())
+                    .await
+            }
+            Ok(None) | Err(_) => {
+                default_mqadmin_ext
+                    .create_user_with_user_info(target_broker.into(), user_info.clone())
+                    .await
+            }
+        };

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM - All CI checks passed ✅

Copy link
Owner

@mxsm mxsm left a comment

Choose a reason for hiding this comment

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

LGTM

@mxsm mxsm merged commit 5702177 into mxsm:main Feb 4, 2026
8 of 13 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge Difficulty level/Moderate Moderate difficult ISSUE feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Implement GetUser Command for User Query

4 participants