From 480e1c055dbf067970158a6a7a8c0866b7ff9223 Mon Sep 17 00:00:00 2001 From: iwanghc Date: Tue, 13 Aug 2024 15:58:49 +0800 Subject: [PATCH 1/4] feat: audit plan analysis and sql audit api define --- sqle/api/app.go | 2 ++ sqle/api/controller/v1/audit_plan.go | 15 +++++++++++++++ sqle/api/controller/v2/audit_plan.go | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/sqle/api/app.go b/sqle/api/app.go index f5213340e..862009832 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -280,6 +280,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sql_meta", v1.GetInstanceAuditPlanSQLMeta) v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sql_data", v1.GetInstanceAuditPlanSQLData) v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sql_export", v1.GetInstanceAuditPlanSQLExport) + v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/audit", v1.AuditPlanTriggerSqlAudit) // sql manager v1ProjectRouter.GET("/:project_name/sql_manages", v1.GetSqlManageList) @@ -335,6 +336,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti // audit plan; 智能扫描任务 v2ProjectRouter.GET("/:project_name/audit_plans", v2.GetAuditPlans) v2ProjectRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls/:number/analysis", v2.GetAuditPlanAnalysisData) + v2ProjectRouter.GET("/:project_name/audit_plans/:instance_audit_plan_id/sqls/:sql_manage_record_id/analysis", v2.GetSqlManageRecordAnalysisData) v2ProjectRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls", v2.GetAuditPlanReportSQLs) // sql managers diff --git a/sqle/api/controller/v1/audit_plan.go b/sqle/api/controller/v1/audit_plan.go index 50c631ce0..7add77ade 100644 --- a/sqle/api/controller/v1/audit_plan.go +++ b/sqle/api/controller/v1/audit_plan.go @@ -1154,6 +1154,21 @@ func TriggerAuditPlan(c echo.Context) error { }) } +// @Summary 扫描任务触发sql审核 +// @Description audit plan trigger sql audit +// @Id auditPlanTriggerSqlAuditV1 +// @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" +// @Param audit_plan_id path string true "audit plan id" +// @Success 200 {object} controller.BaseRes +// @router /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit [post] +func AuditPlanTriggerSqlAudit(c echo.Context) error { + + return controller.JSONBaseErrorReq(c, nil) +} + type UpdateAuditPlanNotifyConfigReqV1 struct { NotifyInterval *int `json:"notify_interval" default:"10"` NotifyLevel *string `json:"notify_level" default:"warn" enums:"normal,notice,warn,error" valid:"oneof=normal notice warn error"` diff --git a/sqle/api/controller/v2/audit_plan.go b/sqle/api/controller/v2/audit_plan.go index 35a40adeb..301f15612 100644 --- a/sqle/api/controller/v2/audit_plan.go +++ b/sqle/api/controller/v2/audit_plan.go @@ -298,6 +298,24 @@ func GetAuditPlanAnalysisData(c echo.Context) error { }) } +// GetSqlManageRecordAnalysisData get SQL explain and related table metadata for analysis +// @Summary 获取扫描任务相关的SQL执行计划和表元数据 +// @Description get SQL explain and related table metadata for analysis +// @Id getSqlManageRecordAnalysisDataV2 +// @Tags instance_audit_plan +// @Param project_name path string true "project name" +// @Param instance_audit_plan_id path string true "instance audit plan id" +// @Param sql_manage_record_id path string true "sql manage record id" +// @Security ApiKeyAuth +// @Success 200 {object} v2.GetAuditPlanAnalysisDataResV2 +// @router /v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis [get] +func GetSqlManageRecordAnalysisData(c echo.Context) error { + return c.JSON(http.StatusOK, &GetAuditPlanAnalysisDataResV2{ + BaseRes: controller.NewBaseReq(nil), + Data: nil, + }) +} + type AuditPlanSQLReqV2 struct { Fingerprint string `json:"audit_plan_sql_fingerprint" form:"audit_plan_sql_fingerprint" example:"select * from t1 where id = ?"` Counter string `json:"audit_plan_sql_counter" form:"audit_plan_sql_counter" example:"6" valid:"required"` From 101b6ef32247887b358528a23eb8e6e0fbd73d97 Mon Sep 17 00:00:00 2001 From: iwanghc Date: Tue, 13 Aug 2024 16:00:21 +0800 Subject: [PATCH 2/4] gen swaggger: audit plan analysis and sql audit api --- sqle/docs/docs.go | 267 ++++++++++++++++++++++++++++++++++++++++- sqle/docs/swagger.json | 267 ++++++++++++++++++++++++++++++++++++++++- sqle/docs/swagger.yaml | 176 ++++++++++++++++++++++++++- 3 files changed, 707 insertions(+), 3 deletions(-) diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 1ff039273..e6da55b7e 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -2528,6 +2528,52 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "audit plan trigger sql audit", + "tags": [ + "instance_audit_plan" + ], + "summary": "扫描任务触发sql审核", + "operationId": "auditPlanTriggerSqlAuditV1", + "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 + }, + { + "type": "string", + "description": "audit plan id", + "name": "audit_plan_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/sql_data": { "post": { "security": [ @@ -3063,6 +3109,86 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/report_push_configs": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get report push config list", + "tags": [ + "ReportPushConfig" + ], + "summary": "获取消息推送配置列表", + "operationId": "GetReportPushConfigList", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetReportPushConfigsListResV1" + } + } + } + } + }, + "/v1/projects/{project_name}/report_push_configs/{report_push_config_id}/": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update report push config", + "tags": [ + "ReportPushConfig" + ], + "summary": "更新消息推送配置", + "operationId": "UpdateReportPushConfig", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "report push config id", + "name": "report_push_config_id", + "in": "path", + "required": true + }, + { + "description": "update report push config request", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateReportPushConfigReqV1" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/projects/{project_name}/rule_template_tips": { "get": { "security": [ @@ -5556,7 +5682,7 @@ var doc = `{ "tags": [ "workflow" ], - "summary": "获取工单附件", + "summary": "获取工单的task附件", "operationId": "getWorkflowAttachment", "parameters": [ { @@ -8169,6 +8295,52 @@ var doc = `{ } } }, + "/v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get SQL explain and related table metadata for analysis", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取扫描任务相关的SQL执行计划和表元数据", + "operationId": "getSqlManageRecordAnalysisDataV2", + "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 + }, + { + "type": "string", + "description": "sql manage record id", + "name": "sql_manage_record_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetAuditPlanAnalysisDataResV2" + } + } + } + } + }, "/v2/projects/{project_name}/instances/{instance_name}/": { "get": { "security": [ @@ -11572,6 +11744,25 @@ var doc = `{ } } }, + "v1.GetReportPushConfigsListResV1": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.ReportPushConfigList" + } + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetRiskAuditPlanResV1": { "type": "object", "properties": { @@ -13110,6 +13301,46 @@ var doc = `{ } } }, + "v1.ReportPushConfigList": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "last_push_time": { + "type": "string" + }, + "push_frequency_cron": { + "type": "string" + }, + "push_user_Type": { + "type": "string", + "enum": [ + "fixed", + "permission_match" + ] + }, + "push_user_list": { + "type": "array", + "items": { + "type": "string" + } + }, + "report_push_config_id": { + "type": "string" + }, + "trigger_type": { + "type": "string", + "enum": [ + "immediately", + "timing" + ] + }, + "type": { + "type": "string" + } + } + }, "v1.RewriteRule": { "type": "object", "properties": { @@ -14290,6 +14521,37 @@ var doc = `{ } } }, + "v1.UpdateReportPushConfigReqV1": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "push_frequency_cron": { + "type": "string" + }, + "push_user_Type": { + "type": "string", + "enum": [ + "fixed", + "permission_match" + ] + }, + "push_user_list": { + "type": "array", + "items": { + "type": "string" + } + }, + "trigger_type": { + "type": "string", + "enum": [ + "immediately", + "timing" + ] + } + } + }, "v1.UpdateRuleKnowledgeReq": { "type": "object", "properties": { @@ -15784,6 +16046,9 @@ var doc = `{ "last_receive_timestamp": { "type": "string" }, + "priority": { + "type": "string" + }, "remark": { "type": "string" }, diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 08c38f524..f0c667dee 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -2512,6 +2512,52 @@ } } }, + "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "audit plan trigger sql audit", + "tags": [ + "instance_audit_plan" + ], + "summary": "扫描任务触发sql审核", + "operationId": "auditPlanTriggerSqlAuditV1", + "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 + }, + { + "type": "string", + "description": "audit plan id", + "name": "audit_plan_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/sql_data": { "post": { "security": [ @@ -3047,6 +3093,86 @@ } } }, + "/v1/projects/{project_name}/report_push_configs": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get report push config list", + "tags": [ + "ReportPushConfig" + ], + "summary": "获取消息推送配置列表", + "operationId": "GetReportPushConfigList", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetReportPushConfigsListResV1" + } + } + } + } + }, + "/v1/projects/{project_name}/report_push_configs/{report_push_config_id}/": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update report push config", + "tags": [ + "ReportPushConfig" + ], + "summary": "更新消息推送配置", + "operationId": "UpdateReportPushConfig", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "report push config id", + "name": "report_push_config_id", + "in": "path", + "required": true + }, + { + "description": "update report push config request", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateReportPushConfigReqV1" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/projects/{project_name}/rule_template_tips": { "get": { "security": [ @@ -5540,7 +5666,7 @@ "tags": [ "workflow" ], - "summary": "获取工单附件", + "summary": "获取工单的task附件", "operationId": "getWorkflowAttachment", "parameters": [ { @@ -8153,6 +8279,52 @@ } } }, + "/v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get SQL explain and related table metadata for analysis", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取扫描任务相关的SQL执行计划和表元数据", + "operationId": "getSqlManageRecordAnalysisDataV2", + "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 + }, + { + "type": "string", + "description": "sql manage record id", + "name": "sql_manage_record_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2.GetAuditPlanAnalysisDataResV2" + } + } + } + } + }, "/v2/projects/{project_name}/instances/{instance_name}/": { "get": { "security": [ @@ -11556,6 +11728,25 @@ } } }, + "v1.GetReportPushConfigsListResV1": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.ReportPushConfigList" + } + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetRiskAuditPlanResV1": { "type": "object", "properties": { @@ -13094,6 +13285,46 @@ } } }, + "v1.ReportPushConfigList": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "last_push_time": { + "type": "string" + }, + "push_frequency_cron": { + "type": "string" + }, + "push_user_Type": { + "type": "string", + "enum": [ + "fixed", + "permission_match" + ] + }, + "push_user_list": { + "type": "array", + "items": { + "type": "string" + } + }, + "report_push_config_id": { + "type": "string" + }, + "trigger_type": { + "type": "string", + "enum": [ + "immediately", + "timing" + ] + }, + "type": { + "type": "string" + } + } + }, "v1.RewriteRule": { "type": "object", "properties": { @@ -14274,6 +14505,37 @@ } } }, + "v1.UpdateReportPushConfigReqV1": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "push_frequency_cron": { + "type": "string" + }, + "push_user_Type": { + "type": "string", + "enum": [ + "fixed", + "permission_match" + ] + }, + "push_user_list": { + "type": "array", + "items": { + "type": "string" + } + }, + "trigger_type": { + "type": "string", + "enum": [ + "immediately", + "timing" + ] + } + } + }, "v1.UpdateRuleKnowledgeReq": { "type": "object", "properties": { @@ -15768,6 +16030,9 @@ "last_receive_timestamp": { "type": "string" }, + "priority": { + "type": "string" + }, "remark": { "type": "string" }, diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 774b5e114..d8e152488 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -1648,6 +1648,19 @@ definitions: example: ok type: string type: object + v1.GetReportPushConfigsListResV1: + properties: + code: + example: 0 + type: integer + data: + items: + $ref: '#/definitions/v1.ReportPushConfigList' + type: array + message: + example: ok + type: string + type: object v1.GetRiskAuditPlanResV1: properties: code: @@ -2698,6 +2711,33 @@ definitions: reason: type: string type: object + v1.ReportPushConfigList: + properties: + enabled: + type: boolean + last_push_time: + type: string + push_frequency_cron: + type: string + push_user_Type: + enum: + - fixed + - permission_match + type: string + push_user_list: + items: + type: string + type: array + report_push_config_id: + type: string + trigger_type: + enum: + - immediately + - timing + type: string + type: + type: string + type: object v1.RewriteRule: properties: message: @@ -3493,6 +3533,27 @@ definitions: $ref: '#/definitions/v1.RuleReqV1' type: array type: object + v1.UpdateReportPushConfigReqV1: + properties: + enabled: + type: boolean + push_frequency_cron: + type: string + push_user_Type: + enum: + - fixed + - permission_match + type: string + push_user_list: + items: + type: string + type: array + trigger_type: + enum: + - immediately + - timing + type: string + type: object v1.UpdateRuleKnowledgeReq: properties: knowledge_content: @@ -4510,6 +4571,8 @@ definitions: type: string last_receive_timestamp: type: string + priority: + type: string remark: type: string schema_name: @@ -6274,6 +6337,36 @@ paths: summary: 更新扫描任务状态 tags: - instance_audit_plan + /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit: + post: + description: audit plan trigger sql audit + operationId: auditPlanTriggerSqlAuditV1 + 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 + - description: audit plan id + in: path + name: audit_plan_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 扫描任务触发sql审核 + tags: + - instance_audit_plan /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/sql_data: post: description: get audit plan SQLs @@ -6623,6 +6716,57 @@ paths: summary: 批量测试实例连通性(实例提交后) tags: - instance + /v1/projects/{project_name}/report_push_configs: + get: + description: Get report push config list + operationId: GetReportPushConfigList + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetReportPushConfigsListResV1' + security: + - ApiKeyAuth: [] + summary: 获取消息推送配置列表 + tags: + - ReportPushConfig + /v1/projects/{project_name}/report_push_configs/{report_push_config_id}/: + put: + description: update report push config + operationId: UpdateReportPushConfig + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: report push config id + in: path + name: report_push_config_id + required: true + type: string + - description: update report push config request + in: body + name: req + required: true + schema: + $ref: '#/definitions/v1.UpdateReportPushConfigReqV1' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 更新消息推送配置 + tags: + - ReportPushConfig /v1/projects/{project_name}/rule_template_tips: get: description: get rule template tips in project @@ -8140,7 +8284,7 @@ paths: type: file security: - ApiKeyAuth: [] - summary: 获取工单附件 + summary: 获取工单的task附件 tags: - workflow /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file: @@ -9964,6 +10108,36 @@ paths: summary: 增量同步SQL到扫描任务 tags: - audit_plan + /v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis: + get: + description: get SQL explain and related table metadata for analysis + operationId: getSqlManageRecordAnalysisDataV2 + 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 + - description: sql manage record id + in: path + name: sql_manage_record_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v2.GetAuditPlanAnalysisDataResV2' + security: + - ApiKeyAuth: [] + summary: 获取扫描任务相关的SQL执行计划和表元数据 + tags: + - instance_audit_plan /v2/projects/{project_name}/instances/{instance_name}/: get: description: get instance db From 92a06e08a7a9e261f2afd3650e370ee5f2f999bd Mon Sep 17 00:00:00 2001 From: iwanghc Date: Wed, 14 Aug 2024 13:24:52 +0800 Subject: [PATCH 3/4] modify: analysis and sql audit api place move and route modify --- sqle/api/app.go | 2 +- sqle/api/controller/v1/audit_plan.go | 15 -------- sqle/api/controller/v1/instance_audit_plan.go | 34 +++++++++++++++++++ sqle/api/controller/v2/audit_plan.go | 18 ---------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/sqle/api/app.go b/sqle/api/app.go index 862009832..5fe7a98f8 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -281,6 +281,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sql_data", v1.GetInstanceAuditPlanSQLData) v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sql_export", v1.GetInstanceAuditPlanSQLExport) v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/audit", v1.AuditPlanTriggerSqlAudit) + v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/sqls/:id/analysis", v1.GetAuditPlanSqlAnalysisData) // sql manager v1ProjectRouter.GET("/:project_name/sql_manages", v1.GetSqlManageList) @@ -336,7 +337,6 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti // audit plan; 智能扫描任务 v2ProjectRouter.GET("/:project_name/audit_plans", v2.GetAuditPlans) v2ProjectRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls/:number/analysis", v2.GetAuditPlanAnalysisData) - v2ProjectRouter.GET("/:project_name/audit_plans/:instance_audit_plan_id/sqls/:sql_manage_record_id/analysis", v2.GetSqlManageRecordAnalysisData) v2ProjectRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls", v2.GetAuditPlanReportSQLs) // sql managers diff --git a/sqle/api/controller/v1/audit_plan.go b/sqle/api/controller/v1/audit_plan.go index 7add77ade..50c631ce0 100644 --- a/sqle/api/controller/v1/audit_plan.go +++ b/sqle/api/controller/v1/audit_plan.go @@ -1154,21 +1154,6 @@ func TriggerAuditPlan(c echo.Context) error { }) } -// @Summary 扫描任务触发sql审核 -// @Description audit plan trigger sql audit -// @Id auditPlanTriggerSqlAuditV1 -// @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" -// @Param audit_plan_id path string true "audit plan id" -// @Success 200 {object} controller.BaseRes -// @router /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit [post] -func AuditPlanTriggerSqlAudit(c echo.Context) error { - - return controller.JSONBaseErrorReq(c, nil) -} - type UpdateAuditPlanNotifyConfigReqV1 struct { NotifyInterval *int `json:"notify_interval" default:"10"` NotifyLevel *string `json:"notify_level" default:"warn" enums:"normal,notice,warn,error" valid:"oneof=normal notice warn error"` diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index 484b6ecf0..3f7f21768 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -1213,3 +1213,37 @@ func ConvertReqToAuditPlanFilter(fs []Filter) []auditplan.Filter { } return filters } + +// GetAuditPlanSqlAnalysisData get SQL explain and related table metadata for analysis +// @Summary 获取扫描任务相关的SQL执行计划和表元数据 +// @Description get SQL explain and related table metadata for analysis +// @Id getAuditPlanSqlAnalysisDataV1 +// @Tags instance_audit_plan +// @Param project_name path string true "project name" +// @Param instance_audit_plan_id path string true "instance audit plan id" +// @Param id path string true "audit plan sql id" +// @Security ApiKeyAuth +// @Success 200 {object} v1.GetSqlManageSqlAnalysisResp +// @router /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/sqls/{id}/analysis [get] +func GetAuditPlanSqlAnalysisData(c echo.Context) error { + + return c.JSON(http.StatusOK, &GetSqlManageSqlAnalysisResp{ + BaseRes: controller.NewBaseReq(nil), + Data: nil, + }) +} + +// @Summary 扫描任务触发sql审核 +// @Description audit plan trigger sql audit +// @Id auditPlanTriggerSqlAuditV1 +// @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" +// @Param audit_plan_id path string true "audit plan id" +// @Success 200 {object} controller.BaseRes +// @router /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/audit_plans/{audit_plan_id}/audit [post] +func AuditPlanTriggerSqlAudit(c echo.Context) error { + + return controller.JSONBaseErrorReq(c, nil) +} diff --git a/sqle/api/controller/v2/audit_plan.go b/sqle/api/controller/v2/audit_plan.go index 301f15612..35a40adeb 100644 --- a/sqle/api/controller/v2/audit_plan.go +++ b/sqle/api/controller/v2/audit_plan.go @@ -298,24 +298,6 @@ func GetAuditPlanAnalysisData(c echo.Context) error { }) } -// GetSqlManageRecordAnalysisData get SQL explain and related table metadata for analysis -// @Summary 获取扫描任务相关的SQL执行计划和表元数据 -// @Description get SQL explain and related table metadata for analysis -// @Id getSqlManageRecordAnalysisDataV2 -// @Tags instance_audit_plan -// @Param project_name path string true "project name" -// @Param instance_audit_plan_id path string true "instance audit plan id" -// @Param sql_manage_record_id path string true "sql manage record id" -// @Security ApiKeyAuth -// @Success 200 {object} v2.GetAuditPlanAnalysisDataResV2 -// @router /v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis [get] -func GetSqlManageRecordAnalysisData(c echo.Context) error { - return c.JSON(http.StatusOK, &GetAuditPlanAnalysisDataResV2{ - BaseRes: controller.NewBaseReq(nil), - Data: nil, - }) -} - type AuditPlanSQLReqV2 struct { Fingerprint string `json:"audit_plan_sql_fingerprint" form:"audit_plan_sql_fingerprint" example:"select * from t1 where id = ?"` Counter string `json:"audit_plan_sql_counter" form:"audit_plan_sql_counter" example:"6" valid:"required"` From 0708f8885bd4917a46fe189a11bc6edf9391c954 Mon Sep 17 00:00:00 2001 From: iwanghc Date: Wed, 14 Aug 2024 13:25:33 +0800 Subject: [PATCH 4/4] gen swagger: modify audit plan sql audit api and analysis api --- sqle/docs/docs.go | 92 +++++++++++++++++++++--------------------- sqle/docs/swagger.json | 92 +++++++++++++++++++++--------------------- sqle/docs/swagger.yaml | 60 +++++++++++++-------------- 3 files changed, 122 insertions(+), 122 deletions(-) diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index e6da55b7e..93fa2e4e4 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -2790,6 +2790,52 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/sqls/{id}/analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get SQL explain and related table metadata for analysis", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取扫描任务相关的SQL执行计划和表元数据", + "operationId": "getAuditPlanSqlAnalysisDataV1", + "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 + }, + { + "type": "string", + "description": "audit plan sql id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlManageSqlAnalysisResp" + } + } + } + } + }, "/v1/projects/{project_name}/instance_tips": { "get": { "security": [ @@ -8295,52 +8341,6 @@ var doc = `{ } } }, - "/v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "get SQL explain and related table metadata for analysis", - "tags": [ - "instance_audit_plan" - ], - "summary": "获取扫描任务相关的SQL执行计划和表元数据", - "operationId": "getSqlManageRecordAnalysisDataV2", - "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 - }, - { - "type": "string", - "description": "sql manage record id", - "name": "sql_manage_record_id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/v2.GetAuditPlanAnalysisDataResV2" - } - } - } - } - }, "/v2/projects/{project_name}/instances/{instance_name}/": { "get": { "security": [ diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index f0c667dee..4fbc44741 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -2774,6 +2774,52 @@ } } }, + "/v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/sqls/{id}/analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get SQL explain and related table metadata for analysis", + "tags": [ + "instance_audit_plan" + ], + "summary": "获取扫描任务相关的SQL执行计划和表元数据", + "operationId": "getAuditPlanSqlAnalysisDataV1", + "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 + }, + { + "type": "string", + "description": "audit plan sql id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlManageSqlAnalysisResp" + } + } + } + } + }, "/v1/projects/{project_name}/instance_tips": { "get": { "security": [ @@ -8279,52 +8325,6 @@ } } }, - "/v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "get SQL explain and related table metadata for analysis", - "tags": [ - "instance_audit_plan" - ], - "summary": "获取扫描任务相关的SQL执行计划和表元数据", - "operationId": "getSqlManageRecordAnalysisDataV2", - "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 - }, - { - "type": "string", - "description": "sql manage record id", - "name": "sql_manage_record_id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/v2.GetAuditPlanAnalysisDataResV2" - } - } - } - } - }, "/v2/projects/{project_name}/instances/{instance_name}/": { "get": { "security": [ diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index d8e152488..8e798ba56 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -6509,6 +6509,36 @@ paths: summary: 获取指定扫描任务的SQLs信息 tags: - instance_audit_plan + /v1/projects/{project_name}/instance_audit_plans/{instance_audit_plan_id}/sqls/{id}/analysis: + get: + description: get SQL explain and related table metadata for analysis + operationId: getAuditPlanSqlAnalysisDataV1 + 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 + - description: audit plan sql id + in: path + name: id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetSqlManageSqlAnalysisResp' + security: + - ApiKeyAuth: [] + summary: 获取扫描任务相关的SQL执行计划和表元数据 + tags: + - instance_audit_plan /v1/projects/{project_name}/instance_tips: get: description: get instance tip list @@ -10108,36 +10138,6 @@ paths: summary: 增量同步SQL到扫描任务 tags: - audit_plan - /v2/projects/{project_name}/audit_plans/{instance_audit_plan_id}/sqls/{sql_manage_record_id}/analysis: - get: - description: get SQL explain and related table metadata for analysis - operationId: getSqlManageRecordAnalysisDataV2 - 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 - - description: sql manage record id - in: path - name: sql_manage_record_id - required: true - type: string - responses: - "200": - description: OK - schema: - $ref: '#/definitions/v2.GetAuditPlanAnalysisDataResV2' - security: - - ApiKeyAuth: [] - summary: 获取扫描任务相关的SQL执行计划和表元数据 - tags: - - instance_audit_plan /v2/projects/{project_name}/instances/{instance_name}/: get: description: get instance db