package controller import ( "crypto/rand" "encoding/hex" "fmt" "time" "ezops/pkg/scriptrunner" "gorm.io/gorm" ) // randomCode returns a short unique code for records that require a unique // string identifier (e.g. playbooks). It combines a unix timestamp with 4 // random hex bytes to guarantee uniqueness even under rapid sequential inserts. func randomCode(prefix string) string { b := make([]byte, 4) _, _ = rand.Read(b) return fmt.Sprintf("%s-%d-%s", prefix, time.Now().Unix(), hex.EncodeToString(b)) } // runLocal 委托 scriptrunner 在本机执行脚本(含运行时预检) // Logan.Li func runLocal(scriptType, content string, timeoutSec int) (output string, exitCode int, durationMs int) { output, exitCode, durationMs, _ = scriptrunner.Run(scriptType, content, timeoutSec) return output, exitCode, durationMs } // AutomationHandler 自动化运维处理器 type AutomationHandler struct { db *gorm.DB } // NewAutomationHandler 创建自动化运维处理器 func NewAutomationHandler(db *gorm.DB) *AutomationHandler { return &AutomationHandler{db: db} }