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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -140,6 +141,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ cloud.google.com/go/storage v1.10.0 h1:STgFzyU5/8miMl0//zKh2aQeTyeaUH3WN9bSUiJ09
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
Expand Down Expand Up @@ -620,6 +622,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/montanaflynn/stats v0.0.0-20151014174947-eeaced052adb/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
Expand Down Expand Up @@ -822,6 +826,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand Down
44 changes: 25 additions & 19 deletions sqle/api/controller/v1/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,14 @@ func GetInstanceAuditPlanSQLData(c echo.Context) error {
}

type GetAuditPlanSQLExportReqV1 struct {
OrderBy string `json:"order_by"`
IsAsc bool `json:"is_asc"`
Filters []Filter `json:"filter_list"`
OrderBy string `json:"order_by"`
IsAsc bool `json:"is_asc"`
Filters []Filter `json:"filter_list"`
ExportFormat utils.ExportFormat `json:"export_format" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel
}

// @Summary 导出指定扫描任务的 SQL CSV 列表
// @Description export audit plan SQL report as CSV
// @Summary 导出指定扫描任务的 SQL 列表
// @Description export audit plan SQL report as CSV or Excel
// @Id getInstanceAuditPlanSQLExportV1
// @Tags instance_audit_plan
// @Security ApiKeyAuth
Expand Down Expand Up @@ -1193,29 +1194,34 @@ func GetInstanceAuditPlanSQLExport(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

csvBuilder := utils.NewCSVBuilder()
// 确定导出格式,默认为excel
exportFormat := utils.NormalizeExportFormat(&req.ExportFormat)

csvHeader := make([]string, len(head))
// 准备表头数据
header := make([]string, len(head))
for col, h := range head {
csvHeader[col] = locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), h.Desc)
}
if err = csvBuilder.WriteHeader(csvHeader); err != nil {
return controller.JSONBaseErrorReq(c, err)
header[col] = locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), h.Desc)
}

// 准备行数据
rowData := make([][]string, 0, len(rows))
for _, rowMap := range rows {
csvRow := make([]string, len(head))
row := make([]string, len(head))
for col, h := range head {
csvRow[col] = rowMap[h.Name]
}
if err = csvBuilder.WriteRow(csvRow); err != nil {
return controller.JSONBaseErrorReq(c, err)
row[col] = rowMap[h.Name]
}
rowData = append(rowData, row)
}

fileName := fmt.Sprintf("sql_export_%s_%s.csv", ap.Type, time.Now().Format("20060102150405"))
c.Response().Header().Set(echo.HeaderContentDisposition, mime.FormatMediaType("attachment", map[string]string{"filename": fileName}))
// 使用通用的导出方法
fileNamePrefix := fmt.Sprintf("sql_export_%s", ap.Type)
exportResult, err := utils.ExportData(header, rowData, fileNamePrefix, exportFormat)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}

return c.Blob(http.StatusOK, "text/csv", csvBuilder.FlushAndGetBuffer().Bytes())
c.Response().Header().Set(echo.HeaderContentDisposition, mime.FormatMediaType("attachment", map[string]string{"filename": exportResult.FileName}))
return c.Blob(http.StatusOK, exportResult.ContentType, exportResult.Content)
}

func ConvertFilterTipsToRes(fts []auditplan.FilterTip) []FilterTip {
Expand Down
4 changes: 3 additions & 1 deletion sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,11 +1568,12 @@ type ExportWorkflowReqV1 struct {
FilterTaskExecuteStartTimeFrom string `json:"filter_task_execute_start_time_from" query:"filter_task_execute_start_time_from"`
FilterTaskExecuteStartTimeTo string `json:"filter_task_execute_start_time_to" query:"filter_task_execute_start_time_to"`
FuzzyKeyword string `json:"fuzzy_keyword" query:"fuzzy_keyword"`
ExportFormat string `json:"export_format" query:"export_format" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel,默认为 excel
}

