新增profile模块
This commit is contained in:
206
internal/profile/templates.go
Normal file
206
internal/profile/templates.go
Normal file
@@ -0,0 +1,206 @@
|
||||
package profile
|
||||
|
||||
import "fmt"
|
||||
|
||||
// TemplateName 模板类型
|
||||
type TemplateName string
|
||||
|
||||
const (
|
||||
TemplateMinimal TemplateName = "minimal" // 最小环境:仅运行时 + 包管理器
|
||||
TemplateStandard TemplateName = "standard" // 标准环境:常用开发工具
|
||||
TemplateFull TemplateName = "full" // 完整环境:含敏感数据和字体
|
||||
)
|
||||
|
||||
// ValidTemplateNames 返回所有合法的模板名称
|
||||
func ValidTemplateNames() []TemplateName {
|
||||
return []TemplateName{TemplateMinimal, TemplateStandard, TemplateFull}
|
||||
}
|
||||
|
||||
// IsValidTemplateName 检查模板名是否合法
|
||||
func IsValidTemplateName(name string) bool {
|
||||
switch TemplateName(name) {
|
||||
case TemplateMinimal, TemplateStandard, TemplateFull:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// NewFromTemplate 根据模板类型创建 Profile
|
||||
// name 为 Profile 名称,tmpl 为模板类型
|
||||
func NewFromTemplate(name string, tmpl TemplateName) (*Profile, error) {
|
||||
switch tmpl {
|
||||
case TemplateMinimal:
|
||||
return newMinimal(name), nil
|
||||
case TemplateStandard:
|
||||
return newStandard(name), nil
|
||||
case TemplateFull:
|
||||
return newFull(name), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("未知模板类型: %q,可选值: minimal, standard, full", tmpl)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// minimal 模板 — 仅运行时 + 包管理器
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
func newMinimal(name string) *Profile {
|
||||
return &Profile{
|
||||
Name: name,
|
||||
Description: "最小环境配置 — 仅包含编程语言运行时和包管理器",
|
||||
Version: CurrentVersion,
|
||||
Collectors: CollectorConfig{
|
||||
Enabled: []string{
|
||||
"go",
|
||||
"node",
|
||||
"python",
|
||||
"scoop",
|
||||
},
|
||||
Disabled: []string{
|
||||
"ssh",
|
||||
"font",
|
||||
},
|
||||
},
|
||||
Settings: map[string]SettingMap{
|
||||
"go": {
|
||||
"include_tools": true,
|
||||
},
|
||||
"node": {
|
||||
"include_global_packages": true,
|
||||
"exclude_packages": []string{"npm"},
|
||||
},
|
||||
"scoop": {
|
||||
"include_buckets": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// standard 模板 — 常用开发工具
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
func newStandard(name string) *Profile {
|
||||
return &Profile{
|
||||
Name: name,
|
||||
Description: "标准开发环境配置 — 包含常用运行时、编辑器、Shell 和 Git",
|
||||
Version: CurrentVersion,
|
||||
Collectors: CollectorConfig{
|
||||
Enabled: []string{
|
||||
"go",
|
||||
"node",
|
||||
"python",
|
||||
"vscode",
|
||||
"powershell",
|
||||
"scoop",
|
||||
"git",
|
||||
},
|
||||
Disabled: []string{
|
||||
"ssh",
|
||||
"font",
|
||||
"env",
|
||||
},
|
||||
},
|
||||
Settings: map[string]SettingMap{
|
||||
"go": {
|
||||
"include_tools": true,
|
||||
"tools_filter": []string{"gopls", "dlv", "staticcheck", "goimports"},
|
||||
},
|
||||
"node": {
|
||||
"include_global_packages": true,
|
||||
"exclude_packages": []string{"npm"},
|
||||
},
|
||||
"vscode": {
|
||||
"include_settings": true,
|
||||
"include_keybindings": true,
|
||||
"include_snippets": true,
|
||||
"exclude_extensions": []string{"ms-vscode.remote-*"},
|
||||
},
|
||||
"powershell": {
|
||||
"include_profile": true,
|
||||
"include_modules": true,
|
||||
},
|
||||
"scoop": {
|
||||
"include_buckets": true,
|
||||
},
|
||||
"git": {
|
||||
"include_aliases": true,
|
||||
"skip_credentials": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// full 模板 — 完整环境(含敏感数据和字体)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
func newFull(name string) *Profile {
|
||||
return &Profile{
|
||||
Name: name,
|
||||
Description: "完整环境配置 — 包含所有采集器,含环境变量、加密密钥和字体",
|
||||
Version: CurrentVersion,
|
||||
Collectors: CollectorConfig{
|
||||
Enabled: []string{}, // 空列表 = 启用全部
|
||||
Disabled: []string{}, // 无禁用
|
||||
},
|
||||
Settings: map[string]SettingMap{
|
||||
"go": {
|
||||
"include_tools": true,
|
||||
},
|
||||
"node": {
|
||||
"include_global_packages": true,
|
||||
"exclude_packages": []string{"npm"},
|
||||
},
|
||||
"vscode": {
|
||||
"include_settings": true,
|
||||
"include_keybindings": true,
|
||||
"include_snippets": true,
|
||||
},
|
||||
"powershell": {
|
||||
"include_profile": true,
|
||||
"include_modules": true,
|
||||
},
|
||||
"scoop": {
|
||||
"include_buckets": true,
|
||||
"exclude_packages": []string{},
|
||||
},
|
||||
"git": {
|
||||
"include_aliases": true,
|
||||
"skip_credentials": true,
|
||||
},
|
||||
"env": {
|
||||
"include_patterns": []string{
|
||||
"GOPATH", "GOROOT", "GOPROXY",
|
||||
"JAVA_HOME",
|
||||
"NODE_*",
|
||||
"PYTHON*",
|
||||
"CARGO_HOME", "RUSTUP_HOME",
|
||||
},
|
||||
"exclude_patterns": []string{
|
||||
"*SECRET*", "*TOKEN*", "*PASSWORD*", "*KEY*", "*CREDENTIAL*",
|
||||
},
|
||||
},
|
||||
"ssh": {
|
||||
"encrypt": true,
|
||||
},
|
||||
"font": {
|
||||
"formats": []string{".ttf", ".otf"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// TemplateDescription 返回模板的简短描述
|
||||
func TemplateDescription(tmpl TemplateName) string {
|
||||
switch tmpl {
|
||||
case TemplateMinimal:
|
||||
return "最小环境 — 仅运行时和包管理器 (go, node, python, scoop)"
|
||||
case TemplateStandard:
|
||||
return "标准环境 — 常用开发工具 (+ vscode, powershell, git)"
|
||||
case TemplateFull:
|
||||
return "完整环境 — 所有采集器 (+ env, ssh, font)"
|
||||
default:
|
||||
return "未知模板"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user