Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

{
Expand Down
4 changes: 2 additions & 2 deletions sqle/api/controller/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
206 changes: 7 additions & 199 deletions sqle/api/controller/v1/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

v1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
Expand Down Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"
Expand All @@ -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 {
Expand All @@ -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" `
Expand All @@ -644,6 +540,7 @@ type HighPriorityCondition struct {
Operator Operator `json:"operator"`
}

// @Deprecated
// @Summary 获取实例扫描任务详情
// @Description get instance audit plan detail
// @Id getInstanceAuditPlanDetailV1
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/project_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions sqle/api/controller/v1/sql_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading