fix: harden ops runbooks and execution

This commit is contained in:
2026-03-15 11:09:26 +08:00
parent 27b038898d
commit 36f11fa846
10 changed files with 1912 additions and 101 deletions

View File

@@ -0,0 +1,37 @@
package runbook
import (
"strings"
"ops-assistant/models"
"gorm.io/gorm"
)
type ResolvedTarget struct {
Found bool
User string
Host string
Port int
}
func resolveTarget(db *gorm.DB, name string) ResolvedTarget {
trim := strings.TrimSpace(name)
if trim == "" {
return ResolvedTarget{}
}
var t models.OpsTarget
if err := db.Where("name = ? AND enabled = ?", trim, true).First(&t).Error; err != nil {
return ResolvedTarget{}
}
user := strings.TrimSpace(t.User)
host := strings.TrimSpace(t.Host)
port := t.Port
if user == "" || host == "" {
return ResolvedTarget{}
}
if port <= 0 {
port = 22
}
return ResolvedTarget{Found: true, User: user, Host: host, Port: port}
}