Skip to content

Commit 6b232ce

Browse files
committed
internal, vendor: update Azure blobstore API
1 parent 7abedf9 commit 6b232ce

99 files changed

Lines changed: 14834 additions & 8143 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎build/ci.go‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,23 +1018,14 @@ func doPurge(cmdline []string) {
10181018
}
10191019
for i := 0; i < len(blobs); i++ {
10201020
for j := i + 1; j < len(blobs); j++ {
1021-
iTime, err := time.Parse(time.RFC1123, blobs[i].Properties.LastModified)
1022-
if err != nil {
1023-
log.Fatal(err)
1024-
}
1025-
jTime, err := time.Parse(time.RFC1123, blobs[j].Properties.LastModified)
1026-
if err != nil {
1027-
log.Fatal(err)
1028-
}
1029-
if iTime.After(jTime) {
1021+
if blobs[i].Properties.LastModified.After(blobs[j].Properties.LastModified) {
10301022
blobs[i], blobs[j] = blobs[j], blobs[i]
10311023
}
10321024
}
10331025
}
10341026
// Filter out all archives more recent that the given threshold
10351027
for i, blob := range blobs {
1036-
timestamp, _ := time.Parse(time.RFC1123, blob.Properties.LastModified)
1037-
if time.Since(timestamp) < time.Duration(*limit)*24*time.Hour {
1028+
if time.Since(blob.Properties.LastModified) < time.Duration(*limit)*24*time.Hour {
10381029
blobs = blobs[:i]
10391030
break
10401031
}

‎internal/build/azure.go‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package build
1818

1919
import (
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
}

vendor/github.com/Azure/azure-storage-go/LICENSE renamed to vendor/github.com/Azure/azure-pipeline-go/LICENSE

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/Azure/azure-pipeline-go/pipeline/core.go‎

Lines changed: 255 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)