Forráskód Böngészése

Skip the first two lines of the pricesheet

They don't have commas, so we can't skip them with the CSV reader
because the field count won't match. Skip them using the buffered
reader first.

Signed-off-by: Christian Muirhead <christian.muirhead@microsoft.com>
Christian Muirhead 3 éve
szülő
commit
23518c0d7f
1 módosított fájl, 9 hozzáadás és 5 törlés
  1. 9 5
      pkg/cloud/azureprovider.go

+ 9 - 5
pkg/cloud/azureprovider.go

@@ -1115,16 +1115,20 @@ func (d *pricesheetDownloader) readPricesheet(ctx context.Context, data io.Reade
 	if !ok {
 		buf = bufio.NewReader(data)
 	}
-	reader := csv.NewReader(buf)
-	reader.ReuseRecord = true
 
-	// Skip the two header rows.
+	// The CSV file starts with two lines before the header without
+	// commas (so different numbers of fields as far as the CSV parser
+	// is concerned). Skip them before making the CSV reader so we
+	// still get the benefit of the row length checks after the
+	// header.
 	for i := 0; i < 2; i++ {
-		_, err := reader.Read()
+		_, err := buf.ReadBytes('\n')
 		if err != nil {
-			return nil, fmt.Errorf("skipping row %d: %w", i, err)
+			return nil, fmt.Errorf("skipping preamble line %d: %w", i, err)
 		}
 	}
+	reader := csv.NewReader(buf)
+	reader.ReuseRecord = true
 
 	header, err := reader.Read()
 	if err != nil {