github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/azure/internal/azurestorage/interface.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package azurestorage
     5  
     6  import (
     7  	"github.com/Azure/azure-sdk-for-go/storage"
     8  	"github.com/juju/errors"
     9  )
    10  
    11  // Client is an interface providing access to Azure storage services.
    12  type Client interface {
    13  	// GetBlobService returns a BlobStorageClient which can operate
    14  	// on the blob service of the storage account.
    15  	GetBlobService() BlobStorageClient
    16  }
    17  
    18  // BlobStorageClient is an interface providing access to Azure blob storage.
    19  //
    20  // This interface the subet of functionality provided by
    21  // https://godoc.org/github.com/Azure/azure-sdk-for-go/storage#BlobStorageClient
    22  // that is required by Juju.
    23  type BlobStorageClient interface {
    24  	// ListBlobs returns an object that contains list of blobs in the
    25  	// container, pagination token and other information in the response
    26  	// of List Blobs call.
    27  	//
    28  	// See https://godoc.org/github.com/Azure/azure-sdk-for-go/storage#BlobStorageClient.ListBlobs
    29  	ListBlobs(container string, params storage.ListBlobsParameters) (storage.BlobListResponse, error)
    30  
    31  	// DeleteBlobIfExists deletes the given blob from the specified
    32  	// container If the blob is deleted with this call, returns true.
    33  	// Otherwise returns false.
    34  	//
    35  	// See https://godoc.org/github.com/Azure/azure-sdk-for-go/storage#BlobStorageClient.DeleteBlobIfExists
    36  	DeleteBlobIfExists(container, name string) (bool, error)
    37  }
    38  
    39  // NewClientFunc is the type of the NewClient function.
    40  type NewClientFunc func(
    41  	accountName, accountKey, blobServiceBaseURL, apiVersion string,
    42  	useHTTPS bool,
    43  ) (Client, error)
    44  
    45  // NewClient returns a Client that is backed by a storage.Client created with
    46  // storage.NewClient
    47  func NewClient(accountName, accountKey, blobServiceBaseURL, apiVersion string, useHTTPS bool) (Client, error) {
    48  	client, err := storage.NewClient(accountName, accountKey, blobServiceBaseURL, apiVersion, useHTTPS)
    49  	if err != nil {
    50  		return nil, errors.Trace(err)
    51  	}
    52  	return clientWrapper{client}, nil
    53  }
    54  
    55  type clientWrapper struct {
    56  	storage.Client
    57  }
    58  
    59  func (w clientWrapper) GetBlobService() BlobStorageClient {
    60  	return w.Client.GetBlobService()
    61  }