Skip to content

Commit

Permalink
add support for zipped xlsx report
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmahanth committed Nov 7, 2024
1 parent 0375a5c commit 932a53d
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 199 deletions.
5 changes: 5 additions & 0 deletions deepfence_utils/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,9 @@ func ComputeChecksumForFile(filePath string) (string, error) {
}

func ZipDir(sourceDir string, baseZipPath string, outputZip string) error {

log.Debug().Msgf("add files from directory %s to zip", sourceDir)

archive, err := os.Create(outputZip)
if err != nil {
return err
Expand All @@ -809,6 +812,8 @@ func ZipDir(sourceDir string, baseZipPath string, outputZip string) error {
}
defer file.Close()

log.Debug().Msgf("adding file to zip %s", info.Name())

f, err := zw.Create(filepath.Join(baseZipPath, info.Name()))
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions deepfence_worker/tasks/reports/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package reports
import (
"context"
_ "embed"
"os"
"path/filepath"
"strconv"
"time"

Expand Down Expand Up @@ -214,3 +216,20 @@ func generatePDF(ctx context.Context, params utils.ReportParams) (string, error)

return document, nil
}

func writeReportToFile(dir string, fileName string, data []byte) (string, error) {

// make sure directory exists
os.MkdirAll(dir, os.ModePerm)

out := filepath.Join(dir, fileName)

log.Debug().Msgf("write report to path %s", out)

err := os.WriteFile(out, data, os.ModePerm)
if err != nil {
return "", err
}

return out, nil
}
21 changes: 1 addition & 20 deletions deepfence_worker/tasks/reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"

"github.com/deepfence/ThreatMapper/deepfence_utils/directory"
"github.com/deepfence/ThreatMapper/deepfence_utils/log"
"github.com/deepfence/ThreatMapper/deepfence_utils/telemetry"
"github.com/deepfence/ThreatMapper/deepfence_utils/utils"
sdkUtils "github.com/deepfence/ThreatMapper/deepfence_utils/utils"
"github.com/hibiken/asynq"
"github.com/minio/minio-go/v7"
Expand Down Expand Up @@ -51,24 +49,7 @@ func reportFileName(params sdkUtils.ReportParams) string {
return strings.Join(list, "_") + fileExt(sdkUtils.ReportType(params.ReportType))
}

func writeReportToFile(dir string, fileName string, data []byte) (string, error) {

// make sure directory exists
os.MkdirAll(dir, os.ModePerm)

out := filepath.Join(dir, fileName)

log.Debug().Msgf("write report to path %s", out)

err := os.WriteFile(out, data, os.ModePerm)
if err != nil {
return "", err
}

return out, nil
}

func tempReportFile(params utils.ReportParams) string {
func tempReportFile(params sdkUtils.ReportParams) string {
return strings.Join(
[]string{
"report",
Expand Down
Loading

0 comments on commit 932a53d

Please sign in to comment.