-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
azure_blob.go
32 lines (25 loc) · 1.1 KB
/
azure_blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package azure
import (
"context"
"github.com/Azure/azure-storage-blob-go/azblob"
kedav1alpha1 "github.com/kedacore/keda/v2/api/v1alpha1"
"github.com/kedacore/keda/v2/pkg/util"
)
// GetAzureBlobListLength returns the count of the blobs in blob container in int
func GetAzureBlobListLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.PodIdentityProvider, connectionString, blobContainerName string, accountName string, blobDelimiter string, blobPrefix string) (int, error) {
credential, endpoint, err := ParseAzureStorageBlobConnection(httpClient, podIdentity, connectionString, accountName)
if err != nil {
return -1, err
}
listBlobsSegmentOptions := azblob.ListBlobsSegmentOptions{
Prefix: blobPrefix,
}
p := azblob.NewPipeline(credential, azblob.PipelineOptions{})
serviceURL := azblob.NewServiceURL(*endpoint, p)
containerURL := serviceURL.NewContainerURL(blobContainerName)
props, err := containerURL.ListBlobsHierarchySegment(ctx, azblob.Marker{}, blobDelimiter, listBlobsSegmentOptions)
if err != nil {
return -1, err
}
return len(props.Segment.BlobItems), nil
}