Skip to content

Commit

Permalink
Merge pull request #2716 from actiontech/ee-1907
Browse files Browse the repository at this point in the history
Ee 1907
  • Loading branch information
ColdWaterLW authored Oct 25, 2024
2 parents 9742078 + 40a9f70 commit c61eeea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
46 changes: 29 additions & 17 deletions sqle/api/controller/v1/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ type AuditPlanTypeResBase struct {
AuditPlanId uint `json:"audit_plan_id"`
AuditPlanType string `json:"type"`
AuditPlanTypeDesc string `json:"desc"`
Token string `json:"token"`
}

type GetInstanceAuditPlansReqV1 struct {
Expand Down Expand Up @@ -519,7 +520,7 @@ func GetInstanceAuditPlans(c echo.Context) error {
typeBases := make([]AuditPlanTypeResBase, 0, len(auditPlanIds))
for _, auditPlanId := range auditPlanIds {
if auditPlanId != "" {
typeBase, err := ConvertAuditPlanTypeToResByID(c.Request().Context(), auditPlanId)
typeBase, err := ConvertAuditPlanTypeToResByID(c.Request().Context(), auditPlanId, v.Token)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
Expand Down Expand Up @@ -547,7 +548,7 @@ func GetInstanceAuditPlans(c echo.Context) error {
})
}

func ConvertAuditPlanTypeToResByID(ctx context.Context, id string) (AuditPlanTypeResBase, error) {
func ConvertAuditPlanTypeToResByID(ctx context.Context, id string, token string) (AuditPlanTypeResBase, error) {
auditPlanID, err := strconv.Atoi(id)
if err != nil {
return AuditPlanTypeResBase{}, err
Expand All @@ -566,6 +567,7 @@ func ConvertAuditPlanTypeToResByID(ctx context.Context, id string) (AuditPlanTyp
AuditPlanType: auditPlan.Type,
AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc),
AuditPlanId: auditPlan.ID,
Token: token,
}, nil
}
}
Expand Down Expand Up @@ -834,22 +836,32 @@ func GetAuditPlanExecCmd(projectName string, iap *model.InstanceAuditPlan, ap *m
return ""
}

scannerd, err := scannerCmd.GetScannerdCmd(ap.Type)
if err != nil {
logger.Infof("get scannerd %s failed %s", ap.Type, err)
return ""
}
cmd, err := scannerd.GenCommand("./scannerd", map[string]string{
scannerCmd.FlagHost: ip,
scannerCmd.FlagPort: port,
scannerCmd.FlagProject: projectName,
scannerCmd.FlagToken: iap.Token,
scannerCmd.FlagAuditPlanID: fmt.Sprint(ap.ID),
})
if err != nil {
logger.Infof("generate scannerd %s command failed %s", ap.Type, err)
return ""
var cmd string
switch ap.Type {
case auditplan.TypeAllAppExtract:
cmd = fmt.Sprintf(`SQLE_PROJECT_NAME=%s \
PROJECT_APP_NAME=<Please provide the business parameters here> \
java -<Please provide the java agent name parameters here> \
-jar <Please provide the java app name parameters here>`, projectName)
default:
scannerd, err := scannerCmd.GetScannerdCmd(ap.Type)
if err != nil {
logger.Infof("get scannerd %s failed %s", ap.Type, err)
return ""
}
cmd, err = scannerd.GenCommand("./scannerd", map[string]string{
scannerCmd.FlagHost: ip,
scannerCmd.FlagPort: port,
scannerCmd.FlagProject: projectName,
scannerCmd.FlagToken: iap.Token,
scannerCmd.FlagAuditPlanID: fmt.Sprint(ap.ID),
})
if err != nil {
logger.Infof("generate scannerd %s command failed %s", ap.Type, err)
return ""
}
}

return cmd
}

Expand Down
1 change: 1 addition & 0 deletions sqle/model/instance_audit_plan_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SELECT
instance_audit_plans.active_status,
instance_audit_plans.create_user_id,
instance_audit_plans.created_at,
instance_audit_plans.token,
audit_plans.audit_plan_ids
Expand Down
5 changes: 3 additions & 2 deletions sqle/server/auditplan/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ func GetMeta(typ string) (Meta, error) {
}

var supportedCmdTypeList = map[string]struct{}{
TypeMySQLSlowLog: {},
TypeTiDBAuditLog: {},
TypeMySQLSlowLog: {},
TypeTiDBAuditLog: {},
TypeAllAppExtract: {},
}

func GetSupportedScannerAuditPlanType() map[string]struct{} {
Expand Down

0 comments on commit c61eeea

Please sign in to comment.