@@ -71,26 +71,35 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
7171
7272// AzureBlobstoreList lists all the files contained within an azure blobstore.
7373func AzureBlobstoreList (config AzureBlobstoreConfig ) ([]azblob.BlobItem , error ) {
74- credential , err := azblob .NewSharedKeyCredential (config .Account , config .Token )
75- if err != nil {
76- return nil , err
74+ credential := azblob .NewAnonymousCredential ()
75+ if len (config .Token ) > 0 {
76+ c , err := azblob .NewSharedKeyCredential (config .Account , config .Token )
77+ if err != nil {
78+ return nil , err
79+ }
80+ credential = c
7781 }
78-
7982 pipeline := azblob .NewPipeline (credential , azblob.PipelineOptions {})
8083
8184 u , _ := url .Parse (fmt .Sprintf ("https://%s.blob.core.windows.net" , config .Account ))
8285 service := azblob .NewServiceURL (* u , pipeline )
8386
87+ var allBlobs []azblob.BlobItem
8488 // List all the blobs from the container and return them
8589 container := service .NewContainerURL (config .Container )
90+ nextMarker := azblob.Marker {}
91+ for nextMarker .NotDone () {
92+ res , err := container .ListBlobsFlatSegment (context .Background (), nextMarker , azblob.ListBlobsSegmentOptions {
93+ MaxResults : 5000 , // The server only gives max 5K items
94+ })
95+ if err != nil {
96+ return nil , err
97+ }
98+ allBlobs = append (allBlobs , res .Segment .BlobItems ... )
99+ nextMarker = res .NextMarker
86100
87- res , err := container .ListBlobsFlatSegment (context .Background (), azblob.Marker {}, azblob.ListBlobsSegmentOptions {
88- MaxResults : 1024 * 1024 * 1024 , // Yes, fetch all of them
89- })
90- if err != nil {
91- return nil , err
92101 }
93- return res . Segment . BlobItems , nil
102+ return allBlobs , nil
94103}
95104
96105// AzureBlobstoreDelete iterates over a list of files to delete and removes them
@@ -121,6 +130,7 @@ func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []azblob.BlobItem)
121130 if _ , err := blockblob .Delete (context .Background (), azblob .DeleteSnapshotsOptionInclude , azblob.BlobAccessConditions {}); err != nil {
122131 return err
123132 }
133+ fmt .Printf ("deleted %s (%s)\n " , blob .Name , blob .Properties .LastModified )
124134 }
125135 return nil
126136}
0 commit comments