chore: 统一本地服务器与远程仓库源码

- 合并 main 与 master 历史并以服务器结构为基线
- 保留迁移、数据保留、AWS 账单与部署安全能力
- 建立 SDD 规格和 CI 验证闭环
This commit is contained in:
Logan.Li committed 2026-08-05 20:03:25 +08:00
commit fd60361d93
460 files changed
+37492 -23871

No files matched your search

+12 -2
View File
@@ -29,6 +29,10 @@ func registerAgentDownloads(r *gin.Engine, log *zap.Logger) {
r.GET("/agent/arch", func(c *gin.Context) {
base := requestBaseURL(c)
if base == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "request host is required"})
return
}
downloads := availableAgentDownloads(paths.binDir)
c.JSON(http.StatusOK, gin.H{
"version": "1.0.0",
@@ -110,11 +114,17 @@ func requestBaseURL(c *gin.Context) string {
scheme = "https"
}
if proto := c.GetHeader("X-Forwarded-Proto"); proto != "" {
scheme = proto
// 多级代理可能传逗号列表,首项是客户端最初使用的协议。 // Logan.Li
scheme = strings.TrimSpace(strings.Split(proto, ",")[0])
}
host := c.Request.Host
if forwardedHost := c.GetHeader("X-Forwarded-Host"); forwardedHost != "" {
// 多级代理可能传逗号列表,首项是客户端最初访问的域名。 // Logan.Li
host = strings.TrimSpace(strings.Split(forwardedHost, ",")[0])
}
if host == "" {
host = "localhost:8080"
// HTTP/1.1 正常请求必须带 Host,缺失时不再伪造本机地址。 // Logan.Li
return ""
}
return fmt.Sprintf("%s://%s", scheme, host)
}
+27 -44
View File
@@ -76,15 +76,15 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
metricsWSHandler := controller.NewMetricsWSHandler(metricsHub, wsMgr)
r.GET("/ws/metrics", middleware.JWTAuth(&cfg.JWT, db), metricsWSHandler.ServeWS)
// WebSocket 流水线日志推流
// 流水线运行日志与工作区属于构建产物,必须同时完成登录和所属流水线授权。 // Logan.Li
wsLogHandler := controller.NewWSPipelineLogHandler(db, redisCache, wsMgr)
r.GET("/ws/pipeline/:runId/log", wsLogHandler.StreamLog)
r.GET("/api/v1/pipelines/runs/:runId/log-stream", wsLogHandler.GetLogHistory)
r.GET("/ws/pipeline/:runId/log", middleware.JWTAuth(&cfg.JWT, db), middleware.PipelineRunAccess(db), wsLogHandler.StreamLog)
r.GET("/api/v1/pipelines/runs/:runId/log-stream", middleware.JWTAuth(&cfg.JWT, db), middleware.PipelineRunAccess(db), wsLogHandler.GetLogHistory)
// 工作区文件浏览器(浏览/下载流水线构建目录文件)
workspaceFilesHandler := controller.NewWorkspaceFilesHandler(db)
r.GET("/api/v1/pipelines/runs/:runId/files", workspaceFilesHandler.ListFiles)
r.GET("/api/v1/pipelines/runs/:runId/files/download", workspaceFilesHandler.DownloadFile)
r.GET("/api/v1/pipelines/runs/:runId/files", middleware.JWTAuth(&cfg.JWT, db), middleware.PipelineRunAccess(db), workspaceFilesHandler.ListFiles)
r.GET("/api/v1/pipelines/runs/:runId/files/download", middleware.JWTAuth(&cfg.JWT, db), middleware.PipelineRunAccess(db), workspaceFilesHandler.DownloadFile)
// WebSocket K8s exec 交互终端 // Logan.Li
k8sHandler := controller.NewKubernetesHandler(db, wsMgr)
@@ -129,7 +129,7 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
api.GET("/rdp-staged/:token", controller.ServeRDPStaged)
// Webhook 触发路由(无需 JWT,由 Webhook Token 签名验证)
pipelineHandler := controller.NewPipelineHandler(db, redisCache, ti)
pipelineHandler := controller.NewPipelineHandler(db, redisCache, ti, cfg.JWT.Secret)
webhookGroup := api.Group("/webhook")
{
webhookGroup.POST("/job/:jobName", pipelineHandler.WebhookTrigger)
@@ -264,7 +264,7 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
}
// 云账单处理器(云账号同步账单路由共用) // Logan.Li
billingHandler := controller.NewBillingHandler(db)
billingHandler := controller.NewBillingHandler(db, &cfg.Billing)
// 云账号路由
cloudAccountHandler := controller.NewCloudAccountHandler(db)
@@ -291,6 +291,7 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
domains.GET("", domainHandler.ListDomains)
domains.POST("", domainHandler.CreateDomain)
domains.PUT("/:id", domainHandler.UpdateDomain)
domains.POST("/:id/check-ssl", domainHandler.CheckDomainSSL)
domains.DELETE("/:id", domainHandler.DeleteDomain)
}
@@ -324,6 +325,8 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
billings.DELETE("/:id", billingHandler.DeleteBilling)
billings.GET("/stats", billingHandler.GetBillingStats)
billings.GET("/cost-analysis", billingHandler.GetBillingCostAnalysis)
billings.GET("/settings", billingHandler.GetBillingSettings)
billings.PUT("/settings", middleware.AdminAuth(), billingHandler.SaveBillingSettings)
billings.GET("/providers", billingHandler.GetProviderOptions)
billings.POST("/sync", billingHandler.SyncYesterdayBillings)
}
@@ -658,6 +661,16 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
buildNodes.POST("/:id/test", pipelineHandler.TestBuildNode)
}
// Jenkins 外部 CI 接入:同步 Jobs 并通过 Jenkins API 触发构建。 // Logan.Li
jenkins := authorized.Group("/deploy/jenkins")
{
jenkins.GET("/config", pipelineHandler.GetJenkinsConfig)
jenkins.PUT("/config", pipelineHandler.SaveJenkinsConfig)
jenkins.POST("/test", pipelineHandler.TestJenkinsConfig)
jenkins.POST("/sync", pipelineHandler.SyncJenkinsJobs)
jenkins.GET("/refs", pipelineHandler.GetJenkinsRefs)
}
// 应用发布路由
releases := authorized.Group("/releases")
{
@@ -669,24 +682,6 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
releases.POST("/:id/rollback", pipelineHandler.RollbackRelease)
}
// 仓库认证 & 镜像仓库认证路由
deployHandler := controller.NewDeployHandler(db)
{
repos := authorized.Group("/deploy/repos")
repos.GET("", deployHandler.ListRepos)
repos.POST("", deployHandler.CreateRepo)
repos.GET("/:id", deployHandler.GetRepo)
repos.PUT("/:id", deployHandler.UpdateRepo)
repos.DELETE("/:id", deployHandler.DeleteRepo)
registries := authorized.Group("/deploy/registries")
registries.GET("", deployHandler.ListRegistries)
registries.POST("", deployHandler.CreateRegistry)
registries.GET("/:id", deployHandler.GetRegistry)
registries.PUT("/:id", deployHandler.UpdateRegistry)
registries.DELETE("/:id", deployHandler.DeleteRegistry)
}
// 工具配置路由(发布配置 Tab ④)// Logan.Li
toolConfigHandler := controller.NewToolConfigHandler(db, ti)
tools := authorized.Group("/deploy/tools")
@@ -879,27 +874,28 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
ll.GET("", llHandler.ListLoginLogs)
}
// Agent 上报路由(无需 JWT)
// Agent 采集通道保持既有协议,待按主机绑定的可轮换凭证上线后再强制校验。 // Logan.Li
agentHandler := controller.NewAgentHandler(db, redisCache, metricsHub)
taskHandler := controller.NewAgentTaskHandler(db)
agentGroup := api.Group("/agent")
agentGroup := api.Group("/agent", middleware.AgentAuth(db, cfg.Agent.EnforceAuth))
{
agentGroup.POST("/report", agentHandler.ReceiveReport)
agentGroup.GET("/tasks/poll", taskHandler.PollTasks)
agentGroup.POST("/tasks/:task_id/result", taskHandler.SubmitResult)
agentGroup.POST("/aggregate", agentHandler.AggregateMetrics)
agentGroup.POST("/exec", agentInstallHandler.RemoteExec)
// 健康探针:Agent 拉取本机配置(无需 JWT)
// 健康探针:Agent 拉取本机配置。
agentGroup.GET("/health-probes/config", agentHandler.GetHealthProbesForAgent)
// 端口策略:Agent 拉取本机端口过滤策略(无需 JWT)
// 端口策略:Agent 拉取本机端口过滤策略。
agentGroup.GET("/port-policy", agentHandler.GetPortPolicyForAgent)
}
// Agent 数据查询 + 任务管理(需要 JWT)
agentQuery := authorized.Group("/agent")
{
agentQuery.POST("/exec", agentInstallHandler.RemoteExec)
agentQuery.GET("/latest", agentHandler.GetLatestReports)
agentQuery.GET("/history/:hostname", agentHandler.GetHostHistory)
agentQuery.GET("/aggregate", agentHandler.GetAggregate)
// 指标聚合是控制台维护操作,必须使用用户 JWT,不能由采集 Agent 调用。 // Logan.Li
agentQuery.POST("/aggregate", agentHandler.AggregateMetrics)
// 远程任务
agentQuery.POST("/tasks", taskHandler.CreateTask)
@@ -942,7 +938,6 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
aiopsGroup.GET("/llm-config", llmHandler.GetLLMConfig)
aiopsGroup.PUT("/llm-config", llmHandler.SaveLLMConfig)
aiopsGroup.POST("/llm-config/test", llmHandler.TestLLMConnection)
aiopsGroup.POST("/llm-config/models", llmHandler.ListLLMModels) // 读取 OpenAI/New API 兼容模型列表 // Logan.Li
aiopsGroup.POST("/chat", llmHandler.Chat)
aiopsGroup.POST("/chat/stream", llmHandler.ChatStream)
aiopsGroup.GET("/chat-history", llmHandler.GetChatHistory)
@@ -1055,18 +1050,6 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
zabbixDSGroup.POST("/test", zabbixDSHandler.TestConnection)
}
// 自定义监控仪表盘 — CRUD + 设默认 // Logan.Li
customDashHandler := controller.NewCustomDashboardHandler(db)
customDashGroup := authorized.Group("/custom-dashboards")
{
customDashGroup.GET("", customDashHandler.List)
customDashGroup.GET("/:id", customDashHandler.Get)
customDashGroup.POST("", customDashHandler.Create)
customDashGroup.PUT("/:id", customDashHandler.Update)
customDashGroup.DELETE("/:id", customDashHandler.Delete)
customDashGroup.POST("/:id/default", customDashHandler.SetDefault)
}
// 链路追踪数据源管理 — CRUD + 测试连接 + 设默认 // Logan.Li
traceDSHandler := controller.NewTraceDSHandler(db)
traceProxyHandler := controller.NewTraceProxyHandler(traceDSHandler)