Files
ops-assistant/internal/module/cpa/commands.go
2026-03-19 21:23:28 +08:00

63 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cpa
import (
"fmt"
"strings"
coremodule "ops-assistant/internal/core/module"
"ops-assistant/internal/core/runbook"
)
func commandSpecs() []coremodule.CommandSpec {
return []coremodule.CommandSpec{
{
Prefixes: []string{"/cpa status"},
Template: coremodule.CommandTemplate{
RunbookName: "cpa_status",
Gate: coremodule.Gate{AllowDryRun: true},
DryRunMsg: "🧪 dry-run: 将执行 /cpa status未实际执行",
SuccessMsg: func(jobID uint) string { return fmt.Sprintf("✅ /cpa status 已执行job=%d", jobID) },
},
ErrPrefix: "/cpa status 执行失败: ",
},
{
Prefixes: []string{"/cpa usage backup"},
Template: coremodule.CommandTemplate{
RunbookName: "cpa_usage_backup",
Gate: coremodule.Gate{AllowDryRun: true},
DryRunMsg: "🧪 dry-run: 将执行 /cpa usage backup未实际执行",
SuccessMsg: func(jobID uint) string { return fmt.Sprintf("✅ /cpa usage backup 已执行job=%d", jobID) },
},
ErrPrefix: "/cpa usage backup 执行失败: ",
},
{
Prefixes: []string{"/cpa usage restore "},
ErrHint: "--confirm YES_RESTORE",
Template: coremodule.CommandTemplate{
RunbookName: "cpa_usage_restore",
Gate: coremodule.Gate{NeedFlag: "allow_ops_restore", RequireConfirm: true, ExpectedToken: "YES_RESTORE", AllowDryRun: true},
InputsFn: func(_ string, parts []string) (map[string]string, error) {
if len(parts) < 4 {
return nil, fmt.Errorf("❌ 用法:/cpa usage restore <backup_id>")
}
backupID := strings.TrimSpace(parts[3])
if backupID == "" {
return nil, fmt.Errorf("❌ backup_id 不能为空")
}
return map[string]string{"backup_id": backupID}, nil
},
MetaFn: func(userID int64, confirmToken string, inputs map[string]string) runbook.RunMeta {
meta := runbook.NewMeta()
meta.Target = "hwsg"
meta.RiskLevel = "high"
meta.ConfirmHash = hashConfirmToken(confirmToken)
return meta
},
DryRunMsg: "🧪 dry-run: 将执行 restore未实际执行",
SuccessMsg: func(jobID uint) string { return fmt.Sprintf("✅ /cpa usage restore 已执行job=%d", jobID) },
},
ErrPrefix: "/cpa usage restore 执行失败: ",
},
}
}