engineutil

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engineutil 提供 core/engine 使用的 100% 无状态纯辅助函数: 涵盖公开哨兵错误与分组映射、枚举文本编解码、配置字段归一化与事件流辅助。

本包属 LayerCoreEngine 无环内部叶包(0 sshnet/*、0 sync、0 net、0 状态), 构造期协议端口与服务装配归属 core/engine/internal/assembly,生产代码严禁导入 tck 与 sim。

Index

Constants

View Source
const (
	DefaultSystemBusBuffer       = 64
	DefaultOperationStreamBuffer = 64
)

Engine 事件流与诊断总线默认缓冲区大小。

Variables

View Source
var (
	ErrNilContext               = domi18n.Sentinel(domi18n.KeyEngineNilContext)
	ErrInvalidConfig            = domi18n.Sentinel(domi18n.KeyEngineInvalidConfig)
	ErrEngineNotInitialized     = domi18n.Sentinel(domi18n.KeyEngineNotInitialized)
	ErrEngineClosed             = domi18n.Sentinel(domi18n.KeyEngineClosed)
	ErrEngineHalted             = domi18n.Sentinel(domi18n.KeyEngineHalted)
	ErrInvalidRequest           = domi18n.Sentinel(domi18n.KeyEngineInvalidRequest)
	ErrInvalidProfile           = domi18n.Sentinel(domi18n.KeyEngineInvalidProfile)
	ErrInvalidFallback          = domi18n.Sentinel(domi18n.KeyEngineInvalidFallback)
	ErrInvalidRequestTTY        = domi18n.Sentinel(domi18n.KeyEngineInvalidReqTTY)
	ErrReconcilerUnavailable    = domi18n.Sentinel(domi18n.KeyEngineReconcilerUnav)
	ErrVaultUnavailable         = domi18n.Sentinel(domi18n.KeyEngineVaultUnavail)
	ErrMCPServerNotInitialized  = domi18n.Sentinel(domi18n.KeyEngineMCPNotInit)
	ErrProjectionNotInitialized = domi18n.Sentinel(domi18n.KeyEngineProjNotInit)
	ErrApprovalRequired         = domi18n.Sentinel(domi18n.KeyEngineApprovalReq)
	ErrApprovalRejected         = domi18n.Sentinel(domi18n.KeyEngineApprovalReject)
	ErrAuthorizationDenied      = domi18n.Sentinel(domi18n.KeyEngineAuthDenied)
	ErrScopeEscalated           = domi18n.Sentinel(domi18n.KeyEngineScopeEscalated)
	ErrNotFound                 = domi18n.Sentinel(domi18n.KeyEngineNotFound)
	ErrAlreadyExists            = domi18n.Sentinel(domi18n.KeyEngineAlreadyExists)
	ErrRevisionConflict         = domi18n.Sentinel(domi18n.KeyEngineRevisionConf)
	ErrStillReferenced          = domi18n.Sentinel(domi18n.KeyEngineStillReferenced)
	ErrImportConflict           = domi18n.Sentinel(domi18n.KeyEngineImportConflict)
	ErrUncertainDurability      = domi18n.Sentinel(domi18n.KeyEngineUncertainDur)
	ErrOutcomeUnknown           = domi18n.Sentinel(domi18n.KeyEngineOutcomeUnknown)
	ErrVaultLocked              = domi18n.Sentinel(domi18n.KeyEngineVaultLocked)
	ErrSecretNotFound           = domi18n.Sentinel(domi18n.KeyEngineSecretNotFound)
	ErrAuthFailed               = domi18n.Sentinel(domi18n.KeyEngineAuthFailed)
	ErrHostKeyUnknown           = domi18n.Sentinel(domi18n.KeyEngineHostKeyUnknown)
	ErrHostKeyMismatch          = domi18n.Sentinel(domi18n.KeyEngineHostKeyMismatch)
	ErrHostKeyRevoked           = domi18n.Sentinel(domi18n.KeyEngineHostKeyRevoked)
	ErrDialFailed               = domi18n.Sentinel(domi18n.KeyEngineDialFailed)
	ErrControlMasterDisabled    = domi18n.Sentinel(domi18n.KeyEngineMuxDisabled)
	ErrMuxUnavailable           = domi18n.Sentinel(domi18n.KeyEngineMuxUnavailable)
	ErrHandleNotFound           = domi18n.Sentinel(domi18n.KeyEngineHandleNotFound)
	ErrHandleRevoked            = domi18n.Sentinel(domi18n.KeyEngineHandleRevoked)
	ErrInteractionUnavailable   = domi18n.Sentinel(domi18n.KeyEngineInteractUnav)
	ErrInteractionCanceled      = domi18n.Sentinel(domi18n.KeyEngineInteractCancel)
	ErrRemoteAnchorMismatch     = domi18n.Sentinel(domi18n.KeyEngineAnchorMismatch)
	ErrRemoteIsDir              = domi18n.Sentinel(domi18n.KeyEngineRemoteIsDir)
	ErrNotRegularFile           = domi18n.Sentinel(domi18n.KeyEngineNotRegularFile)
	ErrPatchConflict            = domi18n.Sentinel(domi18n.KeyEnginePatchConflict)
	ErrDigestMismatch           = domi18n.Sentinel(domi18n.KeyEngineDigestMismatch)
	ErrSymlinkRejected          = domi18n.Sentinel(domi18n.KeyEngineSymlinkReject)
	ErrCorruptData              = domi18n.Sentinel(domi18n.KeyEngineCorruptData)
	ErrLimitExceeded            = domi18n.Sentinel(domi18n.KeyEngineLimitExceeded)
	ErrUnsupported              = domi18n.Sentinel(domi18n.KeyEngineUnsupported)
	ErrCanonicalizeFailed       = ucinv.ErrCanonicalizeFailed
	ErrEscapeDisconnected       = ucsess.ErrEscapeDisconnected
)

不可变公开规范哨兵错误,由父包 core/engine 只读重导出以保持指针同一性。

Functions

func AppendValidEnumText

func AppendValidEnumText(b []byte, valid bool, name string, baseErr error, raw uint8) ([]byte, error)

AppendValidEnumText 在枚举有效时向字节缓冲追加其名称,否则返回结构化错误。

func BuildPoolConfig

func BuildPoolConfig(in PoolConfigInput) (pool.PoolConfig, error)

BuildPoolConfig 校验可选连接池时长参数并构造 pool.PoolConfig。

func ChallengeReasonParam

func ChallengeReasonParam(valid bool, reasonMsg algebraic.Option[domi18n.Message], reason, key string) domi18n.Param

ChallengeReasonParam 将审批挑战原因投影为结构化 domi18n.Param(无效零值失败关闭至默认审批原因)。

func CloseOpStreams

func CloseOpStreams(main *events.OperationStream, extras map[inventory.NodeID]*events.OperationStream)

CloseOpStreams 闭合主事件流与全部节点子事件流。

func CloseStreamIfNonNil

func CloseStreamIfNonNil(s *events.OperationStream)

CloseStreamIfNonNil 在事件流非空时关闭以保证确定性 EOF。

func CompileExecCommandPlan

func CompileExecCommandPlan(planOpt algebraic.Option[execution.CommandPlan], rawCmd string, args []string, timeout algebraic.Option[algebraic.Duration]) (execution.CommandPlan, error)

CompileExecCommandPlan 校验互斥三选一命令来源(CommandPlan / Command / CommandArgs)并编译不可变 CommandPlan。

func CompileGuardrailPolicy

func CompileGuardrailPolicy(in GuardrailInput) (gate.GuardrailPolicy, error)

CompileGuardrailPolicy 解析受保护路径模式与 UTF-8 Glob 命令黑名单并编译不可变 gate.GuardrailPolicy。

func CompileOptionalExecCommandPlan

func CompileOptionalExecCommandPlan(planOpt algebraic.Option[execution.CommandPlan], rawCmd string, args []string, timeout algebraic.Option[algebraic.Duration]) (algebraic.Option[execution.CommandPlan], error)

CompileOptionalExecCommandPlan 校验可选互斥命令来源(0 或 1 项):全部未提供时返回 None,提供 1 项时编译不可变 CommandPlan。

func ForwardBindOptionsFromPolicy

func ForwardBindOptionsFromPolicy(pol option.EffectivePolicy) (ports.ForwardBindOptions, error)

ForwardBindOptionsFromPolicy 将已折叠四层 OpenSSH 策略投影为不可变 ports.ForwardBindOptions。

func LookupEnumName

func LookupEnumName(idx uint8, fallback string, names ...string) string

LookupEnumName 按索引查找枚举规范名称,越界回退 fallback。

func MapEngineError

func MapEngineError(err error) error

MapEngineError 按目标门面哨兵分组收集全部命中的底层源哨兵(保首次命中序), 并逆序经 domi18n.WrapSentinel 封装以完整保留错误链与结构化无损折叠渲染。

func MapEnum

func MapEnum[F ~uint8, T any](v F, ok bool, baseErr error, table ...T) (T, error)

MapEnum 将底层为 uint8 的枚举按查表投影为目标类型,越界或无效时返回结构化错误。

func MapMCPError

func MapMCPError(err error) error

MapMCPError 将 mcpruntime 配置错误叠加至 ErrInvalidConfig 哨兵链,并执行统一门面哨兵映射。

func MapRes

func MapRes[T any](v T, err error) (T, error)

MapRes 对 (T, error) 返回值执行门面语义哨兵映射。

func MirrorForwardAgentIntoCLI

func MirrorForwardAgentIntoCLI(
	hasPreResolved bool,
	cliOpts option.OptionLayer,
	reqFA algebraic.Option[option.ForwardAgentSpec],
) option.OptionLayer

MirrorForwardAgentIntoCLI 在未提供预解析目标且 CLIOptions 未显式设置 ForwardAgent 时, 将请求级显式 ForwardAgent 镜像写入 CLIOptions,使密封跳板 hop.Transport().ForwardAgent() 与 dial.Dialer 纵深护栏保持一致(ADR-019 v2.2 S3-Q2)。

func NewApprovalSubmission

func NewApprovalSubmission(verdict security.Verdict, envelopeDigest security.Digest, envelope algebraic.Option[security.ApprovalEnvelope], comment string) (gate.ApprovalSubmission, error)

NewApprovalSubmission 校验用户审批判定、信封 SHA-256 摘要与可选完整信封,构造 gate.ApprovalSubmission。

func NewOperationStream

func NewOperationStream(entropy ports.Entropy, buffer int) (*events.OperationStream, error)

NewOperationStream 从显式熵源生成 TraceID/OperationID 并构造单次操作隔离事件流。

func NormalizeMuxSocketKey

func NormalizeMuxSocketKey(raw string) string

NormalizeMuxSocketKey 规范化跨平台 ControlMaster 套接字路径键(剥离 \\?\、统一斜杠、去前导 ./ 与小写 Windows 盘符)。

func NotStartedOutcome

func NotStartedOutcome(phase execution.StartPhase, code string, err error) execution.ExecutionOutcome

NotStartedOutcome 构造启动前失败的不可变 OutcomeNotStarted。

func OptPosStdDuration

func OptPosStdDuration(opt algebraic.Option[algebraic.Duration], name string) (time.Duration, error)

OptPosStdDuration 校验可选正时长配置并转换为标准 time.Duration。

func ParseEnumPairs

func ParseEnumPairs[T any](raw string, zero T, baseErr error, pairs ...EnumPair[T]) (T, error)

ParseEnumPairs 按大小写无关且裁剪空白的方式匹配枚举键列表,未命中返回绑定值的结构化错误。

func ResolveHostTrustDirs

func ResolveHostTrustDirs(homeDir, khDirOpt algebraic.Option[pathalg.LocalDir], env ports.EnvPort) (homeOpt algebraic.Option[pathalg.LocalDir], khDir pathalg.LocalDir, err error)

ResolveHostTrustDirs 解析 KnownHostsDB 所需的 HomeDir 与默认 known_hosts 目录(~/.ssh)。

func ResolveSessionAgentOverrides

ResolveSessionAgentOverrides 当会话请求未显式覆写 ForwardAgent/IdentityAgent 时, 从已解析 EffectivePolicy 透传真实四态 ForwardAgentSpec(含自定义套接字路径)与 IdentityAgentSpec, 避免仅靠布尔跳板位回退为 "default" 导致自定义代理路径丢失(ADR-019 v2.2 P1-1)。

func ResolveSystemBus

func ResolveSystemBus(existing *events.SystemBus, buf int) (*events.SystemBus, bool, error)

ResolveSystemBus 在调用方未注入 SystemBus 时按默认缓冲区容量创建自有总线。

func RollbackNew

func RollbackNew(opCancel context.CancelCauseFunc, p *pool.Pool, ownsBus bool, bus *events.SystemBus, cause error)

RollbackNew 在 Engine.New 装配失败时同步回滚已建上下文、连接池与自有诊断总线。

func TakeMapKeys

func TakeMapKeys[K comparable](m map[K]struct{}) []K

TakeMapKeys 抽取映射全部键切片并清空原映射。

func ToAutoTargetNodes

func ToAutoTargetNodes(targets []ucinv.ResolvedTarget) ([]ucauto.TargetNode, error)

ToAutoTargetNodes 将公开 ResolvedTarget 切片直接转换为 automation.TargetNode: 托管及 OpenSSH 派生目标直接消费解析期快照的不可变 Tags、NodeExecution(不含 Global 兜底,避免反向遮蔽 PlaybookSettings)、 Privilege 与 PrivilegePasswordRef,严禁隐式二次 ListNodes 门控与幽灵审计。

func UnmarshalEnumText

func UnmarshalEnumText[T any](dst *T, zero T, text []byte, nilErr error, parse func(string) (T, error)) error

UnmarshalEnumText 统一实现公开枚举类型的 TextUnmarshaler 逻辑。

func ValidOrZero

func ValidOrZero[T any](valid bool, v T) T

ValidOrZero 在 valid 为 true 时返回 v,否则返回类型 T 的零值。

func ValidateBaseDeps

func ValidateBaseDeps(clk ports.Clock, ent ports.Entropy, audit ports.AuditSink, bus *events.SystemBus, busBuf int) error

ValidateBaseDeps 校验 Engine 必填基础设施端口与 SystemBus 合法性。

func WrapCfgFieldErr

func WrapCfgFieldErr(field string, err error) error

WrapCfgFieldErr 将配置字段校验错误包裹至 ErrInvalidConfig 哨兵链。

func WrapInitErr

func WrapInitErr(component string, err error) error

WrapInitErr 将组件装配期底层错误包裹至 ErrInvalidConfig 哨兵链。

func ZeroVal

func ZeroVal[T any]() (z T)

ZeroVal 返回任意类型 T 的零值。

Types

type EnumPair

type EnumPair[T any] struct {
	Key string
	Val T
}

EnumPair 表示枚举解析器的文本键值映射项。

type GuardrailInput

type GuardrailInput struct {
	ApprovalThreshold    security.RiskLevel
	NoElicitFallback     gate.NoElicitFallback
	NodeOverrides        algebraic.Option[security.NodeOverrides]
	BlockedCommands      algebraic.Option[security.BlockedCommandMatcher]
	BlockedPatterns      []string
	ProtectedRules       []pathalg.ProtectedRule
	ProtectedPatterns    []string
	ProtectedPathRisk    algebraic.Option[security.RiskLevel]
	ApprovalTTL          algebraic.Option[algebraic.Duration]
	MaxPendingChallenges int
	MaxReplayHistory     int
}

GuardrailInput 描述编译 gate.GuardrailPolicy 所需的归一化输入参数。

type PoolConfigInput

type PoolConfigInput struct {
	Dialer            ports.DialerPort
	Clock             ports.Clock
	Entropy           ports.Entropy
	Bus               *events.SystemBus
	AcquireBuffer     int
	MaxConns          int
	MaxHandles        int
	TeardownGrace     algebraic.Option[algebraic.Duration]
	IdleTTL           algebraic.Option[algebraic.Duration]
	KeepaliveInterval algebraic.Option[algebraic.Duration]
}

PoolConfigInput 描述构造 pool.PoolConfig 所需的全部归一化入参。

type RefConflictData

type RefConflictData struct {
	AssetKind  string
	Subject    string
	AssetRefs  []inventory.AssetReference
	SecretRefs []inventory.SecretReference
}

RefConflictData 封装从错误链中提取的资产或凭据引用冲突纯数据载荷。

func ExtractRefConflictData

func ExtractRefConflictData(err error) (RefConflictData, bool)

ExtractRefConflictData 从错误链提取资产反向引用或凭据引用冲突数据。

Jump to

Keyboard shortcuts

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