aboutsummaryrefslogtreecommitdiffstats
path: root/internal/build/azure.go
diff options
context:
space:
mode:
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
+}