clients

package
v1.7.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentUpdateState added in v1.6.19

func AgentUpdateState(clientUUID string) (target string, pendingClear bool, err error)

AgentUpdateState returns the rollout state the panel has persisted for one node. An empty target means the node tracks releases; pendingClear means an empty target still has to be delivered before that is actually true on the node. An unknown node is an error so a caller cannot mistake a stale UUID for "no pin".

AgentUpdateState 返回面板为某个节点持久化的 rollout 状态。空目标表示节点跟随 发布;pendingClear 表示这个空目标仍需下发一次,节点侧才算真的解除钉版本。 节点不存在时返回错误,避免调用方把过期的 UUID 误认为“未钉版本”。

func CreateClient

func CreateClient() (clientUUID, token string, err error)

CreateClient 创建新客户端

func CreateClientWithName

func CreateClientWithName(name string) (clientUUID, token string, err error)

func DeleteClient

func DeleteClient(clientUuid string) error

func DeleteClientAndReset added in v1.7.0

func DeleteClientAndReset(ctx context.Context, clientUUID string, reset func()) error

func GetAllClientBasicInfo

func GetAllClientBasicInfo() (clients []models.Client, err error)

func GetClientByUUID

func GetClientByUUID(uuid string) (client models.Client, err error)

// GetAllClients 获取所有客户端配置

func getAllClients() (clients []models.Client, err error) {
	db := dbcore.GetDBInstance()
	err = db.Find(&clients).Error
	if err != nil {
		return nil, err
	}
	return clients, nil
}

func GetClientTokenByUUID

func GetClientTokenByUUID(uuid string) (token string, err error)

func GetClientUUIDByToken

func GetClientUUIDByToken(token string) (clientUUID string, err error)

func GetClientUUIDByTokenContext added in v1.7.0

func GetClientUUIDByTokenContext(ctx context.Context, token string) (clientUUID string, err error)

func GetTargetVersion added in v1.6.16

func GetTargetVersion(clientUUID string) (string, error)

GetTargetVersion returns the persisted rollout target for one node. An empty result means the node follows releases; an unknown node is an error so a caller cannot mistake a stale UUID for "no pin".

GetTargetVersion 返回某个节点已持久化的 rollout 目标。空结果表示该节点跟随发布; 节点不存在时返回错误,避免调用方把过期的 UUID 误认为“未钉版本”。

func HiddenClients added in v0.1.13

func HiddenClients() (map[string]bool, error)

HiddenClients returns the uuid/hidden map for every client. Successful client writes invalidate the cache immediately; only uuid/hidden are loaded, never tokens or hardware details.

The result is a copy the caller owns. It used to hand back the cached map itself, so the "immutable snapshot" in the old comment was a convention rather than a property: one caller deleting or assigning an entry silently changed what every later caller saw, until the next client write refreshed the cache.

func NormalizeReportResources added in v1.6.29

func NormalizeReportResources(report *v2.Report) ([]string, error)

NormalizeReportResources tolerates inconsistent resource snapshots, but never repairs invalid values. Validate everything before modifying any field.

func ReportVerify

func ReportVerify(report v2.Report) error

检查数据防止异常数据导致数据库损坏

func RotateClientTokenAndReset added in v1.7.0

func RotateClientTokenAndReset(ctx context.Context, clientUUID string, reset func()) (string, error)

RotateClientTokenAndReset exposes the replacement only after commit and local invalidation. reset must not block on sockets, external providers or streams.

func SaveClient

func SaveClient(updates map[string]interface{}) error

func SaveClientInfo

func SaveClientInfo(update map[string]interface{}) error

func SaveClientInfoContext added in v1.7.0

func SaveClientInfoContext(ctx context.Context, update map[string]interface{}) error

func SetAgentUpdateState added in v1.6.19

func SetAgentUpdateState(clientUUID, target string, pendingClear bool) error

SetAgentUpdateState writes the rollout state the panel has persisted for one node: the target it should run (empty means "track releases") and whether a cleared target still has to be delivered.

pendingClear only matters when target is empty. An explicit target supersedes any pending clear, because the operator has just said what the node should run; a clear that could not be delivered needs the marker so the next connect re-sends it.

SetAgentUpdateState 写入面板为某个节点持久化的 rollout 状态:应运行的版本 (空表示跟随发布),以及被清除的目标是否仍待下发。

pendingClear 只在 target 为空时有意义。显式目标会覆盖任何待下发的清除标记, 因为操作员刚刚明确了该节点应运行的版本;而未能送达的清除需要这个标记,才能在 下次连接时重发。

func SetTargetVersion added in v1.6.16

func SetTargetVersion(clientUUID, target string) error

SetTargetVersion records the agent version the panel wants this node to run.

An empty target clears the pin, so the node tracks releases again. The panel stores this per node rather than relying on the dispatch that just happened: a node that is offline during a rollout, or an agent that restarted and lost the in-memory target, re-learns it when it next connects. Writing a target also settles any pending clear: the target is now decided.

SetTargetVersion 记录面板希望该节点运行的 agent 版本。

空目标表示清除钉版本,节点重新跟随发布。面板按节点持久化,而不是只依赖刚刚 那次下发:rollout 期间离线的节点、或重启后丢失内存目标的 agent,会在下次连接 时重新获知目标。写入目标同时会结清待下发的清除标记:目标此刻已确定。

func SetTargetVersionClearPending added in v1.6.19

func SetTargetVersionClearPending(clientUUID string, pending bool) error

SetTargetVersionClearPending flips only the pending-clear marker, leaving the target itself alone. The connection handler calls it once an explicit clear has actually been written to the node.

SetTargetVersionClearPending 只翻转“清除待下发”标记,不改动目标本身。连接 处理逻辑在显式清除真正写到节点之后调用它。

Types

type ClientInfoApplier added in v0.1.36

type ClientInfoApplier struct{}

ClientInfoApplier adapts SaveClient to internal/bulk's Applier.

It exists so bulk edits run through the *same* validation as a single-node edit rather than a second implementation of the rules, which is the whole reason `internal/bulk` takes an interface instead of a database handle. Two things about SaveClient make the adapter worth being explicit about rather than inlining a call:

  • It **writes into the map it is given** — `updated_at` is set on it, and `expired_at` is normalised in place. `bulk.Apply` hands each node its own copy for that reason, so one node's timestamp cannot land on the next node's request.
  • It returns the applier's own error text, which is what the per-node report shows. A generic "failed" would make the operator re-derive the reason by hand.

func (ClientInfoApplier) SaveClientInfo added in v0.1.36

func (ClientInfoApplier) SaveClientInfo(update map[string]interface{}) error

SaveClientInfo applies one partial update. Named for the operation, not the receiver, so it satisfies bulk.Applier without the caller importing this package's shape.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL