Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(general): [0.16.0] Add a new function to create the Azure backend storage with the provi… #12

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions repo/blob/azure/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package azure

import (
"context"
"fmt"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/kopia/kopia/internal/clock"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/blob/retrying"
"github.com/pkg/errors"
)

// NewWithClient creates new Azure backend storage with the specified client
func NewWithClient(ctx context.Context, opt *Options, client *azblob.Client) (blob.Storage, error) {
raw := &azStorage{
Options: *opt,
container: opt.Container,
service: client,
}

az := retrying.NewWrapper(raw)

// verify Azure connection is functional by listing blobs in a bucket, which will fail if the container
// does not exist. We list with a prefix that will not exist, to avoid iterating through any objects.
nonExistentPrefix := fmt.Sprintf("kopia-azure-storage-initializing-%v", clock.Now().UnixNano())
if err := raw.ListBlobs(ctx, blob.ID(nonExistentPrefix), func(md blob.Metadata) error {
return nil
}); err != nil {
return nil, errors.Wrap(err, "unable to list from the bucket")
}

return az, nil
}
Loading