From 3fab4697a70fec942479f256a28bc7123c194ea4 Mon Sep 17 00:00:00 2001 From: Abhisek Datta Date: Thu, 2 Jan 2025 18:50:37 +0530 Subject: [PATCH] chore: Render malysis report URL in console (#302) --- cmd/inspect/malware.go | 15 +++++++++++++-- pkg/malysis/url.go | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 pkg/malysis/url.go diff --git a/cmd/inspect/malware.go b/cmd/inspect/malware.go index a23a6596..0fa39891 100644 --- a/cmd/inspect/malware.go +++ b/cmd/inspect/malware.go @@ -16,6 +16,7 @@ import ( "github.com/safedep/dry/utils" "github.com/safedep/vet/internal/auth" "github.com/safedep/vet/internal/ui" + "github.com/safedep/vet/pkg/malysis" "github.com/spf13/cobra" ) @@ -120,7 +121,8 @@ func executeMalwareAnalysis() error { ui.PrintError("Failed to render malware analysis report in JSON format: %v", err) } - return renderMalwareAnalysisReport(malwareAnalysisPackageUrl, report) + return renderMalwareAnalysisReport(malwareAnalysisPackageUrl, + analyzePackageResponse.GetAnalysisId(), report) } func renderToJSON(report *malysisv1pb.Report) error { @@ -136,7 +138,7 @@ func renderToJSON(report *malysisv1pb.Report) error { return os.WriteFile(malwareAnalysisReportJSON, []byte(data), 0644) } -func renderMalwareAnalysisReport(purl string, report *malysisv1pb.Report) error { +func renderMalwareAnalysisReport(purl string, analysisId string, report *malysisv1pb.Report) error { ui.PrintMsg("Malware analysis report for package: %s", purl) tbl := table.NewWriter() @@ -156,5 +158,14 @@ func renderMalwareAnalysisReport(purl string, report *malysisv1pb.Report) error tbl.AppendRow(table.Row{purl, status, confidence}) tbl.Render() + fmt.Println() + fmt.Println(text.FgHiYellow.Sprintf("** The full report is available at: %s", + reportVisualizationUrl(analysisId))) + fmt.Println() + return nil } + +func reportVisualizationUrl(analysisId string) string { + return malysis.ReportURL(analysisId) +} diff --git a/pkg/malysis/url.go b/pkg/malysis/url.go new file mode 100644 index 00000000..d28c8a78 --- /dev/null +++ b/pkg/malysis/url.go @@ -0,0 +1,7 @@ +package malysis + +import "fmt" + +func ReportURL(reportId string) string { + return fmt.Sprintf("https://platform.safedep.io/community/malysis/%s", reportId) +}