aboutsummaryrefslogtreecommitdiffstats
path: root/internal/build/azure.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-04-06 18:53:33 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-06 18:53:33 +0800
commitc76ad944920300be58446ddd1a50c8d693957774 (patch)
treeec9aed051e82deb3c479ab1b7ab50aa2c07d9efb /internal/build/azure.go
parent3d8de95f999de6f52f0c1605eb2913278f1d87d2 (diff)
downloaddexon-c76ad944920300be58446ddd1a50c8d693957774.tar
dexon-c76ad944920300be58446ddd1a50c8d693957774.tar.gz
dexon-c76ad944920300be58446ddd1a50c8d693957774.tar.bz2
dexon-c76ad944920300be58446ddd1a50c8d693957774.tar.lz
dexon-c76ad944920300be58446ddd1a50c8d693957774.tar.xz
dexon-c76ad944920300be58446ddd1a50c8d693957774.tar.zst
dexon-c76ad944920300be58446ddd1a50c8d693957774.zip
.travis, build: autodelete old unstable archives (#13867)
This commit adds a build step to travis to auto-delete unstable archives older than 14 days (our regular release schedule) from Azure via ci.go purge. The commit also pulls in the latest Azure storage code, also switching over from the old import path (github.com/Azure/azure-sdk-for-go) to the new split one (github.com/Azure/azure-storage-go).
Diffstat (limited to 'internal/build/azure.go')
-rw-r--r--internal/build/azure.go50
1 files changed, 48 insertions, 2 deletions
diff --git a/internal/build/azure.go b/internal/build/azure.go
index 32f535558..2081a9a0b 100644
--- a/internal/build/azure.go
+++ b/internal/build/azure.go
@@ -20,7 +20,7 @@ import (
"fmt"
"os"
- "github.com/Azure/azure-sdk-for-go/storage"
+ storage "github.com/Azure/azure-storage-go"
)
// AzureBlobstoreConfig is an authentication and configuration struct containing
@@ -42,7 +42,6 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name)
return nil
}
-
// Create an authenticated client against the Azure cloud
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
if err != nil {
@@ -63,3 +62,50 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
}
return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil)
}
+
+// 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()
+
+ // List all the blobs from the container and return them
+ container := client.GetContainerReference(config.Container)
+
+ blobs, err := container.ListBlobs(storage.ListBlobsParameters{
+ 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
+}
+
+// AzureBlobstoreDelete iterates over a list of files to delete and removes them
+// from the blobstore.
+func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) 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)
+ }
+ 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()
+
+ // Iterate over the blobs and delete them
+ for _, blob := range blobs {
+ if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil {
+ return err
+ }
+ }
+ return nil
+}