github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/builtin/providers/azure/resource_azure_storage_service_helpers.go (about)

     1  package azure
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/Azure/azure-sdk-for-go/management"
     7  	"github.com/Azure/azure-sdk-for-go/management/storageservice"
     8  	"github.com/Azure/azure-sdk-for-go/storage"
     9  )
    10  
    11  // getStorageClientForStorageService is helper function which returns the
    12  // storage.Client associated to the given storage service name.
    13  func getStorageClientForStorageService(mgmtClient management.Client, serviceName string) (storage.Client, error) {
    14  	var storageClient storage.Client
    15  	storageServiceClient := storageservice.NewClient(mgmtClient)
    16  
    17  	keys, err := storageServiceClient.GetStorageServiceKeys(serviceName)
    18  	if err != nil {
    19  		return storageClient, fmt.Errorf("Failed getting Storage Service keys for %s: %s", serviceName, err)
    20  	}
    21  
    22  	storageClient, err = storage.NewBasicClient(serviceName, keys.PrimaryKey)
    23  	if err != nil {
    24  		return storageClient, fmt.Errorf("Failed creating Storage Service client for %s: %s", serviceName, err)
    25  	}
    26  
    27  	return storageClient, err
    28  }
    29  
    30  // getStorageServiceBlobClient is a helper function which returns the
    31  // storage.BlobStorageClient associated to the given storage service name.
    32  func getStorageServiceBlobClient(mgmtClient management.Client, serviceName string) (storage.BlobStorageClient, error) {
    33  	storageClient, err := getStorageClientForStorageService(mgmtClient, serviceName)
    34  	if err != nil {
    35  		return storage.BlobStorageClient{}, err
    36  	}
    37  
    38  	return storageClient.GetBlobService(), nil
    39  }
    40  
    41  // getStorageServiceQueueClient is a helper function which returns the
    42  // storage.QueueServiceClient associated to the given storage service name.
    43  func getStorageServiceQueueClient(mgmtClient management.Client, serviceName string) (storage.QueueServiceClient, error) {
    44  	storageClient, err := getStorageClientForStorageService(mgmtClient, serviceName)
    45  	if err != nil {
    46  		return storage.QueueServiceClient{}, err
    47  	}
    48  
    49  	return storageClient.GetQueueService(), err
    50  }