feat: switch base delivery to awx task logs
This commit is contained in:
@@ -2,7 +2,6 @@ package handler
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -178,65 +177,23 @@ func (h *DeliveryHandler) Cancel(c *gin.Context) {
|
||||
|
||||
// Targets 获取可用部署目标
|
||||
// @Summary 获取可用部署目标
|
||||
// @Description 返回所有已启用的部署目标(如 k8s 集群、主机池)
|
||||
// @Description 从 AWX 动态返回可用 Job Template 及其 Inventory hosts
|
||||
// @Tags delivery
|
||||
// @Produce json
|
||||
// @Param component query string false "组件过滤,例如 mysql"
|
||||
// @Success 200 {object} map[string]any "items: 部署目标数组"
|
||||
// @Failure 500 {object} map[string]any "内部错误"
|
||||
// @Router /auth/api/v1/delivery/targets [get]
|
||||
// @Security BearerAuth
|
||||
func (h *DeliveryHandler) Targets(c *gin.Context) {
|
||||
var items []model.DeploymentTarget
|
||||
if err := h.service.DB().WithContext(c.Request.Context()).Where("enabled = ?", true).Order("id ASC").Find(&items).Error; err != nil {
|
||||
items, err := h.service.ListTargets(c.Request.Context(), c.Query("component"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": items})
|
||||
}
|
||||
|
||||
type targetPayload struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
TargetType string `json:"target_type" binding:"required"`
|
||||
AWXInventoryID uint64 `json:"awx_inventory_id" binding:"required"`
|
||||
AWXTemplateID uint64 `json:"awx_template_id" binding:"required"`
|
||||
Metadata map[string]any `json:"metadata"`
|
||||
}
|
||||
|
||||
// CreateTarget 创建部署目标
|
||||
// @Summary 创建部署目标
|
||||
// @Description 管理员创建新的部署目标(目前仅支持 k8s 类型)
|
||||
// @Tags delivery
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body targetPayload true "目标配置"
|
||||
// @Success 201 {object} model.DeploymentTarget "目标已创建"
|
||||
// @Failure 400 {object} map[string]any "参数错误"
|
||||
// @Failure 401 {object} map[string]any "未授权"
|
||||
// @Failure 409 {object} map[string]any "名称冲突"
|
||||
// @Router /auth/api/v1/delivery/targets [post]
|
||||
// @Security BearerAuth
|
||||
func (h *DeliveryHandler) CreateTarget(c *gin.Context) {
|
||||
if !requirePlatformAdmin(c) {
|
||||
return
|
||||
}
|
||||
var req targetPayload
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if req.TargetType != "k8s" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "only k8s targets are supported"})
|
||||
return
|
||||
}
|
||||
raw, _ := json.Marshal(req.Metadata)
|
||||
item := model.DeploymentTarget{Name: req.Name, TargetType: req.TargetType, AWXInventoryID: req.AWXInventoryID, AWXTemplateID: req.AWXTemplateID, Enabled: true, Metadata: string(raw)}
|
||||
if err := h.service.DB().Create(&item).Error; err != nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, item)
|
||||
}
|
||||
|
||||
type quotaPayload struct {
|
||||
BusinessLineID uint64 `json:"business_line_id" binding:"required"`
|
||||
TargetID uint64 `json:"target_id" binding:"required"`
|
||||
|
||||
Reference in New Issue
Block a user