Skip to content

Consolidate broker credential generation #7441

@n-lark

Description

@n-lark

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).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions