etcd_svc

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdKV

type EtcdKV struct {
	Key            string `json:"key"`
	Value          string `json:"value"`
	ModRevision    int64  `json:"modRevision"`
	CreateRevision int64  `json:"createRevision"`
	Version        int64  `json:"version"`
	Lease          int64  `json:"lease"`
}

EtcdKV 是返回给 IPC 的 KV 投影,屏蔽 etcd 内部 protobuf 类型。

type ExecRequest

type ExecRequest struct {
	AssetID    int64
	Op         string
	Key        string
	Value      string
	Prefix     bool
	Limit      int64
	Revision   int64
	LeaseID    int64
	Args       map[string]any
	ApprovalID string
	Source     string
}

ExecRequest 是 etcd 服务层操作请求,既给 IPC 用,也给 Dispatch 用。

func ParseCommand

func ParseCommand(s string) (*ExecRequest, error)

ParseCommand 解析查询面板的字符串命令。 不追求 etcdctl 完全兼容,只识别支持的子集:

<op> [key] [value...] [--flag] [--flag=val]

复合命令 "member list" / "endpoint status" / "lease grant" 自动归一为下划线形式。

type ExecResult

type ExecResult struct {
	Op       string   `json:"op"`
	KVs      []EtcdKV `json:"kvs,omitempty"`
	Count    int64    `json:"count"`
	Revision int64    `json:"revision"`
}

ExecResult 是 etcd 操作的统一返回。

func Dispatch

func Dispatch(ctx context.Context, client *clientv3.Client, req *ExecRequest) (*ExecResult, error)

Dispatch 按 op 路由到细分 dispatch 函数。 接收 *clientv3.Client(嵌入 KV/Lease/Cluster/Maintenance 接口), per-op 函数仍取窄接口以便 mock 单测。

type ListPrefixRequest

type ListPrefixRequest struct {
	AssetID int64
	Prefix  string
	Delim   string // 默认 "/"
	Limit   int64  // 默认 1000
}

ListPrefixRequest 是 KV 树懒加载的入参。

type ListPrefixResult

type ListPrefixResult struct {
	Dirs      []string `json:"dirs"`
	Leaves    []EtcdKV `json:"leaves"`
	Truncated bool     `json:"truncated"`
}

ListPrefixResult 是 KV 树懒加载的返回。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 是 etcd 资产的服务层入口,负责:

  • 资产查找与类型校验
  • 凭证解密
  • 连接复用 / 即时拨号
  • 命令分发 (Dispatch)
  • 关键流程三态日志

策略检查与审计在调用方(AI Runner / IPC 绑定层)完成,Service 本身不感知策略。

func New

func New(sshPool *sshpool.Pool) *Service

New 创建 etcd 服务实例。

func (*Service) Exec

func (s *Service) Exec(ctx context.Context, req *ExecRequest) (*ExecResult, error)

Exec 执行一次 etcd 操作 (get/put/del/lease/...)。

func (*Service) ListPrefix

func (s *Service) ListPrefix(ctx context.Context, req *ListPrefixRequest) (*ListPrefixResult, error)

ListPrefix 按指定 prefix + 分隔符切分出当前层级的子目录与叶子, 用于 KV 树的懒加载。返回的叶子不带 value (KeysOnly)。

func (*Service) TestConfig

func (s *Service) TestConfig(ctx context.Context, cfg *asset_entity.EtcdConfig, password string) error

TestConfig 用「未保存的配置」即时拨号一次,用于资产表单上的「测试连接」。 与 TestConnection 的区别:不通过 assetID 查找资产,而是接受调用方拼好的 cfg + 已解密的密码。

func (*Service) TestConnection

func (s *Service) TestConnection(ctx context.Context, assetID int64) error

TestConnection 即时拨号一次,验证配置可达。不进缓存,完成后立即关闭。

Directories

Path Synopsis
Package mock_kv is a generated GoMock package.
Package mock_kv is a generated GoMock package.

Jump to

Keyboard shortcuts

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