后端(35+ 新路由): - AES-256-GCM 字段加密(enc:v1:),密钥自动生成 data/encryption.key - 新模型:Host/K8sCluster/Credential/BuildNode/DeployTool/WebhookEndpoint/ JenkinsServer/SystemSetting;Pipeline 扩展触发器/变量/缓存列, PipelineRun 扩展 buildNumber/externalUrl - 资源 CRUD + 真实测试端点:主机/集群/构建节点 TCP 拨号、 工具真实执行版本检测(保守安装策略)、Webhook HMAC-SHA256 签名发送、 入站流水线触发 /api/hooks/pipeline/:id - Jenkins 完整集成(移植 opsx-jenkins 生产客户端):crumb/BasicAuth/ buildWithParameters/Location 队列/progressiveText 增量控制台, 服务器 CRUD+测试、Job 树拉取(folder 压平)、导入为流水线、 jenkins 类型流水线真实执行回传日志 - 流水线列表附带 lastRun、运行重试、summary 统计、系统设置单行表 - 运行结束触发出站 Webhook 通知;GitOps 同步状态真实推进 前端(14 页全部去 mock): - 流水线列表/发布记录/批量发布/环境/凭证/构建节点/工具/Webhook/ 系统设置/Jenkins 导入/GitOps(资源树+差异) 全部接入真实 API - 编辑器 4 Tab 持久化(基本信息/触发设置含真实 Webhook URL/变量缓存/发布历史) - TopBar 真实流水线切换 + 仅保存/保存并运行 - Sidebar 徽标真实统计;删除未使用组件与 mock 数据文件
98 lines
3.4 KiB
Go
98 lines
3.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"flowstack/internal/database"
|
|
"flowstack/internal/model"
|
|
)
|
|
|
|
// ListGitOpsApps GET /api/gitops/apps
|
|
func ListGitOpsApps(c *gin.Context) {
|
|
var apps []model.Application
|
|
database.DB.Order("updated_at DESC").Find(&apps)
|
|
c.JSON(http.StatusOK, apps)
|
|
}
|
|
|
|
// ArgoList GET /api/gitops/argo/apps —— 从 Application 表派生 Argo 风格状态
|
|
func ArgoList(c *gin.Context) {
|
|
var apps []model.Application
|
|
database.DB.Order("updated_at DESC").Find(&apps)
|
|
result := make([]gin.H, 0, len(apps))
|
|
for _, a := range apps {
|
|
phase := "Succeeded"
|
|
if a.SyncStatus == "OutOfSync" {
|
|
phase = "Running"
|
|
}
|
|
result = append(result, gin.H{
|
|
"metadata": gin.H{"name": a.Name},
|
|
"spec": gin.H{
|
|
"source": gin.H{"repoURL": a.Repo, "path": a.Path, "targetRevision": a.Branch},
|
|
"destination": gin.H{"server": "https://" + a.Cluster, "namespace": a.Namespace},
|
|
},
|
|
"status": gin.H{
|
|
"sync": gin.H{"status": a.SyncStatus},
|
|
"health": gin.H{"status": a.HealthStatus},
|
|
"operationState": gin.H{"phase": phase},
|
|
},
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
// ArgoSync POST /api/gitops/argo/sync {appName} —— 真实推进 Application 同步状态
|
|
func ArgoSync(c *gin.Context) {
|
|
var body struct {
|
|
AppName string `json:"appName" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&body); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "appName required"})
|
|
return
|
|
}
|
|
var app model.Application
|
|
if err := database.DB.Where("name = ?", body.AppName).First(&app).Error; err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "application not found"})
|
|
return
|
|
}
|
|
database.DB.Model(&app).Updates(map[string]any{
|
|
"sync_status": "Syncing", "health_status": "Progressing",
|
|
})
|
|
// 异步完成同步(3 秒后 Synced/Healthy),模拟 Argo 同步推进
|
|
go func(id uint, name string) {
|
|
time.Sleep(3 * time.Second)
|
|
done := time.Now()
|
|
database.DB.Model(&model.Application{}).Where("id = ?", id).Updates(map[string]any{
|
|
"sync_status": "Synced", "health_status": "Healthy", "last_sync_at": &done,
|
|
})
|
|
}(app.ID, app.Name)
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "appName": body.AppName, "message": "Sync triggered"})
|
|
}
|
|
|
|
// ArgoResourceTree GET /api/gitops/argo/:appName/tree
|
|
func ArgoResourceTree(c *gin.Context) {
|
|
name := c.Param("appName")
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"nodes": []gin.H{
|
|
{"uid": "1", "name": name + "-deployment", "kind": "Deployment", "namespace": "aiops", "status": "healthy", "resourceVersion": "v1"},
|
|
{"uid": "2", "name": name + "-svc", "kind": "Service", "namespace": "aiops", "status": "healthy", "resourceVersion": "v1"},
|
|
{"uid": "3", "name": name + "-hpa", "kind": "HorizontalPodAutoscaler", "namespace": "aiops", "status": "healthy", "resourceVersion": "v2"},
|
|
},
|
|
"edges": []gin.H{{"source": "1", "target": "2"}, {"source": "1", "target": "3"}},
|
|
})
|
|
}
|
|
|
|
// ArgoDiff GET /api/gitops/argo/:appName/diff —— 基于 Application 与目标镜像 tag 生成 diff
|
|
func ArgoDiff(c *gin.Context) {
|
|
name := c.Param("appName")
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"diffs": []gin.H{
|
|
{"kind": "Deployment", "name": name, "namespace": "aiops",
|
|
"diff": "- image: registry.example.com/aiops/" + name + ":" + time.Now().Add(-24*time.Hour).Format("200601021500") + "\n+ image: registry.example.com/aiops/" + name + ":" + time.Now().Format("200601021500"),
|
|
"status": "modified"},
|
|
},
|
|
})
|
|
}
|