126 lines
3.7 KiB
Go
126 lines
3.7 KiB
Go
package collector
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Category 采集器分类
|
|
type Category string
|
|
|
|
const (
|
|
CategoryRuntime Category = "runtime" // 编程语言运行时
|
|
CategoryPackage Category = "package" // 包管理器
|
|
CategoryEditor Category = "editor" // 编辑器/IDE
|
|
CategoryShell Category = "shell" // Shell 配置
|
|
CategoryGit Category = "git" // Git 配置
|
|
CategoryEnv Category = "env" // 环境变量
|
|
CategoryFont Category = "font" // 字体
|
|
CategorySSH Category = "ssh" // SSH/GPG 密钥
|
|
CategoryCustom Category = "custom" // 自定义
|
|
)
|
|
|
|
// Collector 定义了所有采集器必须实现的接口
|
|
type Collector interface {
|
|
// Name 返回采集器名称(唯一标识)
|
|
Name() string
|
|
|
|
// DisplayName 返回采集器的显示名称
|
|
DisplayName() string
|
|
|
|
// Description 返回采集器的描述信息
|
|
Description() string
|
|
|
|
// Category 返回采集器所属分类
|
|
Category() Category
|
|
|
|
// IsAvailable 检测当前系统是否支持此采集器
|
|
IsAvailable(ctx context.Context) bool
|
|
|
|
// Scan 扫描当前环境,返回扫描结果
|
|
Scan(ctx context.Context, opts ScanOptions) (*ScanResult, error)
|
|
|
|
// Capture 捕获环境数据,写入到指定目录
|
|
Capture(ctx context.Context, targetDir string, opts CaptureOptions) error
|
|
|
|
// Restore 从指定目录还原环境
|
|
Restore(ctx context.Context, sourceDir string, opts RestoreOptions) error
|
|
|
|
// Verify 验证还原后的环境是否正确
|
|
Verify(ctx context.Context) (*VerifyResult, error)
|
|
}
|
|
|
|
// ScanOptions 扫描选项
|
|
type ScanOptions struct {
|
|
Detailed bool `json:"detailed"`
|
|
Filters map[string]string `json:"filters,omitempty"`
|
|
Timeout time.Duration `json:"timeout,omitempty"`
|
|
}
|
|
|
|
// CaptureOptions 捕获选项
|
|
type CaptureOptions struct {
|
|
IncludePatterns []string `json:"include_patterns,omitempty"`
|
|
ExcludePatterns []string `json:"exclude_patterns,omitempty"`
|
|
Encrypt bool `json:"encrypt"`
|
|
}
|
|
|
|
// RestoreOptions 还原选项
|
|
type RestoreOptions struct {
|
|
ConflictStrategy ConflictStrategy `json:"conflict_strategy"`
|
|
DryRun bool `json:"dry_run"`
|
|
Force bool `json:"force"`
|
|
}
|
|
|
|
// ConflictStrategy 冲突处理策略
|
|
type ConflictStrategy string
|
|
|
|
const (
|
|
ConflictSkip ConflictStrategy = "skip"
|
|
ConflictOverwrite ConflictStrategy = "overwrite"
|
|
ConflictMerge ConflictStrategy = "merge"
|
|
ConflictPrompt ConflictStrategy = "prompt"
|
|
ConflictNewest ConflictStrategy = "newest"
|
|
)
|
|
|
|
// PlatformInfo 平台信息
|
|
type PlatformInfo struct {
|
|
OS string `json:"os"`
|
|
Version string `json:"os_version"`
|
|
Arch string `json:"arch"`
|
|
}
|
|
|
|
// ScanResult 扫描结果
|
|
type ScanResult struct {
|
|
Collector string `json:"collector"`
|
|
Category Category `json:"category"`
|
|
Items []ScanItem `json:"items"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Platform PlatformInfo `json:"platform"`
|
|
Errors []string `json:"errors,omitempty"`
|
|
}
|
|
|
|
// ScanItem 单个扫描项
|
|
type ScanItem struct {
|
|
Name string `json:"name"`
|
|
Version string `json:"version,omitempty"`
|
|
Path string `json:"path,omitempty"`
|
|
Type string `json:"type,omitempty"`
|
|
Properties map[string]string `json:"properties,omitempty"`
|
|
Size int64 `json:"size,omitempty"`
|
|
Sensitive bool `json:"sensitive,omitempty"`
|
|
Children []ScanItem `json:"children,omitempty"`
|
|
}
|
|
|
|
// VerifyResult 验证结果
|
|
type VerifyResult struct {
|
|
Success bool `json:"success"`
|
|
Items []VerifyItem `json:"items"`
|
|
}
|
|
|
|
// VerifyItem 验证项
|
|
type VerifyItem struct {
|
|
Name string `json:"name"`
|
|
Status string `json:"status"` // ok, missing, version_mismatch, error
|
|
Message string `json:"message,omitempty"`
|
|
}
|