This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
storage.go
49 lines (40 loc) · 1.51 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package armhelpers
import (
"github.com/Azure/azure-sdk-for-go/arm/storage"
azStorage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest/to"
)
// AzureStorageClient implements the StorageClient interface and wraps the Azure storage client.
type AzureStorageClient struct {
client *azStorage.Client
}
// GetStorageClient returns an authenticated client for the specified account.
func (az *AzureClient) GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error) {
keys, err := az.getStorageKeys(resourceGroup, accountName)
if err != nil {
return nil, err
}
client, err := azStorage.NewBasicClientOnSovereignCloud(accountName, to.String(keys[0].Value), az.environment)
if err != nil {
return nil, err
}
return &AzureStorageClient{
client: &client,
}, nil
}
func (az *AzureClient) getStorageKeys(resourceGroup, accountName string) ([]storage.AccountKey, error) {
storageKeysResult, err := az.storageAccountsClient.ListKeys(resourceGroup, accountName)
if err != nil {
return nil, err
}
return *storageKeysResult.Keys, nil
}
// DeleteBlob deletes the specified blob
// TODO(colemick): why doesn't SDK give a way to just delete a blob by URI?
// it's what it ends up doing internally anyway...
func (as *AzureStorageClient) DeleteBlob(vhdContainer, vhdBlob string) error {
bs := as.client.GetBlobService()
containerRef := bs.GetContainerReference(vhdContainer)
blobRef := containerRef.GetBlobReference(vhdBlob)
return blobRef.Delete(&azStorage.DeleteBlobOptions{})
}