Consolidate broker credential generation
Problem
Broker credential generation is copy-pasted per entity. forge/db/controllers/BrokerClient.js has six near-identical createClientFor* functions (Project, Device, Frontend, ExpertAgent, ExpertClient, TeamFrontend), each repeating: build username, find-and-destroy any existing row, generate a 32-byte password, insert a row, return { url, username, password }. The matching API endpoints repeat the same broker-check / 503 / shape boilerplate.
Each new sync-able entity (instances, devices, apps — see team-channel work) adds another near-duplicate.
Proposal
Extract the shared create/replace/return logic into one helper; let each createClientFor* just supply its username scheme and owner metadata. Optionally consolidate the endpoint-side boilerplate too.
Notes
- Cleanup/refactor only — no behavior change.
- Surfaced during the team-channel PR (
comms-credentials endpoint reused the expert-client pattern verbatim).
Consolidate broker credential generation
Problem
Broker credential generation is copy-pasted per entity.
forge/db/controllers/BrokerClient.jshas six near-identicalcreateClientFor*functions (Project,Device,Frontend,ExpertAgent,ExpertClient,TeamFrontend), each repeating: build username, find-and-destroy any existing row, generate a 32-byte password, insert a row, return{ url, username, password }. The matching API endpoints repeat the same broker-check / 503 / shape boilerplate.Each new sync-able entity (instances, devices, apps — see team-channel work) adds another near-duplicate.
Proposal
Extract the shared create/replace/return logic into one helper; let each
createClientFor*just supply its username scheme and owner metadata. Optionally consolidate the endpoint-side boilerplate too.Notes
comms-credentialsendpoint reused the expert-client pattern verbatim).