Parcourir la source

Review changes

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb il y a 2 ans
Parent
commit
67ee7ba1d5
2 fichiers modifiés avec 12 ajouts et 11 suppressions
  1. 8 5
      pkg/cloud/azure/storagebillingparser.go
  2. 4 6
      pkg/cloud/azure/storageconnection.go

+ 8 - 5
pkg/cloud/azure/storagebillingparser.go

@@ -125,13 +125,16 @@ func (asbp *AzureStorageBillingParser) getMostRecentBlobs(start, end time.Time,
 
 		// Using the list of months strings find the most resent blob for each month in the range
 		for _, blobInfo := range resp.Segment.BlobItems {
+			if blobInfo.Name == nil {
+				continue
+			}
+			// If Container Path configuration exists, check if it is in the blobs name
+			if asbp.Path != "" && !strings.Contains(*blobInfo.Name, asbp.Path) {
+				continue
+			}
 			for _, month := range monthStrs {
 				if strings.Contains(*blobInfo.Name, month) {
-					// If Container Path configuration exists, check if it is in the blobs name
-					if asbp.Path != "" && !strings.Contains(*blobInfo.Name, asbp.Path) {
-						continue
-					}
-
+					// check if blob is the newest seen for this month
 					if prevBlob, ok := mostResentBlobs[month]; ok {
 						if prevBlob.Properties.CreationTime.After(*blobInfo.Properties.CreationTime) {
 							continue

+ 4 - 6
pkg/cloud/azure/storageconnection.go

@@ -3,6 +3,7 @@ package azure
 import (
 	"bytes"
 	"context"
+	"fmt"
 	"strings"
 
 	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
@@ -49,22 +50,19 @@ func (sc *StorageConnection) DownloadBlob(blobName string, client *azblob.Client
 
 	downloadResponse, err := client.DownloadStream(ctx, sc.Container, blobName, nil)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Azure: DownloadBlob: failed to download %w", err)
 	}
 	// NOTE: automatically retries are performed if the connection fails
 	retryReader := downloadResponse.NewRetryReader(ctx, &azblob.RetryReaderOptions{})
+	defer retryReader.Close()
 
 	// read the body into a buffer
 	downloadedData := bytes.Buffer{}
 
 	_, err = downloadedData.ReadFrom(retryReader)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Azure: DownloadBlob: failed to read downloaded data %w", err)
 	}
 
-	err = retryReader.Close()
-	if err != nil {
-		return nil, err
-	}
 	return downloadedData.Bytes(), nil
 }