aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/build/azure.go61
1 files changed, 32 insertions, 29 deletions
diff --git a/internal/build/azure.go b/internal/build/azure.go
index 2081a9a0b..086dff2c4 100644
--- a/internal/build/azure.go
+++ b/internal/build/azure.go
@@ -17,10 +17,12 @@
package build
import (
+ "context"
"fmt"
+ "net/url"
"os"
- storage "github.com/Azure/azure-storage-go"
+ "github.com/Azure/azure-storage-blob-go/2018-03-28/azblob"
)
// AzureBlobstoreConfig is an authentication and configuration struct containing
@@ -43,11 +45,14 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
return nil
}
// Create an authenticated client against the Azure cloud
- rawClient, err := storage.NewBasicClient(config.Account, config.Token)
- if err != nil {
- return err
- }
- client := rawClient.GetBlobService()
+ credential := azblob.NewSharedKeyCredential(config.Account, config.Token)
+ pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{})
+
+ u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", config.Account))
+ service := azblob.NewServiceURL(*u, pipeline)
+
+ container := service.NewContainerURL(config.Container)
+ blockblob := container.NewBlockBlobURL(name)
// Stream the file to upload into the designated blobstore container
in, err := os.Open(path)
@@ -56,38 +61,33 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
}
defer in.Close()
- info, err := in.Stat()
- if err != nil {
- return err
- }
- return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil)
+ _, err = blockblob.Upload(context.Background(), in, azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
+ return err
}
// AzureBlobstoreList lists all the files contained within an azure blobstore.
-func AzureBlobstoreList(config AzureBlobstoreConfig) ([]storage.Blob, error) {
- // Create an authenticated client against the Azure cloud
- rawClient, err := storage.NewBasicClient(config.Account, config.Token)
- if err != nil {
- return nil, err
- }
- client := rawClient.GetBlobService()
+func AzureBlobstoreList(config AzureBlobstoreConfig) ([]azblob.BlobItem, error) {
+ credential := azblob.NewSharedKeyCredential(config.Account, config.Token)
+ pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{})
+
+ u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", config.Account))
+ service := azblob.NewServiceURL(*u, pipeline)
// List all the blobs from the container and return them
- container := client.GetContainerReference(config.Container)
+ container := service.NewContainerURL(config.Container)
- blobs, err := container.ListBlobs(storage.ListBlobsParameters{
+ res, err := container.ListBlobsFlatSegment(context.Background(), azblob.Marker{}, azblob.ListBlobsSegmentOptions{
MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them
- Timeout: 3600, // Yes, wait for all of them
})
if err != nil {
return nil, err
}
- return blobs.Blobs, nil
+ return res.Segment.BlobItems, nil
}
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
// from the blobstore.
-func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) error {
+func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []azblob.BlobItem) error {
if *DryRunFlag {
for _, blob := range blobs {
fmt.Printf("would delete %s (%s) from %s/%s\n", blob.Name, blob.Properties.LastModified, config.Account, config.Container)
@@ -95,15 +95,18 @@ func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) err
return nil
}
// Create an authenticated client against the Azure cloud
- rawClient, err := storage.NewBasicClient(config.Account, config.Token)
- if err != nil {
- return err
- }
- client := rawClient.GetBlobService()
+ credential := azblob.NewSharedKeyCredential(config.Account, config.Token)
+ pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{})
+
+ u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", config.Account))
+ service := azblob.NewServiceURL(*u, pipeline)
+
+ container := service.NewContainerURL(config.Container)
// Iterate over the blobs and delete them
for _, blob := range blobs {
- if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil {
+ blockblob := container.NewBlockBlobURL(blob.Name)
+ if _, err := blockblob.Delete(context.Background(), azblob.DeleteSnapshotsOptionInclude, azblob.BlobAccessConditions{}); err != nil {
return err
}
}