// ExportWorkflowV1
// @Summary 导出工单
// @Description export workflow
// @Description export workflow as CSV or Excel
// @Id exportWorkflowV1
// @Tags workflow
// @Security ApiKeyAuth
Expand All @@ -1588,6 +1589,7 @@ type ExportWorkflowReqV1 struct {
// @Param filter_task_instance_id query string false "filter instance id"
// @Param project_name path string true "project name"
// @Param fuzzy_keyword query string false "fuzzy matching subject/workflow_id/desc"
// @Param export_format query string false "export format" Enums(csv,excel) "export format: csv or excel, default is excel"
// @Success 200 {file} file "export workflow"
// @Router /v1/projects/{project_name}/workflows/exports [get]
func ExportWorkflowV1(c echo.Context) error {
Expand Down
8 changes: 5 additions & 3 deletions sqle/api/controller/v2/sql_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func GetSqlManageList(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"`
FuzzySearchSqlFingerprint *string `query:"fuzzy_search_sql_fingerprint" json:"fuzzy_search_sql_fingerprint,omitempty"`
FilterAssignee *string `query:"filter_assignee" json:"filter_assignee,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"`
FilterSource *string `query:"filter_source" json:"filter_source,omitempty"`
Expand All @@ -83,11 +83,12 @@ type ExportSqlManagesReq struct {
FuzzySearchSchemaName *string `query:"fuzzy_search_schema_name" json:"fuzzy_search_schema_name,omitempty"`
SortField *string `query:"sort_field" json:"sort_field,omitempty" valid:"omitempty,oneof=first_appear_timestamp last_receive_timestamp fp_count" enums:"first_appear_timestamp,last_receive_timestamp,fp_count"`
SortOrder *string `query:"sort_order" json:"sort_order,omitempty" valid:"omitempty,oneof=asc desc" enums:"asc,desc"`
ExportFormat *string `query:"export_format" json:"export_format,omitempty" enums:"csv,excel" example:"excel"` // 导出格式:csv 或 excel,默认为 excel
}

// ExportSqlManagesV2
// @Summary 导出SQL管控
// @Description export sql manage
// @Description export sql manage as CSV or Excel
// @Id exportSqlManageV2
// @Tags SqlManage
// @Security ApiKeyAuth
Expand All @@ -108,6 +109,7 @@ type ExportSqlManagesReq struct {
// @Param fuzzy_search_schema_name query string false "fuzzy search schema name"
// @Param sort_field query string false "sort field" Enums(first_appear_timestamp,last_receive_timestamp,fp_count)
// @Param sort_order query string false "sort order" Enums(asc,desc)
// @Param export_format query string false "export format" Enums(csv,excel) "export format: csv or excel, default is excel"
// @Success 200 {file} file "export sql manage"
// @Router /v2/projects/{project_name}/sql_manages/exports [get]
func ExportSqlManagesV2(c echo.Context) error {
Expand Down
37 changes: 33 additions & 4 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3766,11 +3766,11 @@ var doc = `{
"ApiKeyAuth": []
}
],
"description": "export audit plan SQL report as CSV",
"description": "export audit plan SQL report as CSV or Excel",
"tags": [
"instance_audit_plan"
],
"summary": "导出指定扫描任务的 SQL CSV 列表",
"summary": "导出指定扫描任务的 SQL 列表",
"operationId": "getInstanceAuditPlanSQLExportV1",
"parameters": [
{
Expand Down Expand Up @@ -8073,7 +8073,7 @@ var doc = `{
"ApiKeyAuth": []
}
],
"description": "export workflow",
"description": "export workflow as CSV or Excel",
"tags": [
"workflow"
],
Expand Down Expand Up @@ -8161,6 +8161,16 @@ var doc = `{
"description": "fuzzy matching subject/workflow_id/desc",
"name": "fuzzy_keyword",
"in": "query"
},
{
"enum": [
"csv",
"excel"
],
"type": "string",
"description": "export format",
"name": "export_format",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -11740,7 +11750,7 @@ var doc = `{
"ApiKeyAuth": []
}
],
"description": "export sql manage",
"description": "export sql manage as CSV or Excel",
"tags": [
"SqlManage"
],
Expand Down Expand Up @@ -11878,6 +11888,16 @@ var doc = `{
"description": "sort order",
"name": "sort_order",
"in": "query"
},
{
"enum": [
"csv",
"excel"
],
"type": "string",
"description": "export format",
"name": "export_format",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -15855,6 +15875,15 @@ var doc = `{
"v1.GetAuditPlanSQLExportReqV1": {
"type": "object",
"properties": {
"export_format": {
"description": "导出格式:csv 或 excel,默认为 excel",
"type": "string",
"enum": [
"csv",
"excel"
],
"example": "excel"
},
"filter_list": {
"type": "array",
"items": {
Expand Down
37 changes: 33 additions & 4 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3750,11 +3750,11 @@
"ApiKeyAuth": []
}
],
"description": "export audit plan SQL report as CSV",
"description": "export audit plan SQL report as CSV or Excel",
"tags": [
"instance_audit_plan"
],
"summary": "导出指定扫描任务的 SQL CSV 列表",
"summary": "导出指定扫描任务的 SQL 列表",
"operationId": "getInstanceAuditPlanSQLExportV1",
"parameters": [
{
Expand Down Expand Up @@ -8057,7 +8057,7 @@
"ApiKeyAuth": []
}
],
"description": "export workflow",
"description": "export workflow as CSV or Excel",
"tags": [
"workflow"
],
Expand Down Expand Up @@ -8145,6 +8145,16 @@
"description": "fuzzy matching subject/workflow_id/desc",
"name": "fuzzy_keyword",
"in": "query"
},
{
"enum": [
"csv",
"excel"
],
"type": "string",
"description": "export format",
"name": "export_format",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -11724,7 +11734,7 @@
"ApiKeyAuth": []
}
],
"description": "export sql manage",
"description": "export sql manage as CSV or Excel",
"tags": [
"SqlManage"
],
Expand Down Expand Up @@ -11862,6 +11872,16 @@
"description": "sort order",
"name": "sort_order",
"in": "query"
},
{
"enum": [
"csv",
"excel"
],
"type": "string",
"description": "export format",
"name": "export_format",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -15839,6 +15859,15 @@
"v1.GetAuditPlanSQLExportReqV1": {
"type": "object",
"properties": {
"export_format": {
"description": "导出格式:csv 或 excel,默认为 excel",
"type": "string",
"enum": [
"csv",
"excel"
],
"example": "excel"
},
"filter_list": {
"type": "array",
"items": {
Expand Down
Loading
Loading