Explorar el Código

fix JSON issue

Sean Holcomb hace 5 años
padre
commit
7860ecc9d5
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9 1
      pkg/cloud/azureprovider.go

+ 9 - 1
pkg/cloud/azureprovider.go

@@ -984,7 +984,7 @@ func parseCSV(reader *csv.Reader, start, end time.Time, oocAllocs map[string]*Ou
 		}
 
 		itemTags := make(map[string]string)
-		itemTagJson := record[headerMap["Tags"]]
+		itemTagJson := makeValidJSON(record[headerMap["Tags"]])
 		if itemTagJson != "" {
 			err = json.Unmarshal([]byte(itemTagJson), &itemTags)
 			if err != nil {
@@ -1033,6 +1033,14 @@ func createHeaderMap(headers []string) map[string]int {
 	return headerMap
 }
 
+func makeValidJSON(jsonString string) string {
+	if jsonString == "" || (jsonString[0] == '{' && jsonString[len(jsonString)-1] == '}') {
+		return jsonString
+	}
+	return fmt.Sprintf("{%v}", jsonString)
+}
+
+
 // UsageDateTime only contains date information and not time because of this filtering usageDate time is inclusive on start and exclusive on end
 func isValidUsageDateTime(start, end, usageDateTime time.Time) bool {
 	return (usageDateTime.After(start) || usageDateTime.Equal(start)) && usageDateTime.Before(end)