@@ -71,26 +71,35 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
71
71
72
72
// AzureBlobstoreList lists all the files contained within an azure blobstore.
73
73
func 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
77
81
}
78
-
79
82
pipeline := azblob .NewPipeline (credential , azblob.PipelineOptions {})
80
83
81
84
u , _ := url .Parse (fmt .Sprintf ("https://%s.blob.core.windows.net" , config .Account ))
82
85
service := azblob .NewServiceURL (* u , pipeline )
83
86
87
+ var allBlobs []azblob.BlobItem
84
88
// List all the blobs from the container and return them
85
89
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
86
100
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
92
101
}
93
- return res . Segment . BlobItems , nil
102
+ return allBlobs , nil
94
103
}
95
104
96
105
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
@@ -121,6 +130,7 @@ func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []azblob.BlobItem)
121
130
if _ , err := blockblob .Delete (context .Background (), azblob .DeleteSnapshotsOptionInclude , azblob.BlobAccessConditions {}); err != nil {
122
131
return err
123
132
}
133
+ fmt .Printf ("deleted %s (%s)\n " , blob .Name , blob .Properties .LastModified )
124
134
}
125
135
return nil
126
136
}
0 commit comments