Skip to content

refactor: adopt cinc-api search and node helpers - #263

Merged
tas50 merged 5 commits into
mainfrom
refactor/adopt-cinc-api-nodes-search
Sep 24, 2026
Merged

tas50 merged 5 commits into
mainfrom
refactor/adopt-cinc-api-nodes-search

Conversation

@tas50

@tas50 tas50 commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Second of four cinc-api v0.15.0 adoption PRs. The search envelopes and node read-modify-write logic now live in the library.

Search

  • searchResult, partialProjection, unwrapDataBagItem, and the partial flag threaded through the rendering are gone. Search uses cinc.SearchResult, WithPartialPaths (always projecting name and id), UnwrapSearchRow, DataBagItem.Content(), and Node.AttributeString for the platform column.
  • The explorer's searchRowIdentity shrinks to a few lines on UnwrapSearchRow.
  • Behavior change: --format json now emits the unwrapped objects the table shows, which is what knife does. A partial row is its projected data, and a data bag search yields the items rather than Chef::DataBagItem envelopes. The total/start/rows shape is unchanged.

Nodes

  • node ssh and node status use Search.Nodes. status uses Node.LastCheckin, and a row that isn't a node now fails the command instead of silently printing a blank line. The hand-written attribute walkers are deleted.
  • run-list, tag, environment-set, policy-set and the node edit form go through Nodes.Modify. An edit that changes nothing sends no PUT and says so. After a real change, the output shows the node the server returned, not the local copy.
  • Run-list add, remove and set normalize like erchef, so remove nginx drops a stored recipe[nginx], and add nginx doesn't duplicate it.
  • The tag and run-list command builders were near-copies. They're merged into one table-driven builder.
  • tag list --format json prints [] rather than null for a node with no tags.

Test plan

  • go test ./apps/... ./cli/explore/ ./cli/client/, go vet ./..., gofmt
  • make test-integration (cinc-server-ng): pass. The cases that dug into .data or raw_data are updated for the unwrapped JSON.

Point cinc-api at the local combined branch so the CLI can adopt its new
search, node and run-list helpers before they are released. That branch
also changes Policies.PushRevision to return a PushResult, so policy
push now reads the revision from it; adopting the rest of PushResult is
left to the change that owns policy push.

Drop the replace directive once cinc-api is tagged.

Signed-off-by: Tim Smith <tsmith84@proton.me>
…son too

cinc-api now owns the search wire details: UnwrapSearchRow strips the
partial-search {url, data} envelope and the Chef::DataBagItem wrapper a
full data bag search returns, WithPartialPaths builds the -a projection,
and SearchResult, DataBagItem.Content and Node.AttributeString replace
the CLI's copies. searchResult, partialProjection, unwrapDataBagItem and
the explore view's hand-rolled envelope check are gone.

--format json now emits the unwrapped rows as well. The table already
showed the objects, while the JSON showed the envelopes, so a script
had to know which of two wire shapes each index returns and dig through
"data" or "raw_data" itself. It is also the knife-compatible choice:
Chef's search client hands partial rows back as the projected data,
never the url/data envelope, and search(:bag) yields data bag items, not
their wrappers. total, start and rows keep their shape.

The node table's PLATFORM column now reads platform with Chef attribute
precedence rather than from automatic alone, matching node show.

Signed-off-by: Tim Smith <tsmith84@proton.me>
node ssh and node status decoded search rows themselves, and status did
it with its own attribute walker that swallowed decode errors, so a row
that wasn't a node became a blank line. Both now iterate cinc-api's
Search.Nodes and fail on a row that doesn't decode. status reads the
check-in with Node.LastCheckin (keeping fractional ohai_time) and its
host facts with Node.AttributeString, so an fqdn or platform set outside
automatic shows the way node[...] would read it. lookupAttribute and
attributeString are gone.

A node missing the --attribute host now names the node and suggests
--attribute, instead of "search row missing SSH attribute". node show
reads the environment with Node.EnvironmentName.

Signed-off-by: Tim Smith <tsmith84@proton.me>
…g changed

run-list, tag, environment-set, policy-set and the node edit form each
fetched the node, changed it, patched up a nil run list and PUT it back,
even when the change left the node as it was, and then reported the copy
they had sent. They now go through cinc-api's Nodes.Modify, which skips
the PUT when the node's JSON is unchanged. A no-op says so ("Node "web01"
already has that run list, so there's nothing to change: ..."), and a
real change reports the node the server answered with.

Run-list entries now follow the Chef Server's normalization: a bare
"nginx" is recipe[nginx], so add no longer appends "nginx" beside a
stored recipe[nginx], remove "nginx" drops recipe[nginx], and set stores
qualified entries.

The run-list and tag sub-groups were two copies of one builder; they are
now one nodeListField table each over a shared builder. tag list and
run-list list print [] rather than null under --format json for a node
with none. gatherCSVArgs sits beside splitCSV, and the nil run-list
guards in node and role create/edit are gone, since cinc-api always
encodes run_list as an array.

Signed-off-by: Tim Smith <tsmith84@proton.me>
Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 enabled auto-merge (squash) September 24, 2026 06:01
@tas50
tas50 merged commit 9e9b5a3 into main Sep 24, 2026
6 checks passed
@tas50
tas50 deleted the refactor/adopt-cinc-api-nodes-search branch September 24, 2026 06:07
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.

1 participant