hscontrol/users: add SetUser API and CLI to update user profile fields - #3107
hscontrol/users: add SetUser API and CLI to update user profile fields#3107Razano26 wants to merge 1 commit into
Conversation
Add SetUser gRPC/REST endpoint (PUT /api/v1/user/{id}) and
"headscale users set" CLI command to update a user's display_name,
email, and profile_pic_url.
Uses optional proto fields so only explicitly provided values are
applied; omitted fields preserve their current value.
Fixes juanfont#2166
There was a problem hiding this comment.
Pull request overview
This PR adds the ability to update user profile fields through a new SetUser API endpoint and headscale users set CLI command. It addresses issue #2166 by allowing administrators to set display names, emails, and profile picture URLs on existing users, which enables features like tailscale whois to display user information.
Changes:
- Add
SetUsergRPC/REST endpoint (PUT /api/v1/user/{id}) with optional proto fields for partial updates - Add
headscale users setCLI command with flags for--display-name,--email, and--picture-url - Comprehensive unit and integration tests covering normal operation, partial updates, validation, and error cases
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| proto/headscale/v1/user.proto | Adds SetUserRequest and SetUserResponse messages with optional fields |
| proto/headscale/v1/headscale.proto | Adds SetUser RPC endpoint with PUT HTTP binding |
| hscontrol/grpcv1.go | Implements SetUser API with URL validation and UpdateUser state call |
| cmd/headscale/cli/users.go | Adds setUserCmd with flag handling and validation logic |
| hscontrol/grpcv1_test.go | Adds comprehensive unit tests for SetUser functionality |
| integration/cli_test.go | Adds integration test verifying CLI command works end-to-end |
| gen/go/headscale/v1/*.go | Auto-generated protobuf and gRPC code |
| gen/openapiv2/headscale/v1/headscale.swagger.json | Auto-generated OpenAPI/Swagger documentation |
| CHANGELOG.md | Documents the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| if cmd.Flags().Changed("picture-url") { | ||
| pictureURL, _ := cmd.Flags().GetString("picture-url") |
There was a problem hiding this comment.
The picture URL is not validated before sending the request to the server. The createUserCmd validates the URL using url.ParseRequestURI at lines 102-105. For consistency and to provide faster feedback to users, the same validation should be added here before constructing the SetUserRequest. This would catch invalid URLs at the CLI level rather than requiring a round trip to the server.
| pictureURL, _ := cmd.Flags().GetString("picture-url") | |
| pictureURL, _ := cmd.Flags().GetString("picture-url") | |
| if _, err := url.ParseRequestURI(pictureURL); err != nil { | |
| return fmt.Errorf("invalid picture-url %q: %w", pictureURL, err) | |
| } |
Add
SetUsergRPC/REST endpoint (PUT /api/v1/user/{id}) andheadscale users setCLI command to update a user'sdisplay_name,email, andprofile_pic_urlfields.Uses
optionalproto fields so only explicitly provided values are applied — omitted fields preserve their current value.Fixes #2166