go.mod, internal/build: update Azure dependencies (#28329)
This commit is contained in:
+21
-21
@@ -22,6 +22,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
|
||||
)
|
||||
|
||||
// AzureBlobstoreConfig is an authentication and configuration struct containing
|
||||
@@ -48,8 +49,8 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u := fmt.Sprintf("https://%s.blob.core.windows.net/%s", config.Account, config.Container)
|
||||
container, err := azblob.NewContainerClientWithSharedKey(u, credential, nil)
|
||||
a := fmt.Sprintf("https://%s.blob.core.windows.net/", config.Account)
|
||||
client, err := azblob.NewClientWithSharedKeyCredential(a, credential, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -60,38 +61,38 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
blockblob := container.NewBlockBlobClient(name)
|
||||
_, err = blockblob.Upload(context.Background(), in, nil)
|
||||
_, err = client.UploadFile(context.Background(), config.Container, name, in, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// AzureBlobstoreList lists all the files contained within an azure blobstore.
|
||||
func AzureBlobstoreList(config AzureBlobstoreConfig) ([]*azblob.BlobItemInternal, error) {
|
||||
func AzureBlobstoreList(config AzureBlobstoreConfig) ([]*container.BlobItem, error) {
|
||||
// Create an authenticated client against the Azure cloud
|
||||
credential, err := azblob.NewSharedKeyCredential(config.Account, config.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u := fmt.Sprintf("https://%s.blob.core.windows.net/%s", config.Account, config.Container)
|
||||
container, err := azblob.NewContainerClientWithSharedKey(u, credential, nil)
|
||||
a := fmt.Sprintf("https://%s.blob.core.windows.net/", config.Account)
|
||||
client, err := azblob.NewClientWithSharedKeyCredential(a, credential, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var maxResults int32 = 5000
|
||||
pager := container.ListBlobsFlat(&azblob.ContainerListBlobFlatSegmentOptions{
|
||||
Maxresults: &maxResults,
|
||||
})
|
||||
var allBlobs []*azblob.BlobItemInternal
|
||||
for pager.NextPage(context.Background()) {
|
||||
res := pager.PageResponse()
|
||||
allBlobs = append(allBlobs, res.ContainerListBlobFlatSegmentResult.Segment.BlobItems...)
|
||||
pager := client.NewListBlobsFlatPager(config.Container, nil)
|
||||
|
||||
var blobs []*container.BlobItem
|
||||
for pager.More() {
|
||||
page, err := pager.NextPage(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blobs = append(blobs, page.Segment.BlobItems...)
|
||||
}
|
||||
return allBlobs, pager.Err()
|
||||
return blobs, nil
|
||||
}
|
||||
|
||||
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
|
||||
// from the blobstore.
|
||||
func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []*azblob.BlobItemInternal) error {
|
||||
func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []*container.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)
|
||||
@@ -103,15 +104,14 @@ func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []*azblob.BlobItemI
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u := fmt.Sprintf("https://%s.blob.core.windows.net/%s", config.Account, config.Container)
|
||||
container, err := azblob.NewContainerClientWithSharedKey(u, credential, nil)
|
||||
a := fmt.Sprintf("https://%s.blob.core.windows.net/", config.Account)
|
||||
client, err := azblob.NewClientWithSharedKeyCredential(a, credential, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Iterate over the blobs and delete them
|
||||
for _, blob := range blobs {
|
||||
blockblob := container.NewBlockBlobClient(*blob.Name)
|
||||
if _, err := blockblob.Delete(context.Background(), &azblob.DeleteBlobOptions{}); err != nil {
|
||||
if _, err := client.DeleteBlob(context.Background(), config.Container, *blob.Name, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("deleted %s (%s)\n", *blob.Name, blob.Properties.LastModified)
|
||||
|
||||
Reference in New Issue
Block a user