1717package build
1818
1919import (
20+ "context"
2021 "fmt"
22+ "net/url"
2123 "os"
2224
23- storage "github.com/Azure/azure-storage-go "
25+ "github.com/Azure/azure-storage-blob-go/2018-03-28/azblob "
2426)
2527
2628// AzureBlobstoreConfig is an authentication and configuration struct containing
@@ -43,11 +45,14 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
4345 return nil
4446 }
4547 // Create an authenticated client against the Azure cloud
46- rawClient , err := storage .NewBasicClient (config .Account , config .Token )
47- if err != nil {
48- return err
49- }
50- client := rawClient .GetBlobService ()
48+ credential := azblob .NewSharedKeyCredential (config .Account , config .Token )
49+ pipeline := azblob .NewPipeline (credential , azblob.PipelineOptions {})
50+
51+ u , _ := url .Parse (fmt .Sprintf ("https://%s.blob.core.windows.net" , config .Account ))
52+ service := azblob .NewServiceURL (* u , pipeline )
53+
54+ container := service .NewContainerURL (config .Container )
55+ blockblob := container .NewBlockBlobURL (name )
5156
5257 // Stream the file to upload into the designated blobstore container
5358 in , err := os .Open (path )
@@ -56,54 +61,52 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
5661 }
5762 defer in .Close ()
5863
59- info , err := in .Stat ()
60- if err != nil {
61- return err
62- }
63- return client .CreateBlockBlobFromReader (config .Container , name , uint64 (info .Size ()), in , nil )
64+ _ , err = blockblob .Upload (context .Background (), in , azblob.BlobHTTPHeaders {}, azblob.Metadata {}, azblob.BlobAccessConditions {})
65+ return err
6466}
6567
6668// AzureBlobstoreList lists all the files contained within an azure blobstore.
67- func AzureBlobstoreList (config AzureBlobstoreConfig ) ([]storage.Blob , error ) {
68- // Create an authenticated client against the Azure cloud
69- rawClient , err := storage .NewBasicClient (config .Account , config .Token )
70- if err != nil {
71- return nil , err
72- }
73- client := rawClient .GetBlobService ()
69+ func AzureBlobstoreList (config AzureBlobstoreConfig ) ([]azblob.BlobItem , error ) {
70+ credential := azblob .NewSharedKeyCredential (config .Account , config .Token )
71+ pipeline := azblob .NewPipeline (credential , azblob.PipelineOptions {})
72+
73+ u , _ := url .Parse (fmt .Sprintf ("https://%s.blob.core.windows.net" , config .Account ))
74+ service := azblob .NewServiceURL (* u , pipeline )
7475
7576 // List all the blobs from the container and return them
76- container := client . GetContainerReference (config .Container )
77+ container := service . NewContainerURL (config .Container )
7778
78- blobs , err := container .ListBlobs (storage. ListBlobsParameters {
79+ res , err := container .ListBlobsFlatSegment ( context . Background (), azblob. Marker {}, azblob. ListBlobsSegmentOptions {
7980 MaxResults : 1024 * 1024 * 1024 , // Yes, fetch all of them
80- Timeout : 3600 , // Yes, wait for all of them
8181 })
8282 if err != nil {
8383 return nil , err
8484 }
85- return blobs . Blobs , nil
85+ return res . Segment . BlobItems , nil
8686}
8787
8888// AzureBlobstoreDelete iterates over a list of files to delete and removes them
8989// from the blobstore.
90- func AzureBlobstoreDelete (config AzureBlobstoreConfig , blobs []storage. Blob ) error {
90+ func AzureBlobstoreDelete (config AzureBlobstoreConfig , blobs []azblob. BlobItem ) error {
9191 if * DryRunFlag {
9292 for _ , blob := range blobs {
9393 fmt .Printf ("would delete %s (%s) from %s/%s\n " , blob .Name , blob .Properties .LastModified , config .Account , config .Container )
9494 }
9595 return nil
9696 }
9797 // Create an authenticated client against the Azure cloud
98- rawClient , err := storage .NewBasicClient (config .Account , config .Token )
99- if err != nil {
100- return err
101- }
102- client := rawClient .GetBlobService ()
98+ credential := azblob .NewSharedKeyCredential (config .Account , config .Token )
99+ pipeline := azblob .NewPipeline (credential , azblob.PipelineOptions {})
100+
101+ u , _ := url .Parse (fmt .Sprintf ("https://%s.blob.core.windows.net" , config .Account ))
102+ service := azblob .NewServiceURL (* u , pipeline )
103+
104+ container := service .NewContainerURL (config .Container )
103105
104106 // Iterate over the blobs and delete them
105107 for _ , blob := range blobs {
106- if err := client .DeleteBlob (config .Container , blob .Name , nil ); err != nil {
108+ blockblob := container .NewBlockBlobURL (blob .Name )
109+ if _ , err := blockblob .Delete (context .Background (), azblob .DeleteSnapshotsOptionInclude , azblob.BlobAccessConditions {}); err != nil {
107110 return err
108111 }
109112 }
0 commit comments