feat(identity): add --project/--project-domain to user set - #20
Merged
Merged
Conversation
`koc user set` could not change a user's default project: the flag pair
existed on `user create` only, while `user show` printed `Default Project
ID` all along — settable at creation, visible forever, never changeable.
Upstream `openstack user set` has taken `--project` (and `--project-domain`)
since forever (python-openstackclient `identity/v3/user.py`, `SetUser`), so
the workaround was to reach for `openstack`, which is what this binary
exists to avoid.
`users.UpdateOpts.DefaultProjectID` was already in the pinned gophercloud
v2.13.0, so this is unwired capability rather than a vendor change. The
project-domain resolution `runUserCreate` grew is now a shared
`resolveDefaultProjectID` helper that both write verbs call: an empty
--project short-circuits in `resolveProjectID` and the empty ID is
`omitempty` on both opts structs, so the field stays untouched when the
flag is absent.
Absent --project-domain the lookup falls back to the user's own domain,
where upstream resolves the project unscoped across all domains. The two
differ only when --domain is given and the default project lives
elsewhere; scoping to the user's domain is the safer reading of an
ambiguous project name and keeps the two user write verbs consistent.
Recorded under "Naming deviations" in docs/coverage.md, which needs no
count change — this adds no leaf command.
Verified end-to-end against a mock keystone: `koc user set --project admin
admin` resolves the user, resolves the project, then PATCHes
`{"user":{"default_project_id":"..."}}` and prints nothing, matching
upstream.
Closes #19
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019Dnh8BhczXscNe67sYomCw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #19.
koc user setcould not change a user's default project. The flag pair existedon
user createonly, whileuser showprintedDefault Project IDall along —settable at creation, visible forever, never changeable. Upstream
openstack user sethas taken--project(and--project-domain) since forever(python-openstackclient 10.2.1,
identity/v3/user.py,SetUser), so theworkaround was to reach for
openstack.users.UpdateOpts.DefaultProjectIDwas already in the pinned gophercloudv2.13.0, so this is unwired capability rather than a vendor change.
Changes
internal/cli/identity/user.go— register--project/--project-domainonuser setand setDefaultProjectID. The project-domain resolution thatrunUserCreategrew inline is now a sharedresolveDefaultProjectIDbothwrite verbs call: an empty
--projectshort-circuits inresolveProjectIDand the empty ID is
omitemptyon both opts structs, so the field staysuntouched when the flag is absent.
internal/cli/identity/user_test.go— two tests through therunUserSetseam: the PATCH body, and a table for
--project-domainoverriding vs.falling back to the user's domain.
docs/coverage.md— no count change (no new leaf command); records the onesemantic deviation below under "Naming deviations".
Deviation
Absent
--project-domain, the lookup falls back to the user's own domain, whereupstream resolves the default project unscoped across all domains. The two
differ only when
--domainis given and the default project lives elsewhere,which
--project-domainthen states explicitly. Scoping to the user's domain isthe safer reading of a cloud-wide-ambiguous project name and keeps the two user
write verbs consistent with each other.
Verification
Offline gate on the merged tree:
gofmtclean under the pinned toolchain,go vetclean,golangci-lint run ./...0 issues (v2.13.2, the CI pin,checksum-verified),
go test ./...green with-mod=vendor GOPROXY=off, staticbuild OK.
Exercised end-to-end with the built binary against a mock keystone —
koc user set --project admin adminresolves the user, resolves the project,then
PATCH /v3/users/u1 {"user":{"default_project_id":"..."}}and printsnothing, matching upstream:
Not included, and left on #19 for a separate pass:
--email(missing fromuser createtoo),--password-prompt, and the_add_user_optionsfamily.🤖 Generated with Claude Code
https://claude.ai/code/session_019Dnh8BhczXscNe67sYomCw
Generated by Claude Code