aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-07-27 00:59:46 +0800
committerGitHub <noreply@github.com>2018-07-27 00:59:46 +0800
commit93c0f1715d1ce6e590811a659d20f0e80277ba6a (patch)
tree39ac2bdba86fd080a717ff2926f615d5d21ee3ce /internal
parentd9575e92fc6e52ba18267410fcd2426d5a148cbc (diff)
parent6b232ce3252c6823ac84cd3d2256340f981cd387 (diff)
downloadgo-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar.gz
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar.bz2
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar.lz
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar.xz
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.tar.zst
go-tangerine-93c0f1715d1ce6e590811a659d20f0e80277ba6a.zip
Merge pull request #17245 from karalabe/azure-deps-fixups
internal, vendor: update Azure blobstore API
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
}
}