Skip to content

feat!: client create result, rename through Update, and in-place Reregister - #153

Merged
tas50 merged 3 commits into
mainfrom
feat/clients-users-1.0
Nov 27, 2026
Merged

tas50 merged 3 commits into
mainfrom
feat/clients-users-1.0

Conversation

@tas50

@tas50 tas50 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Clients.Create result. erchef answers POST /clients with {"uri", "chef_key": {name, public_key, expiration_date, uri, private_key?}} (oc_chef_wm_base.erl:1080, oc_chef_wm_key_base.erl:92-115). So the *APIClient result had an empty Name and Validator and lost the URI. It now returns ClientCreateResult{URI, ChefKey}, the same shape as UserCreateResult. ChefKey gains URI and moves to keys.go, and APIClient.ChefKey is removed.

Rename through Update. Clients.Update and Users.Update used the body's name as the path, so they couldn't rename, although erchef renames on a PUT whose body name differs from the path (201 with Location). Both are now Update(ctx, name, obj), as KeyScope.Update already is:

  • An empty name in the body keeps the current one.
  • The caller's object isn't modified.
  • An empty name is refused.

Groups can be renamed the same way (oc_chef_group.erl:145) but are left as they are. Orgs can't be renamed (oc_chef_organization.erl:62).

Clients.Reregister in place. It deleted the default key and then created a new one. A failed create left the client keyless, and any expiration was reset to infinity. erchef regenerates a key in place: PUT .../keys/default {"create_key": true} returns the new pair and keeps the expiration (oc_chef_wm_named_key.erl:123-145), the same call pedant uses (platform.rb:234). Reregister now sends that single PUT. It falls back to creating the key only when there is none (404). A client still can't reregister itself, because erchef answers 403 for the key the request is signed with; this was true before too and is now documented.

cinc-server-ng answers a renaming PUT with 200 and stores the new body under the old name. clients/rename and users/rename are listed in its Gaps, and AGENTS.md records the difference.

Breaking:

  • Clients.Create returns *ClientCreateResult, and APIClient.ChefKey is removed.
  • Clients.Update(ctx, name, cl) and Users.Update(ctx, name, u).

Test plan

  • Fixtures replay erchef's bodies. Unit tests cover:
    • create result
    • rename paths and bodies
    • Reregister's in-place PUT, the keyless fallback, a missing client, and a 403 that creates nothing
  • New integration cases:
    • clients/rename and users/rename (gaps on cinc-server-ng)
    • clients/reregister-keeps-client-usable: signs with the new key, the old key gets ErrUnauthorized, and only default remains
    • clients/reregister-keyless
  • go test ./... -race -count=2, cd integration && go test ./..., golangci-lint in both modules
  • The erchef run covers the rename cases (in progress for this batch)

…e keys in place

Clients.Create decoded erchef's POST /clients answer into an APIClient,
but under API v1 erchef sends only {"uri", "chef_key"}
(oc_chef_wm_base:create_from_json, oc_chef_wm_key_base:finalize_create_body),
so Name and Validator came back empty and the uri was lost. It now returns
a ClientCreateResult{URI, ChefKey}, like Users.Create's UserCreateResult.
ChefKey gains the key's URI, which erchef embeds, and moves to keys.go;
APIClient.ChefKey, which only carried this, is gone.

Clients.Update and Users.Update took the path from the body's name, so they
could not rename. erchef renames when a PUT body names a different object
and answers 201 with a Location (oc_chef_wm_base:update_from_json,
handle_rename). Both now take the current name for the path; the body
carries the possibly new one, as KeyScope.Update already does. A client PUT
echoes the validated body, so Clients.Update still returns the client.

Clients.Reregister deleted the default key and created a new one: a failure
in between left the client keyless, and the new key never expired whatever
the old one's date. It now sends one PUT .../keys/default with create_key,
which erchef regenerates in place, keeping the expiration
(oc_chef_wm_named_key:from_json, finalize_update_body). A client with no
default key (404) still gets one created.

cinc-server-ng v0.22.0 stores a renaming PUT under the old name, so the new
clients/rename and users/rename integration cases are gaps there.

BREAKING CHANGE: Clients.Create returns *ClientCreateResult instead of
*APIClient; APIClient.ChefKey is removed; Clients.Update(ctx, cl) becomes
Clients.Update(ctx, name, cl); Users.Update(ctx, u) becomes
Users.Update(ctx, name, u).

Signed-off-by: Tim Smith <tsmith84@proton.me>
if err != nil {
t.Fatalf("Reregister: %v", err)
}
if key.PrivateKey == "" || key.PrivateKey == created.ChefKey.PrivateKey {
Both are about cinc-server-ng PUT replies, and the new position does not collide with other additions to the gaps list.

Signed-off-by: Tim Smith <tsmith84@proton.me>
…e test

Against CINC Server 15.10.125 a client rename succeeds (201, the old name
404s), but the renamed client lists no keys and neither name
authenticates, so the rename case's check that the original key still
works failed there. Clients.Update and the README now say so, and the
case gives the renamed client a key with Reregister, which creates a
missing default key, then signs with it. The case passes on erchef.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50

tas50 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Ran the suite against CINC Server 15.10.125 (erchef). Everything passed except clients/rename. The rename itself succeeds (201, and the old name 404s), but erchef keeps no keys across it: the renamed client lists no keys, default is a 404, and neither name authenticates. Fixed in the latest commit: Clients.Update and the README document this, and the case now calls Reregister after the rename (it creates a missing default key) and signs with the new key. All five clients/* cases pass on erchef.

@tas50
tas50 merged commit 48a5f3f into main Nov 27, 2026
7 checks passed
@tas50
tas50 deleted the feat/clients-users-1.0 branch November 27, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants