Documentation
¶
Index ¶
- Variables
- func DownloadDeliveryMode(cfg config.MCP) string
- func FormatLogLine(line LogLine, ansi bool) string
- type AccountView
- type AccountsInput
- type AliasView
- type AliasesInput
- type AssetInput
- type AssetResult
- type AssetView
- type AssetsInput
- type AuthReader
- type CallDetails
- type CancelInput
- type CloseInput
- type ConfigReader
- type ConnectionInput
- type ConnectionView
- type Connector
- func (c Connector) Dial(ctx context.Context, r ResolvedTarget) (*ssh.Client, error)
- func (c Connector) OpenDownloadSFTP(ctx context.Context, r ResolvedTarget) (DownloadSFTP, error)
- func (c Connector) Resolve(ctx context.Context, in Target) (ResolvedTarget, error)
- func (c Connector) Validate(ctx context.Context, r ResolvedTarget) error
- type DownloadIDInput
- type DownloadInput
- type DownloadLink
- type DownloadProgress
- type DownloadRemote
- type DownloadRename
- type DownloadResult
- type DownloadSFTP
- type DownloadView
- type DownloadedFile
- type DownloadsPageInput
- type Engine
- func (e *Engine) CancelDownload(_ context.Context, in DownloadIDInput) (DownloadView, error)
- func (e *Engine) CancelExecution(ctx context.Context, in CancelInput) (ExecutionView, error)
- func (e *Engine) CloseConnection(ctx context.Context, in CloseInput) (ConnectionView, error)
- func (e *Engine) ConnectionsPage(ctx context.Context, in PageInput) (Page[ConnectionView], error)
- func (e *Engine) DownloadFiles(ctx context.Context, in DownloadInput) (DownloadView, error)
- func (e *Engine) DownloadsPage(_ context.Context, in DownloadsPageInput) (Page[DownloadView], error)
- func (e *Engine) Execute(ctx context.Context, in ExecuteInput) (ExecutionView, error)
- func (e *Engine) ExecutionsPage(ctx context.Context, in ExecutionsPageInput) (Page[ExecutionView], error)
- func (e *Engine) GetConnection(_ context.Context, in ConnectionInput) (ConnectionView, error)
- func (e *Engine) GetDownload(ctx context.Context, in GetDownloadInput) (DownloadView, error)
- func (e *Engine) GetExecution(ctx context.Context, in GetExecutionInput) (ExecutionView, error)
- func (e *Engine) Limits() map[string]int64
- func (e *Engine) ListConnections(_ context.Context, _ struct{}) ([]ConnectionView, error)
- func (e *Engine) ListExecutions(_ context.Context, in ListExecutionsInput) ([]ExecutionView, error)
- func (e *Engine) Open(ctx context.Context, in OpenInput) (OpenResult, error)
- func (e *Engine) RecordCall(name string, err error, details ...CallDetails)
- func (e *Engine) RequestEpoch() uint64
- func (e *Engine) Retire()
- func (e *Engine) Shutdown(ctx context.Context) error
- func (e *Engine) Stats() EngineStats
- type EngineOptions
- type EngineStats
- type ExecuteInput
- type ExecutionView
- type ExecutionsPageInput
- type Fault
- type GetDownloadInput
- type GetExecutionInput
- type HandlerFactory
- type History
- type IdentitySource
- type Instance
- type Limits
- type ListExecutionsInput
- type LogLine
- type LogPage
- type OpenInput
- type OpenResult
- type OutputChunk
- type OutputView
- type Page
- type PageInput
- type ProfilePageInput
- type ProfileView
- type ProtocolView
- type Queries
- func (q *Queries) GetAsset(ctx context.Context, input AssetInput) (AssetResult, error)
- func (q *Queries) ListAccounts(ctx context.Context, input AccountsInput) (Page[AccountView], error)
- func (q *Queries) ListAliases(ctx context.Context, input AliasesInput) (Page[AliasView], error)
- func (q *Queries) ListAssets(ctx context.Context, input AssetsInput) (Page[AssetView], error)
- func (q *Queries) ListOrganizations(ctx context.Context, input ProfilePageInput) (Page[jumpserver.Organization], error)
- func (q *Queries) ListProfiles(ctx context.Context, input PageInput) (Page[ProfileView], error)
- type QueryError
- type ResolvedTarget
- type ResourceReader
- type Runtime
- func (r *Runtime) CloseConnection(ctx context.Context, input CloseInput) (ConnectionView, error)
- func (r *Runtime) Connections(ctx context.Context) ([]ConnectionView, error)
- func (r *Runtime) History() *History
- func (r *Runtime) Restart(ctx context.Context) (Status, error)
- func (r *Runtime) Start(ctx context.Context) (Status, error)
- func (r *Runtime) Status(ctx context.Context) (Status, error)
- func (r *Runtime) Stop(ctx context.Context) error
- func (r *Runtime) Wait(ctx context.Context) error
- type Settings
- func (s Settings) AcquireInstance(ctx context.Context) (func() error, error)
- func (s Settings) Config() (config.MCP, error)
- func (s Settings) GenerateToken(ctx context.Context) (string, error)
- func (s Settings) SaveConfig(ctx context.Context, value config.MCP) error
- func (s Settings) TokenConfigured() (bool, error)
- func (s Settings) UpdateConfig(ctx context.Context, change func(*config.MCP) error) (config.MCP, error)
- type Status
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrRunning = errors.New("MCP 实例正在运行或管理操作忙碌,请先停止服务后重试")
Functions ¶
func DownloadDeliveryMode ¶
交付规则取自本次运行配置,不根据单个请求的来源猜测调用方文件系统。
func FormatLogLine ¶
FormatLogLine 的 ANSI 编号与 GUI 色板语义相同。外部终端决定实际颜色。
Types ¶
type AccountView ¶
type AccountsInput ¶
type AliasView ¶
type AliasView struct {
Name string `json:"name"`
Profile string `json:"profile"`
Organization string `json:"organization"`
AssetReference string `json:"asset_reference"`
AccountReference string `json:"account_reference"`
AssetID string `json:"asset_id,omitempty"`
AccountID string `json:"account_id,omitempty"`
ResolutionStatus string `json:"resolution_status"`
}
type AliasesInput ¶
type AssetInput ¶
type AssetResult ¶
type AssetResult struct {
Profile string `json:"profile"`
Organization string `json:"organization"`
Asset AssetView `json:"asset"`
Accounts []AccountView `json:"accounts"`
Protocols []ProtocolView `json:"protocols"`
}
type AssetsInput ¶
type CallDetails ¶
type CallDetails struct {
Summary, Conditions string
ConnectionID, ExecutionID string
Duration time.Duration
}
CallDetails 只接受调用摘要和经过白名单筛选的条件,不持有原始请求或响应。
type CancelInput ¶
type CloseInput ¶
type ConfigReader ¶
type ConnectionInput ¶
type ConnectionInput struct {
ConnectionID string `json:"connection_id"`
}
type ConnectionView ¶
type ConnectionView struct {
ID string `json:"connection_id"`
Target ResolvedTarget `json:"target"`
Status string `json:"status"`
TransportGeneration uint64 `json:"transport_generation"`
TransportConnected bool `json:"transport_connected"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt time.Time `json:"last_used_at"`
ActiveExecutionID string `json:"active_execution_id,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
CloseReason string `json:"close_reason,omitempty"`
LastError *Fault `json:"last_error,omitempty"`
ExecCapability string `json:"exec_capability"`
RemoteDeadlineCapability string `json:"remote_deadline_capability"`
LastDisconnectReason string `json:"last_disconnect_reason,omitempty"`
RetryAfterMS int64 `json:"retry_after_ms"`
RecentUnknownExecutionIDs []string `json:"recent_unknown_execution_ids"`
}
type Connector ¶
type Connector struct {
Config ConfigReader
Auth IdentitySource
Queries *Queries
Connect connect.Service
KnownHosts string
Timeout time.Duration
}
Connector 只读取明确的目标;不修改当前选择,不发起交互登录或主机信任弹窗。
func (Connector) OpenDownloadSFTP ¶
func (c Connector) OpenDownloadSFTP(ctx context.Context, r ResolvedTarget) (DownloadSFTP, error)
type DownloadIDInput ¶
type DownloadIDInput struct {
DownloadID string `json:"download_id"`
}
type DownloadInput ¶
type DownloadInput struct {
Target Target `json:"target,omitempty"`
ConnectionID string `json:"connection_id,omitempty"`
RequestKey string `json:"request_key"`
RemotePaths []string `json:"remote_paths"`
LocalDirectory string `json:"local_directory,omitempty"`
TimeoutMS int `json:"timeout_ms,omitempty"`
WaitMS *int `json:"wait_ms,omitempty"`
}
type DownloadLink ¶
type DownloadLink struct {
URL string `json:"url,omitempty"`
FileName string `json:"file_name"`
Format string `json:"format"`
Size int64 `json:"size"`
ExpiresAt time.Time `json:"expires_at"`
RequiresExtraction bool `json:"requires_extraction"`
RestoreName string `json:"restore_name"`
Artifact downloadcache.Artifact `json:"-"`
Available bool `json:"available"`
}
type DownloadProgress ¶
type DownloadProgress struct {
Phase string `json:"phase"`
Protocol string `json:"protocol,omitempty"`
TransferredBytes int64 `json:"transferred_bytes"`
TransferBytes int64 `json:"transfer_bytes"`
Published *DownloadResult `json:"-"`
}
type DownloadRemote ¶
type DownloadRemote interface {
Open(string) (io.ReadCloser, error)
Close() error
}
type DownloadRename ¶
type DownloadRename struct {
Source string `json:"source"`
ArchivePath string `json:"archive_path"`
}
ArchivePath 是准备包中的相对位置;只有同名独立来源被改名时返回对应关系。
type DownloadResult ¶
type DownloadResult struct {
Delivery string `json:"delivery,omitempty"`
Link *DownloadLink `json:"link,omitempty"`
Instructions string `json:"instructions,omitempty"`
RenamedEntries []DownloadRename `json:"renamed_entries,omitempty"`
Directory string `json:"directory,omitempty"`
Files []DownloadedFile `json:"files,omitempty"`
Warnings []string `json:"warnings,omitempty"`
RemoteArtifacts []string `json:"remote_artifacts,omitempty"`
}
type DownloadSFTP ¶
type DownloadSFTP struct {
Client DownloadRemote
Root *string
Account string
}
type DownloadView ¶
type DownloadView struct {
ID string `json:"download_id"`
Target ResolvedTarget `json:"target"`
Status string `json:"status"`
DownloadProgress
DownloadResult
FilesReady bool `json:"files_ready"`
RemoteMayContinue bool `json:"remote_may_continue"`
AcceptedAt time.Time `json:"accepted_at"`
DeadlineAt time.Time `json:"deadline_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
Error *Fault `json:"error,omitempty"`
}
type DownloadedFile ¶
type DownloadsPageInput ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 归属于一次服务实例;HTTP 请求结束不取消它拥有的工作。
func NewEngine ¶
func NewEngine(opts EngineOptions) *Engine
func (*Engine) CancelDownload ¶
func (e *Engine) CancelDownload(_ context.Context, in DownloadIDInput) (DownloadView, error)
func (*Engine) CancelExecution ¶
func (e *Engine) CancelExecution(ctx context.Context, in CancelInput) (ExecutionView, error)
func (*Engine) CloseConnection ¶
func (e *Engine) CloseConnection(ctx context.Context, in CloseInput) (ConnectionView, error)
func (*Engine) ConnectionsPage ¶
func (*Engine) DownloadFiles ¶
func (e *Engine) DownloadFiles(ctx context.Context, in DownloadInput) (DownloadView, error)
func (*Engine) DownloadsPage ¶
func (e *Engine) DownloadsPage(_ context.Context, in DownloadsPageInput) (Page[DownloadView], error)
func (*Engine) Execute ¶
func (e *Engine) Execute(ctx context.Context, in ExecuteInput) (ExecutionView, error)
func (*Engine) ExecutionsPage ¶
func (e *Engine) ExecutionsPage(ctx context.Context, in ExecutionsPageInput) (Page[ExecutionView], error)
func (*Engine) GetConnection ¶
func (e *Engine) GetConnection(_ context.Context, in ConnectionInput) (ConnectionView, error)
func (*Engine) GetDownload ¶
func (e *Engine) GetDownload(ctx context.Context, in GetDownloadInput) (DownloadView, error)
func (*Engine) GetExecution ¶
func (e *Engine) GetExecution(ctx context.Context, in GetExecutionInput) (ExecutionView, error)
func (*Engine) ListConnections ¶
func (e *Engine) ListConnections(_ context.Context, _ struct{}) ([]ConnectionView, error)
func (*Engine) ListExecutions ¶
func (e *Engine) ListExecutions(_ context.Context, in ListExecutionsInput) ([]ExecutionView, error)
func (*Engine) RecordCall ¶
func (e *Engine) RecordCall(name string, err error, details ...CallDetails)
func (*Engine) RequestEpoch ¶
func (*Engine) Retire ¶
func (e *Engine) Retire()
Retire 在宿主停止实例后解除仓库到旧 Engine 的引用。历史只保留单条操作, 不因一条日志而保留整个旧实例的索引、连接池和上下文;在途清理仍持有自己的 Engine。
func (*Engine) Stats ¶
func (e *Engine) Stats() EngineStats
type EngineOptions ¶
type EngineOptions struct {
History *History
Instance string
Resolve func(context.Context, Target) (ResolvedTarget, error)
Validate func(context.Context, ResolvedTarget) error
Dial func(context.Context, ResolvedTarget) (*ssh.Client, error)
OpenSFTP func(context.Context, ResolvedTarget) (DownloadSFTP, error)
Download func(context.Context, ResolvedTarget, DownloadInput, func(DownloadProgress)) (DownloadResult, error)
DeliveryMode string
DownloadCache *downloadcache.Store
Limits Limits
Now func() time.Time
MaintenanceInterval time.Duration
}
type EngineStats ¶
type EngineStats struct {
Connections int `json:"connections"`
SSHConnections int `json:"ssh_connections"`
Connecting int `json:"connecting"`
Executions int `json:"executions"`
Downloads int `json:"downloads"`
UnknownDownloads int `json:"unknown_downloads"`
DownloadTransportSlots int `json:"download_transport_slots"`
UnknownExecutions int `json:"unknown_executions"`
Draining bool `json:"draining"`
}
type ExecuteInput ¶
type ExecuteInput struct {
ConnectionID string `json:"connection_id"`
RequestKey string `json:"request_key"`
Command string `json:"command"`
Cwd string `json:"cwd"`
Env map[string]string `json:"env,omitempty"`
TimeoutMS int `json:"timeout_ms,omitempty"`
TimeoutStrategy string `json:"timeout_strategy,omitempty"`
WaitMS *int `json:"wait_ms,omitempty"`
}
type ExecutionView ¶
type ExecutionView struct {
ID string `json:"execution_id"`
ConnectionID string `json:"connection_id"`
Target ResolvedTarget `json:"target"`
TransportGeneration uint64 `json:"transport_generation"`
ConnectAttempts int `json:"connect_attempts"`
Reconnected bool `json:"reconnected"`
Status string `json:"status"`
DispatchState string `json:"dispatch_state"`
RemoteState string `json:"remote_state"`
RemoteMayContinue bool `json:"remote_may_continue"`
TerminationScope string `json:"termination_scope"`
AcceptedAt time.Time `json:"accepted_at"`
PrepareDeadlineAt time.Time `json:"prepare_deadline_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
ExitCode *int `json:"exit_code"`
ExitSignal string `json:"exit_signal,omitempty"`
Error *Fault `json:"error,omitempty"`
Reason string `json:"reason,omitempty"`
TimeoutMS int `json:"timeout_ms"`
TimeoutStrategy string `json:"timeout_strategy"`
CancelRequested bool `json:"cancel_requested"`
CancelConfirmed bool `json:"cancel_confirmed"`
CancelError *Fault `json:"cancel_error,omitempty"`
Output OutputView `json:"output"`
}
type ExecutionsPageInput ¶
type ExecutionsPageInput struct {
PageInput
ListExecutionsInput
}
type Fault ¶
type Fault struct {
Code string `json:"code"`
Message string `json:"message"`
Retryable bool `json:"retryable"`
}
Fault 只携带适合向 Agent 返回的信息,不透传凭据或上游原始响应。
type GetDownloadInput ¶
type GetExecutionInput ¶
type History ¶
type History struct {
// contains filtered or unexported fields
}
History 是宿主内共享的操作仓库。Engine 索引和输出链表只引用这里的对象; 所有实例共用同一把锁,回收时无需持有两个 Engine 锁或调用外部订阅者。
func NewHistory ¶
type IdentitySource ¶
type ListExecutionsInput ¶
type LogLine ¶
type LogLine struct {
Sequence uint64 `json:"sequence"`
Time time.Time `json:"time"`
Instance string `json:"instance"`
Severity string `json:"severity"`
Detail int `json:"detail"`
ConnectionID string `json:"connectionID,omitempty"`
ExecutionID string `json:"executionID,omitempty"`
Event string `json:"event"`
Text string `json:"text"`
}
type OpenResult ¶
type OpenResult struct {
Status string `json:"status"`
Connection *ConnectionView `json:"connection,omitempty"`
Reused bool `json:"reused"`
Error *Fault `json:"error,omitempty"`
}
type OutputChunk ¶
type OutputView ¶
type OutputView struct {
Chunks []OutputChunk `json:"chunks"`
NextCursor uint64 `json:"next_cursor"`
EarliestCursor uint64 `json:"earliest_cursor"`
HasMore bool `json:"has_more"`
Gap bool `json:"output_gap"`
Truncated bool `json:"output_truncated"`
Incomplete bool `json:"output_incomplete"`
DroppedBytes int64 `json:"dropped_bytes"`
}
type ProfilePageInput ¶
type ProfileView ¶
type ProtocolView ¶
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func NewQueries ¶
func NewQueries(instance string, config ConfigReader, auth AuthReader, resources ResourceReader) *Queries
func (*Queries) GetAsset ¶
func (q *Queries) GetAsset(ctx context.Context, input AssetInput) (AssetResult, error)
func (*Queries) ListAccounts ¶
func (q *Queries) ListAccounts(ctx context.Context, input AccountsInput) (Page[AccountView], error)
func (*Queries) ListAliases ¶
func (*Queries) ListAssets ¶
func (*Queries) ListOrganizations ¶
func (q *Queries) ListOrganizations(ctx context.Context, input ProfilePageInput) (Page[jumpserver.Organization], error)
func (*Queries) ListProfiles ¶
type QueryError ¶
func (*QueryError) Error ¶
func (e *QueryError) Error() string
type ResolvedTarget ¶
type ResourceReader ¶
type ResourceReader interface {
ListOrganizations(context.Context, string) ([]jumpserver.Organization, error)
ListAssets(context.Context, string, string, string, int, int) (jumpserver.AssetPage, error)
GetAssetByID(context.Context, string, string, string) (jumpserver.AssetDetail, error)
}
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime 的生存期属于宿主进程,不属于启动请求或 MCP 协议会话。
func NewRuntime ¶
func NewRuntime(settings Settings, host string, handler HandlerFactory) *Runtime
func (*Runtime) CloseConnection ¶
func (r *Runtime) CloseConnection(ctx context.Context, input CloseInput) (ConnectionView, error)
func (*Runtime) Connections ¶
func (r *Runtime) Connections(ctx context.Context) ([]ConnectionView, error)
type Settings ¶
type Settings struct {
Store config.Store
// 仅兼容旧开发版的独立 Token 文件;显式保存后以 config.toml 为准。
Credentials credential.Backend
Locker filelock.Locker
}
func (Settings) AcquireInstance ¶
AcquireInstance 约束服务生存期,同一应用数据目录只允许一个宿主监听。
func (Settings) GenerateToken ¶
GenerateToken 只生成草稿,不写配置或独立凭据,也不要求服务停止。
func (Settings) SaveConfig ¶
SaveConfig 一次原子写入完整配置;运行中的服务继续使用启动快照。
func (Settings) TokenConfigured ¶
type Status ¶
type Status struct {
State string `json:"state"`
Instance *Instance `json:"instance"`
Config config.MCP `json:"config"`
TokenConfigured bool `json:"tokenConfigured"`
RestartRequired bool `json:"restartRequired"`
Error string `json:"error"`
Counts *EngineStats `json:"counts,omitempty"`
StopWarning string `json:"stopWarning,omitempty"`
}