diff --git a/sqle/api/app.go b/sqle/api/app.go index 6a276de2b3..6ccf19ca59 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -345,8 +345,8 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti v1ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls", v1.GetAuditPlanReportSQLsV1) v1ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/export", v1.ExportAuditPlanReportV1) - v1ProjectViewRouter.GET("/:project_name/instance_audit_plans", v1.GetInstanceAuditPlans) - v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", v1.GetInstanceAuditPlanDetail) + v1ProjectViewRouter.GET("/:project_name/instance_audit_plans", DeprecatedBy(apiV2)) + v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", DeprecatedBy(apiV2)) v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans", v1.GetInstanceAuditPlanOverview) v1ProjectViewRouter.GET("/:project_name/sql_manages", v1.GetSqlManageList) @@ -434,6 +434,8 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti // sql managers v2ProjectViewRouter.GET("/:project_name/sql_manages", DeprecatedBy(apiV3)) v2ProjectViewRouter.GET("/:project_name/sql_manages/exports", v2.ExportSqlManagesV2) + v2ProjectViewRouter.GET("/:project_name/instance_audit_plans", v2.GetInstanceAuditPlans) + v2ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", v2.GetInstanceAuditPlanDetail) } { diff --git a/sqle/api/controller/v1/instance.go b/sqle/api/controller/v1/instance.go index 7cb30cb2b9..103906ca55 100644 --- a/sqle/api/controller/v1/instance.go +++ b/sqle/api/controller/v1/instance.go @@ -335,7 +335,7 @@ const ( // InstanceTipReqV1.FunctionalModule Enums type InstanceTipReqV1 struct { FilterDBType string `json:"filter_db_type" query:"filter_db_type"` - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated FilterByBusiness string `json:"filter_by_business" query:"filter_by_business"` FilterByEnvironmentTag string `json:"filter_by_environment_tag" query:"filter_by_environment_tag"` FilterWorkflowTemplateId uint32 `json:"filter_workflow_template_id" query:"filter_workflow_template_id"` @@ -368,7 +368,7 @@ type GetInstanceTipsResV1 struct { // @Security ApiKeyAuth // @Param project_name path string true "project name" // @Param filter_db_type query string false "filter db type" -// @Param filter_by_business query string false "filter by business // TODO This parameter is deprecated and will be removed soon." +// @Param filter_by_business query string false "filter by business" // This parameter is deprecated // @Param filter_workflow_template_id query string false "filter workflow template id" // @Param functional_module query string false "functional module" Enums(create_audit_plan,create_workflow,sql_manage,create_optimization,create_pipeline) // @Success 200 {object} v1.GetInstanceTipsResV1 diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index f5f39d1604..e79612708c 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -10,7 +10,6 @@ import ( "net/http" "net/url" "strconv" - "strings" "time" v1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" @@ -438,7 +437,7 @@ type AuditPlanTypeResBase struct { } type GetInstanceAuditPlansReqV1 struct { - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated FilterByBusiness string `json:"filter_by_business" query:"filter_by_business"` FilterByEnvironmentTag string `json:"filter_by_environment_tag" query:"filter_by_environment_tag"` FilterByDBType string `json:"filter_by_db_type" query:"filter_by_db_type"` @@ -461,7 +460,7 @@ type InstanceAuditPlanResV1 struct { InstanceAuditPlanId uint `json:"instance_audit_plan_id"` InstanceID string `json:"instance_id"` InstanceName string `json:"instance_name"` - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated Business string `json:"business"` Environment string `json:"environment"` InstanceType string `json:"instance_type"` @@ -480,7 +479,7 @@ type InstanceAuditPlanResV1 struct { // @Tags instance_audit_plan // @Security ApiKeyAuth // @Param project_name path string true "project name" -// @Param filter_by_business query string false "filter by business // TODO This parameter is deprecated and will be removed soon." +// @Param filter_by_business query string false "filter by business" // This parameter is deprecated // @Param filter_by_environment_tag query string false "filter by environment tag" // @Param filter_by_db_type query string false "filter by db type" // @Param filter_by_instance_id query string false "filter by instance id" @@ -492,110 +491,7 @@ type InstanceAuditPlanResV1 struct { // @Success 200 {object} v1.GetInstanceAuditPlansResV1 // @router /v1/projects/{project_name}/instance_audit_plans [get] func GetInstanceAuditPlans(c echo.Context) error { - s := model.GetStorage() - - req := new(GetInstanceAuditPlansReqV1) - if err := controller.BindAndValidateReq(c, req); err != nil { - return controller.JSONBaseErrorReq(c, err) - } - projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name")) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - - limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize) - - userId := controller.GetUserID(c) - - up, err := dms.NewUserPermission(userId, projectUid) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - - data := map[string]interface{}{ - "filter_instance_audit_plan_db_type": req.FilterByDBType, - "filter_audit_plan_type": req.FilterByAuditPlanType, - "filter_audit_plan_instance_id": req.FilterByInstanceID, - "filter_by_business": req.FilterByBusiness, - "filter_project_id": projectUid, - "current_user_id": userId, - "current_user_is_admin": up.IsAdmin(), - "filter_by_active_status": req.FilterByActiveStatus, - "limit": limit, - "offset": offset, - } - if !up.CanViewProject() { - accessinstanceId := up.GetInstancesByOP(v1.OpPermissionTypeViewOtherAuditPlan) - if len(accessinstanceId) > 0 { - data["accessible_instances_id"] = fmt.Sprintf("\"%s\"", strings.Join(accessinstanceId, "\",\"")) - } - } - - instanceAuditPlans, count, err := s.GetInstanceAuditPlansByReq(data) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - - resData := make([]InstanceAuditPlanResV1, len(instanceAuditPlans)) - for i, v := range instanceAuditPlans { - auditPlanIds := strings.Split(v.AuditPlanIds.String, ",") - typeBases := make([]AuditPlanTypeResBase, 0, len(auditPlanIds)) - for _, auditPlanId := range auditPlanIds { - if auditPlanId != "" { - typeBase, err := ConvertAuditPlanTypeToResByID(c.Request().Context(), auditPlanId, v.Token) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - typeBases = append(typeBases, typeBase) - - } - } - inst := dms.GetInstancesByIdWithoutError(v.InstanceID) - resData[i] = InstanceAuditPlanResV1{ - InstanceAuditPlanId: v.Id, - InstanceID: strconv.FormatUint(inst.ID, 10), - InstanceName: inst.Name, - Business: inst.Business, - InstanceType: v.DBType, - AuditPlanTypes: typeBases, - ActiveStatus: v.ActiveStatus, - CreateTime: v.CreateTime, - Creator: dms.GetUserNameWithDelTag(v.CreateUserId), - } - } - return c.JSON(http.StatusOK, &GetInstanceAuditPlansResV1{ - BaseRes: controller.NewBaseReq(nil), - Data: resData, - TotalNums: count, - }) -} - -func ConvertAuditPlanTypeToResByID(ctx context.Context, id string, token string) (AuditPlanTypeResBase, error) { - auditPlanID, err := strconv.Atoi(id) - if err != nil { - return AuditPlanTypeResBase{}, err - } - s := model.GetStorage() - auditPlan, exist, err := s.GetAuditPlanByID(auditPlanID) - if err != nil { - return AuditPlanTypeResBase{}, err - } - if !exist { - return AuditPlanTypeResBase{}, nil - } - for _, meta := range auditplan.Metas { - if meta.Type == auditPlan.Type { - return AuditPlanTypeResBase{ - AuditPlanType: auditPlan.Type, - AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), - AuditPlanId: auditPlan.ID, - Token: token, - ActiveStatus: auditPlan.ActiveStatus, - LastCollectionStatus: auditPlan.AuditPlanTaskInfo.LastCollectionStatus, - }, nil - } - } - return AuditPlanTypeResBase{}, nil + return nil } func ConvertAuditPlanTypeToRes(ctx context.Context, id uint, auditPlanType string) AuditPlanTypeResBase { @@ -617,7 +513,7 @@ type GetInstanceAuditPlanDetailResV1 struct { } type InstanceAuditPlanDetailResV1 struct { - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated Business string `json:"business" example:"test"` Environment string `json:"environment" example:"prod"` InstanceType string `json:"instance_type" example:"mysql" ` @@ -644,6 +540,7 @@ type HighPriorityCondition struct { Operator Operator `json:"operator"` } +// @Deprecated // @Summary 获取实例扫描任务详情 // @Description get instance audit plan detail // @Id getInstanceAuditPlanDetailV1 @@ -654,96 +551,7 @@ type HighPriorityCondition struct { // @Success 200 {object} v1.GetInstanceAuditPlanDetailResV1 // @router /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id} [get] func GetInstanceAuditPlanDetail(c echo.Context) error { - instanceAuditPlanID := c.Param("instance_audit_plan_id") - projectUID, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name"), true) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - // check current user instance audit plan permission - detail, exist, err := GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, v1.OpPermissionTypeViewOtherAuditPlan) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - if !exist { - return controller.JSONBaseErrorReq(c, errors.NewInstanceAuditPlanNotExistErr()) - } - auditPlans, err := ConvertAuditPlansToRes(c.Request().Context(), detail.AuditPlans) - if err != nil { - return controller.JSONBaseErrorReq(c, err) - } - inst := dms.GetInstancesByIdWithoutError(fmt.Sprintf("%d", detail.InstanceID)) - resData := InstanceAuditPlanDetailResV1{ - Business: inst.Business, - InstanceType: detail.DBType, - InstanceName: inst.Name, - InstanceID: inst.GetIDStr(), - AuditPlans: auditPlans, - } - return c.JSON(http.StatusOK, &GetInstanceAuditPlanDetailResV1{ - BaseRes: controller.NewBaseReq(nil), - Data: resData, - }) -} - -func ConvertAuditPlansToRes(ctx context.Context, auditPlans []*model.AuditPlanV2) ([]AuditPlanRes, error) { - resAuditPlans := make([]AuditPlanRes, 0, len(auditPlans)) - for _, v := range auditPlans { - typeBase := ConvertAuditPlanTypeToRes(ctx, v.ID, v.Type) - resAuditPlan := AuditPlanRes{ - RuleTemplateName: v.RuleTemplateName, - Type: typeBase, - } - meta, err := auditplan.GetMeta(v.Type) - if err != nil { - return nil, err - } - meta.Params = func(instanceId ...string) params.Params { return v.Params } - if meta.Params != nil && len(meta.Params()) > 0 { - paramsRes := make([]AuditPlanParamResV1, 0, len(meta.Params())) - for _, p := range meta.Params() { - val := p.Value - if p.Type == params.ParamTypePassword { - val = "" - } - paramRes := AuditPlanParamResV1{ - Key: p.Key, - Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), - Type: string(p.Type), - Value: val, - } - paramsRes = append(paramsRes, paramRes) - } - resAuditPlan.Params = paramsRes - } - - if v.HighPriorityParams != nil && len(v.HighPriorityParams) > 0 { - hppParamsRes := make([]HighPriorityConditionResV1, len(v.HighPriorityParams)) - for i, hpp := range v.HighPriorityParams { - for _, metaHpp := range meta.HighPriorityParams { - if metaHpp.Key != hpp.Key { - continue - } - highParamRes := HighPriorityConditionResV1{ - Key: metaHpp.Key, - Desc: metaHpp.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), - Value: hpp.Value, - Type: string(metaHpp.Type), - Operator: OperatorResV1{ - Value: string(hpp.Operator.Value), - EnumsValue: ConvertEnumsValuesToRes(ctx, metaHpp.Operator.EnumsValue), - }, - } - hppParamsRes[i] = highParamRes - break - } - } - resAuditPlan.HighPriorityConditions = hppParamsRes - resAuditPlan.NeedMarkHighPrioritySQL = v.NeedMarkHighPrioritySQL - } - - resAuditPlans = append(resAuditPlans, resAuditPlan) - } - return resAuditPlans, nil + return nil } type GetInstanceAuditPlanOverviewResV1 struct { diff --git a/sqle/api/controller/v1/project_permission.go b/sqle/api/controller/v1/project_permission.go index 6be124e1c9..30249615f5 100644 --- a/sqle/api/controller/v1/project_permission.go +++ b/sqle/api/controller/v1/project_permission.go @@ -522,7 +522,7 @@ func CheckUserCanCreateOptimization(ctx context.Context, projectUID string, user // 根据用户权限获取能访问/操作的实例列表 func GetCanOperationInstances(ctx context.Context, user *model.User, req *dmsV2.ListDBServiceReq, operationType dmsV1.OpPermissionType) ([]*model.Instance, error) { // 获取当前项目下指定数据库类型的全部实例 - instances, err := dms.GetInstancesInProjectByTypeAndEnvironmentTag(ctx, req.ProjectUid, req.FilterByDBType, req.FilterByEnvironmentTag) + instances, err := dms.GetInstancesInProjectByTypeAndEnvironmentTag(ctx, req.ProjectUid, req.FilterByDBType, req.FilterByEnvironmentTagUID) if err != nil { return nil, err } diff --git a/sqle/api/controller/v1/sql_manage.go b/sqle/api/controller/v1/sql_manage.go index 3603f23a77..a41eb6cfcf 100644 --- a/sqle/api/controller/v1/sql_manage.go +++ b/sqle/api/controller/v1/sql_manage.go @@ -20,7 +20,7 @@ type GetSqlManageListReq struct { FilterStatus *string `query:"filter_status" json:"filter_status,omitempty"` FilterDbType *string `query:"filter_db_type" json:"filter_db_type,omitempty"` FilterRuleName *string `query:"filter_rule_name" json:"filter_rule_name,omitempty"` - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated FilterBusiness *string `query:"filter_business" json:"filter_business,omitempty"` FilterByEnvironmentTag *string `query:"filter_by_environment_tag" json:"filter_by_environment_tag,omitempty"` FilterPriority *string `query:"filter_priority" json:"filter_priority,omitempty" enums:"high,low"` @@ -100,7 +100,7 @@ type Source struct { // @Success 200 {object} v1.GetSqlManageListResp // @Router /v1/projects/{project_name}/sql_manages [get] func GetSqlManageList(c echo.Context) error { - return getSqlManageList(c) + return nil } type BatchUpdateSqlManageReq struct { @@ -171,7 +171,7 @@ func BatchUpdateSqlManage(c echo.Context) error { type ExportSqlManagesReq struct { FuzzySearchSqlFingerprint *string `query:"fuzzy_search_sql_fingerprint" json:"fuzzy_search_sql_fingerprint,omitempty"` FilterAssignee *string `query:"filter_assignee" json:"filter_assignee,omitempty"` - // TODO This parameter is deprecated and will be removed soon. + // This parameter is deprecated FilterBusiness *string `query:"filter_business" json:"filter_business,omitempty"` FilterByEnvironmentTag *string `query:"filter_by_environment_tag" json:"filter_by_environment_tag,omitempty"` FilterInstanceID *string `query:"filter_instance_id" json:"filter_instance_id,omitempty"` @@ -199,7 +199,7 @@ type ExportSqlManagesReq struct { // @Param project_name path string true "project name" // @Param fuzzy_search_sql_fingerprint query string false "fuzzy search sql fingerprint" // @Param filter_assignee query string false "assignee" -// @Param filter_business query string false "business // TODO This parameter is deprecated and will be removed soon." +// @Param filter_business query string false "filter by business" // This parameter is deprecated // @Param filter_priority query string false "priority" Enums(high,low) // @Param filter_instance_id query string false "instance id" // @Param filter_source query string false "source" Enums(audit_plan,sql_audit_record) @@ -216,7 +216,7 @@ type ExportSqlManagesReq struct { // @Success 200 {file} file "export sql manage" // @Router /v1/projects/{project_name}/sql_manages/exports [get] func ExportSqlManagesV1(c echo.Context) error { - return exportSqlManagesV1(c) + return nil } type RuleRespV1 struct { diff --git a/sqle/api/controller/v1/workflow.go b/sqle/api/controller/v1/workflow.go index 2bd5a007fa..b55a9f5e9e 100644 --- a/sqle/api/controller/v1/workflow.go +++ b/sqle/api/controller/v1/workflow.go @@ -812,7 +812,7 @@ func (m ProjectMap) ProjectPriority(projectUid string) dmsV1.ProjectPriority { return dmsV1.ProjectPriorityUnknown } -type InstanceMap map[string] /* instance id */ *dmsV1.ListDBService +type InstanceMap map[string] /* instance id */ *dmsV2.ListDBService func (m InstanceMap) InstanceName(instanceId string) string { if m == nil { diff --git a/sqle/api/controller/v2/instance_audit_plan.go b/sqle/api/controller/v2/instance_audit_plan.go index 214ce5cf0e..56f980fbdd 100644 --- a/sqle/api/controller/v2/instance_audit_plan.go +++ b/sqle/api/controller/v2/instance_audit_plan.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + "strconv" + "strings" dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" dmsCommonV2 "github.com/actiontech/dms/pkg/dms-common/api/dms/v2" @@ -11,8 +13,12 @@ import ( "github.com/actiontech/sqle/sqle/api/controller" v1 "github.com/actiontech/sqle/sqle/api/controller/v1" "github.com/actiontech/sqle/sqle/dms" + "github.com/actiontech/sqle/sqle/errors" + "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/model" + "github.com/actiontech/sqle/sqle/pkg/params" "github.com/actiontech/sqle/sqle/server" + "github.com/actiontech/sqle/sqle/server/auditplan" opt "github.com/actiontech/sqle/sqle/server/optimization/rule" "github.com/labstack/echo/v4" ) @@ -24,7 +30,6 @@ type InstanceTipReqV2 struct { FunctionalModule string `json:"functional_module" query:"functional_module" enums:"create_audit_plan,create_workflow,sql_manage,create_optimization,create_pipeline" valid:"omitempty,oneof=create_audit_plan create_workflow sql_manage create_optimization create_pipeline"` } - type GetInstanceTipsResV2 struct { controller.BaseRes Data []InstanceTipResV2 `json:"data"` @@ -83,9 +88,9 @@ func GetInstanceTips(c echo.Context) error { default: } dbServiceReq := &dmsCommonV2.ListDBServiceReq{ - FilterByEnvironmentTag: req.FilterByEnvironmentTag, - ProjectUid: projectUid, - FilterByDBType: req.FilterDBType, + FilterByEnvironmentTagUID: req.FilterByEnvironmentTag, + ProjectUid: projectUid, + FilterByDBType: req.FilterDBType, } instances, err := GetCanOperationInstances(c.Request().Context(), user, dbServiceReq, operationType) @@ -129,7 +134,7 @@ func GetInstanceTips(c echo.Context) error { // 根据用户权限获取能访问/操作的实例列表 func GetCanOperationInstances(ctx context.Context, user *model.User, req *dmsCommonV2.ListDBServiceReq, operationType dmsCommonV1.OpPermissionType) ([]*model.Instance, error) { // 获取当前项目下指定数据库类型的全部实例 - instances, err := dms.GetInstancesInProjectByTypeAndEnvironmentTag(ctx, req.ProjectUid, req.FilterByDBType, req.FilterByEnvironmentTag) + instances, err := dms.GetInstancesInProjectByTypeAndEnvironmentTag(ctx, req.ProjectUid, req.FilterByDBType, req.FilterByEnvironmentTagUID) if err != nil { return nil, err } @@ -150,3 +155,313 @@ func GetCanOperationInstances(ctx context.Context, user *model.User, req *dmsCom } return canOperationInstance, nil } + +type GetInstanceAuditPlansReq struct { + FilterByEnvironmentTag string `json:"filter_by_environment_tag" query:"filter_by_environment_tag"` + FilterByDBType string `json:"filter_by_db_type" query:"filter_by_db_type"` + FilterByInstanceID string `json:"filter_by_instance_id" query:"filter_by_instance_id"` + FilterByAuditPlanType string `json:"filter_by_audit_plan_type" query:"filter_by_audit_plan_type"` + FilterByActiveStatus string `json:"filter_by_active_status" query:"filter_by_active_status"` + FuzzySearch string `json:"fuzzy_search" query:"fuzzy_search"` + + PageIndex uint32 `json:"page_index" query:"page_index" valid:"required"` + PageSize uint32 `json:"page_size" query:"page_size" valid:"required"` +} + +type GetInstanceAuditPlansRes struct { + controller.BaseRes + Data []InstanceAuditPlanResV1 `json:"data"` + TotalNums uint64 `json:"total_nums"` +} + +type InstanceAuditPlanResV1 struct { + InstanceAuditPlanId uint `json:"instance_audit_plan_id"` + InstanceID string `json:"instance_id"` + InstanceName string `json:"instance_name"` + Environment string `json:"environment"` + InstanceType string `json:"instance_type"` + AuditPlanTypes []AuditPlanTypeResBase `json:"audit_plan_types"` + ActiveStatus string `json:"active_status" enums:"normal,disabled"` + // TODO 采集状态 + CreateTime string `json:"create_time"` + Creator string `json:"creator"` +} + +type AuditPlanTypeResBase struct { + AuditPlanId uint `json:"audit_plan_id"` + AuditPlanType string `json:"type"` + AuditPlanTypeDesc string `json:"desc"` + Token string `json:"token"` + ActiveStatus string `json:"active_status" enums:"normal,disabled"` + LastCollectionStatus string `json:"last_collection_status" enums:"normal,abnormal"` +} + +// GetInstanceAuditPlans +// @Summary 获取实例扫描任务列表 +// @Description get instance audit plan info list +// @Id getInstanceAuditPlansV2 +// @Tags instance_audit_plan +// @Security ApiKeyAuth +// @Param project_name path string true "project name" +// @Param filter_by_environment_tag query string false "filter by environment tag" +// @Param filter_by_db_type query string false "filter by db type" +// @Param filter_by_instance_id query string false "filter by instance id" +// @Param filter_by_audit_plan_type query string false "filter instance audit plan type" +// @Param filter_by_active_status query string false "filter instance audit plan active status" +// @Param fuzzy_search query string false "fuzzy search" +// @Param page_index query uint32 true "page index" +// @Param page_size query uint32 true "size of per page" +// @Success 200 {object} v2.GetInstanceAuditPlansRes +// @router /v2/projects/{project_name}/instance_audit_plans [get] +func GetInstanceAuditPlans(c echo.Context) error { + s := model.GetStorage() + + req := new(GetInstanceAuditPlansReq) + if err := controller.BindAndValidateReq(c, req); err != nil { + return controller.JSONBaseErrorReq(c, err) + } + projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name")) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + + limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize) + + userId := controller.GetUserID(c) + + up, err := dms.NewUserPermission(userId, projectUid) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + + data := map[string]interface{}{ + "filter_instance_audit_plan_db_type": req.FilterByDBType, + "filter_audit_plan_type": req.FilterByAuditPlanType, + "filter_audit_plan_instance_id": req.FilterByInstanceID, + "filter_by_environment_tag": req.FilterByEnvironmentTag, + "filter_project_id": projectUid, + "current_user_id": userId, + "current_user_is_admin": up.IsAdmin(), + "filter_by_active_status": req.FilterByActiveStatus, + "limit": limit, + "offset": offset, + } + if !up.CanViewProject() { + accessibleInstanceId := up.GetInstancesByOP(dmsCommonV1.OpPermissionTypeViewOtherAuditPlan) + if len(accessibleInstanceId) > 0 { + data["accessible_instances_id"] = fmt.Sprintf("\"%s\"", strings.Join(accessibleInstanceId, "\",\"")) + } + } + + instanceAuditPlans, count, err := s.GetInstanceAuditPlansByReq(data) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + + resData := make([]InstanceAuditPlanResV1, len(instanceAuditPlans)) + for i, v := range instanceAuditPlans { + auditPlanIds := strings.Split(v.AuditPlanIds.String, ",") + typeBases := make([]AuditPlanTypeResBase, 0, len(auditPlanIds)) + for _, auditPlanId := range auditPlanIds { + if auditPlanId != "" { + typeBase, err := ConvertAuditPlanTypeToResByID(c.Request().Context(), auditPlanId, v.Token) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + typeBases = append(typeBases, typeBase) + + } + } + inst := dms.GetInstancesByIdWithoutError(v.InstanceID) + resData[i] = InstanceAuditPlanResV1{ + InstanceAuditPlanId: v.Id, + InstanceID: strconv.FormatUint(inst.ID, 10), + InstanceName: inst.Name, + Environment: inst.Environment, + InstanceType: v.DBType, + AuditPlanTypes: typeBases, + ActiveStatus: v.ActiveStatus, + CreateTime: v.CreateTime, + Creator: dms.GetUserNameWithDelTag(v.CreateUserId), + } + } + return c.JSON(http.StatusOK, &GetInstanceAuditPlansRes{ + BaseRes: controller.NewBaseReq(nil), + Data: resData, + TotalNums: count, + }) +} + +func ConvertAuditPlanTypeToResByID(ctx context.Context, id string, token string) (AuditPlanTypeResBase, error) { + auditPlanID, err := strconv.Atoi(id) + if err != nil { + return AuditPlanTypeResBase{}, err + } + s := model.GetStorage() + auditPlan, exist, err := s.GetAuditPlanByID(auditPlanID) + if err != nil { + return AuditPlanTypeResBase{}, err + } + if !exist { + return AuditPlanTypeResBase{}, nil + } + for _, meta := range auditplan.Metas { + if meta.Type == auditPlan.Type { + return AuditPlanTypeResBase{ + AuditPlanType: auditPlan.Type, + AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), + AuditPlanId: auditPlan.ID, + Token: token, + ActiveStatus: auditPlan.ActiveStatus, + LastCollectionStatus: auditPlan.AuditPlanTaskInfo.LastCollectionStatus, + }, nil + } + } + return AuditPlanTypeResBase{}, nil +} + +type GetInstanceAuditPlanDetailRes struct { + controller.BaseRes + Data InstanceAuditPlanDetailRes `json:"data"` +} + +type InstanceAuditPlanDetailRes struct { + Environment string `json:"environment" example:"prod"` + InstanceType string `json:"instance_type" example:"mysql" ` + InstanceName string `json:"instance_name" example:"test_mysql"` + InstanceID string `json:"instance_id" example:"instance_id"` + // 扫描类型 + AuditPlans []AuditPlanRes `json:"audit_plans"` +} + +type AuditPlanRes struct { + RuleTemplateName string `json:"rule_template_name" from:"rule_template_name" example:"default_MySQL"` + Type AuditPlanTypeResBase `json:"audit_plan_type" form:"audit_plan_type"` + Params []v1.AuditPlanParamResV1 `json:"audit_plan_params" valid:"dive,required"` + NeedMarkHighPrioritySQL bool `json:"need_mark_high_priority_sql"` + HighPriorityConditions []v1.HighPriorityConditionResV1 `json:"high_priority_conditions"` +} + +type HighPriorityCondition struct { + Key string `json:"key"` + Desc string `json:"desc"` + Value string `json:"value"` + Type string `json:"type" enums:"string,int,bool,password"` + EnumsValues []params.EnumsValue `json:"enums_value"` + Operator v1.Operator `json:"operator"` +} + +// @Summary 获取实例扫描任务详情 +// @Description get instance audit plan detail +// @Id getInstanceAuditPlanDetailV2 +// @Tags instance_audit_plan +// @Security ApiKeyAuth +// @Param project_name path string true "project name" +// @Param instance_audit_plan_id path string true "instance audit plan id" +// @Success 200 {object} v2.GetInstanceAuditPlanDetailRes +// @router /v2/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id} [get] +func GetInstanceAuditPlanDetail(c echo.Context) error { + instanceAuditPlanID := c.Param("instance_audit_plan_id") + projectUID, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name"), true) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + // check current user instance audit plan permission + detail, exist, err := v1.GetInstanceAuditPlanIfCurrentUserCanView(c, projectUID, instanceAuditPlanID, dmsCommonV1.OpPermissionTypeViewOtherAuditPlan) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + if !exist { + return controller.JSONBaseErrorReq(c, errors.NewInstanceAuditPlanNotExistErr()) + } + auditPlans, err := ConvertAuditPlansToRes(c.Request().Context(), detail.AuditPlans) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + inst := dms.GetInstancesByIdWithoutError(fmt.Sprintf("%d", detail.InstanceID)) + resData := InstanceAuditPlanDetailRes{ + InstanceType: detail.DBType, + InstanceName: inst.Name, + Environment: inst.Environment, + InstanceID: inst.GetIDStr(), + AuditPlans: auditPlans, + } + return c.JSON(http.StatusOK, &GetInstanceAuditPlanDetailRes{ + BaseRes: controller.NewBaseReq(nil), + Data: resData, + }) +} + +func ConvertAuditPlanTypeToRes(ctx context.Context, id uint, auditPlanType string) AuditPlanTypeResBase { + for _, meta := range auditplan.Metas { + if meta.Type == auditPlanType { + return AuditPlanTypeResBase{ + AuditPlanType: auditPlanType, + AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc), + AuditPlanId: id, + } + } + } + return AuditPlanTypeResBase{} +} + +func ConvertAuditPlansToRes(ctx context.Context, auditPlans []*model.AuditPlanV2) ([]AuditPlanRes, error) { + resAuditPlans := make([]AuditPlanRes, 0, len(auditPlans)) + for _, v := range auditPlans { + typeBase := ConvertAuditPlanTypeToRes(ctx, v.ID, v.Type) + resAuditPlan := AuditPlanRes{ + RuleTemplateName: v.RuleTemplateName, + Type: typeBase, + } + meta, err := auditplan.GetMeta(v.Type) + if err != nil { + return nil, err + } + meta.Params = func(instanceId ...string) params.Params { return v.Params } + if meta.Params != nil && len(meta.Params()) > 0 { + paramsRes := make([]v1.AuditPlanParamResV1, 0, len(meta.Params())) + for _, p := range meta.Params() { + val := p.Value + if p.Type == params.ParamTypePassword { + val = "" + } + paramRes := v1.AuditPlanParamResV1{ + Key: p.Key, + Desc: p.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), + Type: string(p.Type), + Value: val, + } + paramsRes = append(paramsRes, paramRes) + } + resAuditPlan.Params = paramsRes + } + + if v.HighPriorityParams != nil && len(v.HighPriorityParams) > 0 { + hppParamsRes := make([]v1.HighPriorityConditionResV1, len(v.HighPriorityParams)) + for i, hpp := range v.HighPriorityParams { + for _, metaHpp := range meta.HighPriorityParams { + if metaHpp.Key != hpp.Key { + continue + } + highParamRes := v1.HighPriorityConditionResV1{ + Key: metaHpp.Key, + Desc: metaHpp.GetDesc(locale.Bundle.GetLangTagFromCtx(ctx)), + Value: hpp.Value, + Type: string(metaHpp.Type), + Operator: v1.OperatorResV1{ + Value: string(hpp.Operator.Value), + EnumsValue: v1.ConvertEnumsValuesToRes(ctx, metaHpp.Operator.EnumsValue), + }, + } + hppParamsRes[i] = highParamRes + break + } + } + resAuditPlan.HighPriorityConditions = hppParamsRes + resAuditPlan.NeedMarkHighPrioritySQL = v.NeedMarkHighPrioritySQL + } + + resAuditPlans = append(resAuditPlans, resAuditPlan) + } + return resAuditPlans, nil +} diff --git a/sqle/api/controller/v2/sql_manage.go b/sqle/api/controller/v2/sql_manage.go index 55a2c6d1a9..5759356a5d 100644 --- a/sqle/api/controller/v2/sql_manage.go +++ b/sqle/api/controller/v2/sql_manage.go @@ -51,7 +51,7 @@ type SqlManage struct { // @Param filter_status query string false "status" Enums(unhandled,solved,ignored,manual_audited,sent) // @Param filter_rule_name query string false "rule name" // @Param filter_db_type query string false "db type" -// @Param filter_business query string false "business // TODO This parameter is deprecated and will be removed soon." +// @Param filter_business query string false "filter by business" // This parameter is deprecated // @Param filter_by_environment_tag query string false "filter by environment tag" // @Param filter_priority query string false "priority" Enums(high,low) // @Param fuzzy_search_endpoint query string false "fuzzy search endpoint" @@ -63,7 +63,7 @@ type SqlManage struct { // @Success 200 {object} v2.GetSqlManageListResp // @Router /v2/projects/{project_name}/sql_manages [get] func GetSqlManageList(c echo.Context) error { - return getSqlManageList(c) + return nil } type ExportSqlManagesReq struct { diff --git a/sqle/dms/instance.go b/sqle/dms/instance.go index 15a2a53769..7f7932dcd0 100644 --- a/sqle/dms/instance.go +++ b/sqle/dms/instance.go @@ -6,7 +6,6 @@ import ( "strconv" "time" - dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" dmsV2 "github.com/actiontech/dms/pkg/dms-common/api/dms/v2" "github.com/actiontech/dms/pkg/dms-common/dmsobject" dmsCommonAes "github.com/actiontech/dms/pkg/dms-common/pkg/aes" @@ -24,7 +23,7 @@ func getInstances(ctx context.Context, req dmsV2.ListDBServiceReq) ([]*model.Ins req.PageIndex = pageIndex req.PageSize = limit - dbServices, _, err := func() ([]*dmsV1.ListDBService, int64, error) { + dbServices, _, err := func() ([]*dmsV2.ListDBService, int64, error) { newCtx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() @@ -78,7 +77,7 @@ func getInstance(ctx context.Context, req dmsV2.ListDBServiceReq) (*model.Instan return instance, true, nil } -func convertInstance(instance *dmsV1.ListDBService) (*model.Instance, error) { +func convertInstance(instance *dmsV2.ListDBService) (*model.Instance, error) { instanceId, err := strconv.ParseInt(instance.DBServiceUid, 0, 64) if err != nil { return nil, err @@ -123,7 +122,10 @@ func convertInstance(instance *dmsV1.ListDBService) (*model.Instance, error) { AllowQueryWhenLessThanAuditLevel: string(instance.SQLEConfig.SQLQueryConfig.AllowQueryWhenLessThanAuditLevel), } } - + environmentTag := "" + if instance.EnvironmentTag != nil { + environmentTag = instance.EnvironmentTag.Name + } return &model.Instance{ ID: uint64(instanceId), Name: instance.Name, @@ -139,7 +141,7 @@ func convertInstance(instance *dmsV1.ListDBService) (*model.Instance, error) { Desc: instance.Desc, AdditionalParams: additionalParams, SqlQueryConfig: sqlQueryConfig, - Business: instance.Business, + Environment: environmentTag, EnableBackup: instance.EnableBackup, BackupMaxRows: instance.BackupMaxRows, }, nil @@ -153,9 +155,9 @@ func GetInstancesInProject(ctx context.Context, projectUid string) ([]*model.Ins func GetInstancesInProjectByTypeAndEnvironmentTag(ctx context.Context, projectUid, dbType, environmentTag string) ([]*model.Instance, error) { return getInstances(ctx, dmsV2.ListDBServiceReq{ - ProjectUid: projectUid, - FilterByDBType: dbType, - FilterByEnvironmentTag: environmentTag, + ProjectUid: projectUid, + FilterByDBType: dbType, + FilterByEnvironmentTagUID: environmentTag, }) } diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index d2ba04ea7c..d3006f58f6 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -3112,7 +3112,7 @@ var doc = `{ }, { "type": "string", - "description": "filter by business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_by_business", "in": "query" }, @@ -3232,6 +3232,7 @@ var doc = `{ ], "summary": "获取实例扫描任务详情", "operationId": "getInstanceAuditPlanDetailV1", + "deprecated": true, "parameters": [ { "type": "string", @@ -3865,7 +3866,7 @@ var doc = `{ }, { "type": "string", - "description": "filter by business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_by_business", "in": "query" }, @@ -5498,7 +5499,7 @@ var doc = `{ }, { "type": "string", - "description": "business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_business", "in": "query" }, @@ -10652,6 +10653,127 @@ var doc = `{ } } }, + "/v2/projects/{project_name}/instance_audit_plans": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get instance audit plan info list", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取实例扫描任务列表", + "operationId": "getInstanceAuditPlansV2", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "filter by environment tag", + "name": "filter_by_environment_tag", + "in": "query" + }, + { + "type": "string", + "description": "filter by db type", + "name": "filter_by_db_type", + "in": "query" + }, + { + "type": "string", + "description": "filter by instance id", + "name": "filter_by_instance_id", + "in": "query" + }, + { + "type": "string", + "description": "filter instance audit plan type", + "name": "filter_by_audit_plan_type", + "in": "query" + }, + { + "type": "string", + "description": "filter instance audit plan active status", + "name": "filter_by_active_status", + "in": "query" + }, + { + "type": "string", + "description": "fuzzy search", + "name": "fuzzy_search", + "in": "query" + }, + { + "type": "integer", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "size of per page", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetInstanceAuditPlansRes" + } + } + } + } + }, + "/v2/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get instance audit plan detail", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取实例扫描任务详情", + "operationId": "getInstanceAuditPlanDetailV2", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance audit plan id", + "name": "instance_audit_plan_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetInstanceAuditPlanDetailRes" + } + } + } + } + }, "/v2/projects/{project_name}/instance_tips": { "get": { "security": [ @@ -10855,7 +10977,7 @@ var doc = `{ }, { "type": "string", - "description": "business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_business", "in": "query" }, @@ -16697,7 +16819,7 @@ var doc = `{ } }, "business": { - "description": "TODO This parameter is deprecated and will be removed soon.", + "description": "This parameter is deprecated", "type": "string", "example": "test" }, @@ -16787,7 +16909,7 @@ var doc = `{ } }, "business": { - "description": "TODO This parameter is deprecated and will be removed soon.", + "description": "This parameter is deprecated", "type": "string" }, "create_time": { @@ -20508,6 +20630,34 @@ var doc = `{ } } }, + "v2.AuditPlanRes": { + "type": "object", + "properties": { + "audit_plan_params": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.AuditPlanParamResV1" + } + }, + "audit_plan_type": { + "type": "object", + "$ref": "#/definitions/v2.AuditPlanTypeResBase" + }, + "high_priority_conditions": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.HighPriorityConditionResV1" + } + }, + "need_mark_high_priority_sql": { + "type": "boolean" + }, + "rule_template_name": { + "type": "string", + "example": "default_MySQL" + } + } + }, "v2.AuditPlanResV2": { "type": "object", "properties": { @@ -20599,6 +20749,37 @@ var doc = `{ } } }, + "v2.AuditPlanTypeResBase": { + "type": "object", + "properties": { + "active_status": { + "type": "string", + "enum": [ + "normal", + "disabled" + ] + }, + "audit_plan_id": { + "type": "integer" + }, + "desc": { + "type": "string" + }, + "last_collection_status": { + "type": "string", + "enum": [ + "normal", + "abnormal" + ] + }, + "token": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "v2.AuditResDataV2": { "type": "object", "properties": { @@ -21123,6 +21304,45 @@ var doc = `{ } } }, + "v2.GetInstanceAuditPlanDetailRes": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v2.InstanceAuditPlanDetailRes" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, + "v2.GetInstanceAuditPlansRes": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.InstanceAuditPlanResV1" + } + }, + "message": { + "type": "string", + "example": "ok" + }, + "total_nums": { + "type": "integer" + } + } + }, "v2.GetInstanceResV2": { "type": "object", "properties": { @@ -21296,6 +21516,74 @@ var doc = `{ } } }, + "v2.InstanceAuditPlanDetailRes": { + "type": "object", + "properties": { + "audit_plans": { + "description": "扫描类型", + "type": "array", + "items": { + "$ref": "#/definitions/v2.AuditPlanRes" + } + }, + "environment": { + "type": "string", + "example": "prod" + }, + "instance_id": { + "type": "string", + "example": "instance_id" + }, + "instance_name": { + "type": "string", + "example": "test_mysql" + }, + "instance_type": { + "type": "string", + "example": "mysql" + } + } + }, + "v2.InstanceAuditPlanResV1": { + "type": "object", + "properties": { + "active_status": { + "type": "string", + "enum": [ + "normal", + "disabled" + ] + }, + "audit_plan_types": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.AuditPlanTypeResBase" + } + }, + "create_time": { + "description": "TODO 采集状态", + "type": "string" + }, + "creator": { + "type": "string" + }, + "environment": { + "type": "string" + }, + "instance_audit_plan_id": { + "type": "integer" + }, + "instance_id": { + "type": "string" + }, + "instance_name": { + "type": "string" + }, + "instance_type": { + "type": "string" + } + } + }, "v2.InstanceResV2": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 7a5a5932ef..0dfda137a3 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -3096,7 +3096,7 @@ }, { "type": "string", - "description": "filter by business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_by_business", "in": "query" }, @@ -3216,6 +3216,7 @@ ], "summary": "获取实例扫描任务详情", "operationId": "getInstanceAuditPlanDetailV1", + "deprecated": true, "parameters": [ { "type": "string", @@ -3849,7 +3850,7 @@ }, { "type": "string", - "description": "filter by business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_by_business", "in": "query" }, @@ -5482,7 +5483,7 @@ }, { "type": "string", - "description": "business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_business", "in": "query" }, @@ -10636,6 +10637,127 @@ } } }, + "/v2/projects/{project_name}/instance_audit_plans": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get instance audit plan info list", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取实例扫描任务列表", + "operationId": "getInstanceAuditPlansV2", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "filter by environment tag", + "name": "filter_by_environment_tag", + "in": "query" + }, + { + "type": "string", + "description": "filter by db type", + "name": "filter_by_db_type", + "in": "query" + }, + { + "type": "string", + "description": "filter by instance id", + "name": "filter_by_instance_id", + "in": "query" + }, + { + "type": "string", + "description": "filter instance audit plan type", + "name": "filter_by_audit_plan_type", + "in": "query" + }, + { + "type": "string", + "description": "filter instance audit plan active status", + "name": "filter_by_active_status", + "in": "query" + }, + { + "type": "string", + "description": "fuzzy search", + "name": "fuzzy_search", + "in": "query" + }, + { + "type": "integer", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "size of per page", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetInstanceAuditPlansRes" + } + } + } + } + }, + "/v2/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get instance audit plan detail", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取实例扫描任务详情", + "operationId": "getInstanceAuditPlanDetailV2", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance audit plan id", + "name": "instance_audit_plan_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetInstanceAuditPlanDetailRes" + } + } + } + } + }, "/v2/projects/{project_name}/instance_tips": { "get": { "security": [ @@ -10839,7 +10961,7 @@ }, { "type": "string", - "description": "business // TODO This parameter is deprecated and will be removed soon.", + "description": "filter by business", "name": "filter_business", "in": "query" }, @@ -16681,7 +16803,7 @@ } }, "business": { - "description": "TODO This parameter is deprecated and will be removed soon.", + "description": "This parameter is deprecated", "type": "string", "example": "test" }, @@ -16771,7 +16893,7 @@ } }, "business": { - "description": "TODO This parameter is deprecated and will be removed soon.", + "description": "This parameter is deprecated", "type": "string" }, "create_time": { @@ -20492,6 +20614,34 @@ } } }, + "v2.AuditPlanRes": { + "type": "object", + "properties": { + "audit_plan_params": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.AuditPlanParamResV1" + } + }, + "audit_plan_type": { + "type": "object", + "$ref": "#/definitions/v2.AuditPlanTypeResBase" + }, + "high_priority_conditions": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.HighPriorityConditionResV1" + } + }, + "need_mark_high_priority_sql": { + "type": "boolean" + }, + "rule_template_name": { + "type": "string", + "example": "default_MySQL" + } + } + }, "v2.AuditPlanResV2": { "type": "object", "properties": { @@ -20583,6 +20733,37 @@ } } }, + "v2.AuditPlanTypeResBase": { + "type": "object", + "properties": { + "active_status": { + "type": "string", + "enum": [ + "normal", + "disabled" + ] + }, + "audit_plan_id": { + "type": "integer" + }, + "desc": { + "type": "string" + }, + "last_collection_status": { + "type": "string", + "enum": [ + "normal", + "abnormal" + ] + }, + "token": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "v2.AuditResDataV2": { "type": "object", "properties": { @@ -21107,6 +21288,45 @@ } } }, + "v2.GetInstanceAuditPlanDetailRes": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v2.InstanceAuditPlanDetailRes" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, + "v2.GetInstanceAuditPlansRes": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.InstanceAuditPlanResV1" + } + }, + "message": { + "type": "string", + "example": "ok" + }, + "total_nums": { + "type": "integer" + } + } + }, "v2.GetInstanceResV2": { "type": "object", "properties": { @@ -21280,6 +21500,74 @@ } } }, + "v2.InstanceAuditPlanDetailRes": { + "type": "object", + "properties": { + "audit_plans": { + "description": "扫描类型", + "type": "array", + "items": { + "$ref": "#/definitions/v2.AuditPlanRes" + } + }, + "environment": { + "type": "string", + "example": "prod" + }, + "instance_id": { + "type": "string", + "example": "instance_id" + }, + "instance_name": { + "type": "string", + "example": "test_mysql" + }, + "instance_type": { + "type": "string", + "example": "mysql" + } + } + }, + "v2.InstanceAuditPlanResV1": { + "type": "object", + "properties": { + "active_status": { + "type": "string", + "enum": [ + "normal", + "disabled" + ] + }, + "audit_plan_types": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.AuditPlanTypeResBase" + } + }, + "create_time": { + "description": "TODO 采集状态", + "type": "string" + }, + "creator": { + "type": "string" + }, + "environment": { + "type": "string" + }, + "instance_audit_plan_id": { + "type": "integer" + }, + "instance_id": { + "type": "string" + }, + "instance_name": { + "type": "string" + }, + "instance_type": { + "type": "string" + } + } + }, "v2.InstanceResV2": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 7b53c5728b..241de99385 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -3156,7 +3156,7 @@ definitions: $ref: '#/definitions/v1.AuditPlanRes' type: array business: - description: TODO This parameter is deprecated and will be removed soon. + description: This parameter is deprecated example: test type: string environment: @@ -3220,7 +3220,7 @@ definitions: $ref: '#/definitions/v1.AuditPlanTypeResBase' type: array business: - description: TODO This parameter is deprecated and will be removed soon. + description: This parameter is deprecated type: string create_time: description: TODO 采集状态 @@ -5753,6 +5753,25 @@ definitions: example: 1 type: integer type: object + v2.AuditPlanRes: + properties: + audit_plan_params: + items: + $ref: '#/definitions/v1.AuditPlanParamResV1' + type: array + audit_plan_type: + $ref: '#/definitions/v2.AuditPlanTypeResBase' + type: object + high_priority_conditions: + items: + $ref: '#/definitions/v1.HighPriorityConditionResV1' + type: array + need_mark_high_priority_sql: + type: boolean + rule_template_name: + example: default_MySQL + type: string + type: object v2.AuditPlanResV2: properties: audit_plan_cron: @@ -5819,6 +5838,27 @@ definitions: example: 100.22 type: number type: object + v2.AuditPlanTypeResBase: + properties: + active_status: + enum: + - normal + - disabled + type: string + audit_plan_id: + type: integer + desc: + type: string + last_collection_status: + enum: + - normal + - abnormal + type: string + token: + type: string + type: + type: string + type: object v2.AuditResDataV2: properties: audit_level: @@ -6180,6 +6220,33 @@ definitions: example: ok type: string type: object + v2.GetInstanceAuditPlanDetailRes: + properties: + code: + example: 0 + type: integer + data: + $ref: '#/definitions/v2.InstanceAuditPlanDetailRes' + type: object + message: + example: ok + type: string + type: object + v2.GetInstanceAuditPlansRes: + properties: + code: + example: 0 + type: integer + data: + items: + $ref: '#/definitions/v2.InstanceAuditPlanResV1' + type: array + message: + example: ok + type: string + total_nums: + type: integer + type: object v2.GetInstanceResV2: properties: code: @@ -6301,6 +6368,53 @@ definitions: example: ok type: string type: object + v2.InstanceAuditPlanDetailRes: + properties: + audit_plans: + description: 扫描类型 + items: + $ref: '#/definitions/v2.AuditPlanRes' + type: array + environment: + example: prod + type: string + instance_id: + example: instance_id + type: string + instance_name: + example: test_mysql + type: string + instance_type: + example: mysql + type: string + type: object + v2.InstanceAuditPlanResV1: + properties: + active_status: + enum: + - normal + - disabled + type: string + audit_plan_types: + items: + $ref: '#/definitions/v2.AuditPlanTypeResBase' + type: array + create_time: + description: TODO 采集状态 + type: string + creator: + type: string + environment: + type: string + instance_audit_plan_id: + type: integer + instance_id: + type: string + instance_name: + type: string + instance_type: + type: string + type: object v2.InstanceResV2: properties: additional_params: @@ -8676,8 +8790,7 @@ paths: name: project_name required: true type: string - - description: filter by business // TODO This parameter is deprecated and will - be removed soon. + - description: filter by business in: query name: filter_by_business type: string @@ -8754,6 +8867,7 @@ paths: - instance_audit_plan /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}: get: + deprecated: true description: get instance audit plan detail operationId: getInstanceAuditPlanDetailV1 parameters: @@ -9169,8 +9283,7 @@ paths: in: query name: filter_db_type type: string - - description: filter by business // TODO This parameter is deprecated and will - be removed soon. + - description: filter by business in: query name: filter_by_business type: string @@ -10316,8 +10429,7 @@ paths: in: query name: filter_assignee type: string - - description: business // TODO This parameter is deprecated and will be removed - soon. + - description: filter by business in: query name: filter_business type: string @@ -13612,6 +13724,85 @@ paths: summary: 增量同步SQL到扫描任务 tags: - audit_plan + /v2/projects/{project_name}/instance_audit_plans: + get: + description: get instance audit plan info list + operationId: getInstanceAuditPlansV2 + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: filter by environment tag + in: query + name: filter_by_environment_tag + type: string + - description: filter by db type + in: query + name: filter_by_db_type + type: string + - description: filter by instance id + in: query + name: filter_by_instance_id + type: string + - description: filter instance audit plan type + in: query + name: filter_by_audit_plan_type + type: string + - description: filter instance audit plan active status + in: query + name: filter_by_active_status + type: string + - description: fuzzy search + in: query + name: fuzzy_search + type: string + - description: page index + in: query + name: page_index + required: true + type: integer + - description: size of per page + in: query + name: page_size + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v2.GetInstanceAuditPlansRes' + security: + - ApiKeyAuth: [] + summary: 获取实例扫描任务列表 + tags: + - instance_audit_plan + /v2/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}: + get: + description: get instance audit plan detail + operationId: getInstanceAuditPlanDetailV2 + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: instance audit plan id + in: path + name: instance_audit_plan_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v2.GetInstanceAuditPlanDetailRes' + security: + - ApiKeyAuth: [] + summary: 获取实例扫描任务详情 + tags: + - instance_audit_plan /v2/projects/{project_name}/instance_tips: get: description: get instance tip list @@ -13744,8 +13935,7 @@ paths: in: query name: filter_db_type type: string - - description: business // TODO This parameter is deprecated and will be removed - soon. + - description: filter by business in: query name: filter_business type: string diff --git a/sqle/locale/active.en.toml b/sqle/locale/active.en.toml index b009a11210..f47a505809 100644 --- a/sqle/locale/active.en.toml +++ b/sqle/locale/active.en.toml @@ -142,7 +142,7 @@ NotifyAuditPlanBodyLink = "\n- Scan Task Link: %v" NotifyAuditPlanSubject = "SQLE Scan Task [%v] Scan Result [%v]" NotifyManageRecordBodyLink = "\n- SQL Management Record Link: %v\n" NotifyManageRecordBodyProj = "Project: %v" -NotifyManageRecordBodyRecord = "- SQL ID: %v\n- Data Source Name: %v\n- Business: %v\n- SQL: %v\n- Trigger Rule Level: %v\n- SQL Audit Recommendation: %v\n================================" +NotifyManageRecordBodyRecord = "- SQL ID: %v\n- Data Source Name: %v\n- Environment: %v\n- SQL: %v\n- Trigger Rule Level: %v\n- SQL Audit Recommendation: %v\n================================" NotifyManageRecordBodyTime = "Record Time Period: %v - %v" NotifyManageRecordSubject = "SQL Management Record" NotifyWorkflowBodyConfigUrl = "Please add a global URL in the system settings - global configuration" diff --git a/sqle/locale/active.zh.toml b/sqle/locale/active.zh.toml index dcfb57cabc..0c9922b3ae 100644 --- a/sqle/locale/active.zh.toml +++ b/sqle/locale/active.zh.toml @@ -142,7 +142,7 @@ NotifyAuditPlanBodyLink = "\n- 扫描任务链接: %v" NotifyAuditPlanSubject = "SQLE扫描任务[%v]扫描结果[%v]" NotifyManageRecordBodyLink = "\n- SQL管控记录链接: %v\n" NotifyManageRecordBodyProj = "所属项目: %v" -NotifyManageRecordBodyRecord = "- SQL ID: %v\n- 所在数据源名称: %v\n- 所属业务: %v\n- SQL: %v\n- 触发规则级别: %v\n- SQL审核建议: %v\n================================" +NotifyManageRecordBodyRecord = "- SQL ID: %v\n- 所在数据源名称: %v\n- 环境属性: %v\n- SQL: %v\n- 触发规则级别: %v\n- SQL审核建议: %v\n================================" NotifyManageRecordBodyTime = "记录时间周期: %v - %v" NotifyManageRecordSubject = "SQL管控记录" NotifyWorkflowBodyConfigUrl = "请在系统设置-全局配置中补充全局url" diff --git a/sqle/locale/message_zh.go b/sqle/locale/message_zh.go index cfd21ff34a..cffb99250c 100644 --- a/sqle/locale/message_zh.go +++ b/sqle/locale/message_zh.go @@ -327,8 +327,8 @@ var ( ApMetricNameMetaType = &i18n.Message{ID: "ApMetricNameMetaType", Other: "对象类型"} ApMetricNameQueryTimeTotal = &i18n.Message{ID: "ApMetricNameQueryTimeTotal", Other: "总执行时间(s)"} ApMetricNameQueryTimeAvg = &i18n.Message{ID: "ApMetricNameQueryTimeAvg", Other: "平均执行时间(s)"} - ApMetricNameQueryTimeTotalMS = &i18n.Message{ID: "ApMetricNameQueryTimeTotalMS", Other: "总执行时间(ms)"} - ApMetricNameQueryTimeAvgMS = &i18n.Message{ID: "ApMetricNameQueryTimeAvgMS", Other: "平均执行时间(ms)"} + ApMetricNameQueryTimeTotalMS = &i18n.Message{ID: "ApMetricNameQueryTimeTotalMS", Other: "总执行时间(ms)"} + ApMetricNameQueryTimeAvgMS = &i18n.Message{ID: "ApMetricNameQueryTimeAvgMS", Other: "平均执行时间(ms)"} ApMetricNameCounter = &i18n.Message{ID: "ApMetricNameCounter", Other: "执行次数"} ApMetricNameCPUTimeAvg = &i18n.Message{ID: "ApMetricNameCPUTimeAvg", Other: "平均 CPU 时间(μs)"} ApMetricNameLockWaitTimeTotal = &i18n.Message{ID: "ApMetricNameLockWaitTimeTotal", Other: "锁等待时间(ms)"} @@ -429,7 +429,7 @@ var ( NotifyManageRecordSubject = &i18n.Message{ID: "NotifyManageRecordSubject", Other: "SQL管控记录"} NotifyManageRecordBodyLink = &i18n.Message{ID: "NotifyManageRecordBodyLink", Other: "\n- SQL管控记录链接: %v\n"} - NotifyManageRecordBodyRecord = &i18n.Message{ID: "NotifyManageRecordBodyRecord", Other: "- SQL ID: %v\n- 所在数据源名称: %v\n- 所属业务: %v\n- SQL: %v\n- 触发规则级别: %v\n- SQL审核建议: %v\n================================"} + NotifyManageRecordBodyRecord = &i18n.Message{ID: "NotifyManageRecordBodyRecord", Other: "- SQL ID: %v\n- 所在数据源名称: %v\n- 环境属性: %v\n- SQL: %v\n- 触发规则级别: %v\n- SQL审核建议: %v\n================================"} NotifyManageRecordBodyTime = &i18n.Message{ID: "NotifyManageRecordBodyTime", Other: "记录时间周期: %v - %v"} NotifyManageRecordBodyProj = &i18n.Message{ID: "NotifyManageRecordBodyProj", Other: "所属项目: %v"} diff --git a/sqle/model/instance.go b/sqle/model/instance.go index 9867f59506..42c6a83250 100644 --- a/sqle/model/instance.go +++ b/sqle/model/instance.go @@ -35,8 +35,6 @@ type Instance struct { SqlQueryConfig SqlQueryConfig `json:"sql_query_config" gorm:"type:varchar(255); default:'{\"max_pre_query_rows\":100,\"query_timeout_second\":10}'"` Source string `json:"source" gorm:"not null"` SyncInstanceTaskID uint `json:"sync_instance_task_id"` - // TODO This parameter is deprecated and will be removed soon. - Business string `json:"business"` Environment string `json:"environment"` EnableBackup bool `json:"enable_backup"` BackupMaxRows uint64 `json:"backup_max_rows"`