Documentation
¶
Overview ¶
Package plugincatalog 是插件事实的只读、租户作用域视图:合并 Registry lockfile/manifest(安装事实)、plugincontrol desired state(期望状态)、 pluginhost observed snapshot/metrics(观测状态),为 WebUI 与自动化提供稳定 API。
安全边界(docs/api.md 插件目录):视图只携带白名单字段,绝不返回安装本地绝对路径、 proof、env 或 config secret 值;desired 与 observed 严格分离,Host 未运行时 observed 为 unknown,绝不根据 desired_enabled 虚报 HEALTHY。
Index ¶
- func APIInstanceView(in ProjectionInstance) api.PluginInstanceView
- func InstanceViews(src ProjectionSource, tenant string) ([]api.PluginInstanceView, error)
- func SanitizeDetail(s string) string
- type ApplicationContributionView
- type Catalog
- type ConnectorContributionView
- type ContributesView
- type DriverContributionView
- type InstanceView
- type MetricsView
- type Observed
- type PermissionsView
- type PluginView
- type ProjectionInstance
- type ProjectionSource
- type Reader
- type SourceReader
- func (r *SourceReader) DesiredStates(tenant string) ([]plugincontrol.InstanceState, error)
- func (r *SourceReader) Lockfile() (*registry.LockFile, error)
- func (r *SourceReader) Manifest(pluginID string) (*registry.Manifest, error)
- func (r *SourceReader) Metrics(tenant, instanceID string) (pluginhost.Metrics, bool)
- func (r *SourceReader) Observed(tenant, instanceID string) (Observed, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIInstanceView ¶
func APIInstanceView(in ProjectionInstance) api.PluginInstanceView
APIInstanceView 是单实例的契约视图映射(纯函数,便于反向测试)。
func InstanceViews ¶
func InstanceViews(src ProjectionSource, tenant string) ([]api.PluginInstanceView, error)
InstanceViews 构造契约视图(GET /api/plugin-instances 的载荷)。 desired 与 observed 永远分开呈现:无 observed 时 Observed 为 nil。
func SanitizeDetail ¶
SanitizeDetail 对 Edge 上报的错误摘要做防御性脱敏:截断长度、抹掉本机绝对路径 与疑似凭据值。Edge 侧本应已脱敏(control-plane-sync §2 不变量 6),这里是 Server 不信任下游输入的第二道闸:任何响应体都不得泄漏 secret 明文或本机路径。
Types ¶
type ApplicationContributionView ¶
type ApplicationContributionView struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
}
ApplicationContributionView 是一个 Application 贡献。requirements 可能携带任意 载荷,为避免泄漏不暴露,仅保留 id/title。
type Catalog ¶
type Catalog interface {
Plugins(tenant string) ([]PluginView, error)
Plugin(tenant, id string) (PluginView, bool, error)
Instances(tenant string) ([]InstanceView, error)
Instance(tenant, id string) (InstanceView, bool, error)
}
Catalog 是 server 消费的只读 API 视图接口。实现可被注入,nil 时 server 返回空列表。
func NewProjectionCatalog ¶
func NewProjectionCatalog(src ProjectionSource) Catalog
NewProjectionCatalog 用 Server 投影构造只读目录,替换任何 fake/静态来源。 src 为 nil 时返回空目录(永不 panic)。
type ConnectorContributionView ¶
type ConnectorContributionView struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
Direction string `json:"direction,omitempty"`
Host string `json:"host,omitempty"`
}
ConnectorContributionView 是一个 Connector 贡献。
type ContributesView ¶
type ContributesView struct {
Drivers []DriverContributionView `json:"drivers,omitempty"`
Applications []ApplicationContributionView `json:"applications,omitempty"`
Connectors []ConnectorContributionView `json:"connectors,omitempty"`
}
ContributesView 是插件声明的贡献。路径类字段只保留相对引用,本地绝对路径被丢弃。
type DriverContributionView ¶
type DriverContributionView struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
Descriptor string `json:"descriptor,omitempty"`
ConfigSchema string `json:"configSchema,omitempty"`
Discovery string `json:"discovery,omitempty"`
CapabilityCatalog string `json:"capabilityCatalog,omitempty"`
}
DriverContributionView 是一个 Driver 贡献。
type InstanceView ¶
type InstanceView struct {
Tenant string `json:"tenant"`
EdgeID string `json:"edge_id"`
ID string `json:"id"`
Plugin string `json:"plugin"`
Version string `json:"version"`
DesiredEnabled bool `json:"desired_enabled"`
ObservedState string `json:"observed_state"`
Health string `json:"health"`
DataPreserved bool `json:"data_preserved"`
ConfigPresent bool `json:"config_present"`
// Drift 表示 desired_revision 与 applied_revision 不一致(期望已变、Edge 未确认)。
Drift bool `json:"drift"`
// Stale 表示 observed 投影过期或所属 edge 离线;只标记,绝不改写 desired。
Stale bool `json:"stale"`
Metrics MetricsView `json:"metrics"`
}
InstanceView 是单个插件实例的期望+观测视图。desired_enabled 与 observed_state 相互独立;Host 未运行时 observed_state/health 为 unknown。
type MetricsView ¶
type MetricsView struct {
CPUTime int64 `json:"cpu_ms"`
RSSBytes int64 `json:"rss_bytes"`
Handles int `json:"handles"`
Goroutines int `json:"goroutines"`
MessageRate float64 `json:"message_rate"`
RestartCount int `json:"restart_count"`
LastHealthy int64 `json:"last_healthy"`
}
MetricsView 是实例的脱敏资源指标快照。不可观测字段以 -1 标记 unavailable。
type Observed ¶
type Observed struct {
HostOnline bool
State pluginhost.State
Health pluginhost.Health
}
Observed 是单实例的点时刻观测运行时状态。
type PermissionsView ¶
type PermissionsView struct {
Hardware []string `json:"hardware,omitempty"`
Network []string `json:"network,omitempty"`
Filesystem []string `json:"filesystem,omitempty"`
Secrets []string `json:"secrets,omitempty"`
}
PermissionsView 是权限披露(请求的名字,非 secret 值)。
type PluginView ¶
type PluginView struct {
ID string `json:"id"`
Kind string `json:"kind"`
Version string `json:"version"`
Source string `json:"source"`
Digest string `json:"digest"`
Verified bool `json:"verified"`
Compatibility string `json:"compatibility,omitempty"`
Protocol int `json:"protocol"`
Permissions PermissionsView `json:"permissions"`
Contributes ContributesView `json:"contributes"`
}
PluginView 是单个已安装插件的脱敏事实视图。
type ProjectionInstance ¶
type ProjectionInstance struct {
TenantID int64
Tenant string
EdgeID string
InstanceID string
PluginID string
Version string
Enabled bool
Isolation string
// Config 只含非敏感标量与 secret://<name> handle(写入时已拒绝明文凭据)。
Config map[string]string
// ConfigPresent 只表示「有非敏感配置」,绝不携带 secret 明文。
ConfigPresent bool
// SecretRefs 只含 secret://<name> handle 名。
SecretRefs []string
HasObserved bool
// ObservedVersion 是 Edge 上报的实际版本,与 desired Version 分别承载:
// 只有 observed 的实例(Server 无期望态)不得把上报值塞进 desired 子视图。
ObservedVersion string
State string
Health string
Detail string
RestartCount int
LastHealthy int64
ReportedAt int64
MessageRate float64
EdgeOnline bool
DesiredRevision uint64
AppliedRevision uint64
Drift bool
Stale bool
LastAckAt int64
UpdatedAt int64
RowRevision uint64
}
ProjectionInstance 是 Server 侧「desired + observed」合成后的单实例事实。
不变量(docs/architecture/control-plane-sync.md §2):
- HasObserved=false 表示 Edge 从未上报过该实例,Observed 必须为 null, 绝不把 desired enabled 渲染成 observed healthy;
- Drift = desired_revision != applied_revision(期望已变但 Edge 未确认收敛);
- Stale = 投影过期或所属 edge 离线(只标记,不改写 desired)。
type ProjectionSource ¶
type ProjectionSource interface {
// Installations 返回租户可见的已安装插件公开事实(Edge 上报投影)。
Installations(tenant string) ([]api.PluginInstallationStatusData, error)
// Instances 返回租户可见的插件实例合成事实(desired + observed)。
Instances(tenant string) ([]ProjectionInstance, error)
}
ProjectionSource 是 Server 投影的只读源(由 internal/server 实现并注入)。 tenant 为租户 slug,与 Catalog 接口保持一致;空串表示全部租户(开发/全局形态)。
实现必须是真实投影:安装物只来自 Edge 上报,期望态只来自 Server 权威存储。 禁止用静态/内置样例数据填充。
type Reader ¶
type Reader interface {
// Lockfile 返回安装锁文件。
Lockfile() (*registry.LockFile, error)
// Manifest 返回 pluginID 的已安装 manifest。
Manifest(pluginID string) (*registry.Manifest, error)
// DesiredStates 返回租户的期望实例状态;空 tenant 表示全部租户(开发/全局形态)。
DesiredStates(tenant string) ([]plugincontrol.InstanceState, error)
// Observed 返回单实例的观测运行时状态;ok=false 表示 Host 未运行或无法观测。
Observed(tenant, instanceID string) (Observed, bool)
// Metrics 返回点时刻资源指标;ok=false 表示不可用。
Metrics(tenant, instanceID string) (pluginhost.Metrics, bool)
}
Reader 是 catalog 的可注入源契约。调用方注入 lockfile/manifest/state/observed/ metrics 读取器;plugincatalog 本身不构造真实文件系统/Host 源。
nil 或失败的 observed/metrics 读取器不得让插件安装事实变成硬错误:调用方用 ok=false 表示未观测/失败,catalog 把 observed 标为 unknown。manifest/lock 读取 失败属于数据损坏,fail-closed(返回 error,由 caller 映射为 500)。
type SourceReader ¶
type SourceReader struct {
LockfileFn func() (*registry.LockFile, error)
ManifestFn func(pluginID string) (*registry.Manifest, error)
DesiredFn func(tenant string) ([]plugincontrol.InstanceState, error)
ObservedFn func(tenant, instanceID string) (Observed, bool)
MetricsFn func(tenant, instanceID string) (pluginhost.Metrics, bool)
}
SourceReader 是由可注入函数字段组装的 Reader。nil 字段按空/不可用处理,调用方 只提供手头有的源(例如无运行中的 Host 时 observed/metrics 恒为 unknown)。
func (*SourceReader) DesiredStates ¶
func (r *SourceReader) DesiredStates(tenant string) ([]plugincontrol.InstanceState, error)
func (*SourceReader) Manifest ¶
func (r *SourceReader) Manifest(pluginID string) (*registry.Manifest, error)
func (*SourceReader) Metrics ¶
func (r *SourceReader) Metrics(tenant, instanceID string) (pluginhost.Metrics, bool)