Skip to content

Commit

Permalink
feat: service and metadata fields add to CSV export (#1360)
Browse files Browse the repository at this point in the history
Add to metadata and service column to export csv
  • Loading branch information
Mahiro-T authored Mar 4, 2024
1 parent 23cc666 commit 06b21f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions handlers/csv_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func respondWithCSVDownload(resources []models.Resource, c *gin.Context) {
fw := bufio.NewWriter(file)
csvWriter := csv.NewWriter(fw)

header := []string{"id", "provider", "account", "name", "region", "tags", "cost"}
header := []string{"id", "provider", "account", "name", "service", "region", "tags", "cost", "metadata"}
if err := csvWriter.Write(header); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "could not write csv"})
return
Expand All @@ -256,9 +256,13 @@ func respondWithCSVDownload(resources []models.Resource, c *gin.Context) {
if err != nil {
log.Fatalf("Could not marshal tags")
}
metadata, err := json.Marshal(record.Metadata)
if err != nil {
log.Fatalf("Could not marshal metadata")
}

row := []string{
record.ResourceId, record.Provider, record.Account, record.Name, record.Region, string(tags), fmt.Sprintf("%2.f", record.Cost),
record.ResourceId, record.Provider, record.Account, record.Name, record.Service, record.Region, string(tags), fmt.Sprintf("%2.f", record.Cost), string(metadata),
}
if err := csvWriter.Write(row); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "could not write csv"})
Expand Down

0 comments on commit 06b21f8

Please sign in to comment.