...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/storageservice/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management/storageservice

     1  // +build go1.7
     2  
     3  // Package storageservice provides a client for Storage Services.
     4  package storageservice
     5  
     6  // Copyright (c) Microsoft Corporation. All rights reserved.
     7  // Licensed under the MIT License. See License.txt in the project root for license information.
     8  
     9  import (
    10  	"encoding/xml"
    11  	"fmt"
    12  
    13  	"github.com/Azure/azure-sdk-for-go/services/classic/management"
    14  )
    15  
    16  const (
    17  	azureStorageServiceListURL         = "services/storageservices"
    18  	azureStorageServiceURL             = "services/storageservices/%s"
    19  	azureStorageServiceKeysURL         = "services/storageservices/%s/keys"
    20  	azureStorageAccountAvailabilityURL = "services/storageservices/operations/isavailable/%s"
    21  
    22  	azureXmlns = "http://schemas.microsoft.com/windowsazure"
    23  
    24  	errParamNotSpecified = "Parameter %s is not specified."
    25  )
    26  
    27  // NewClient is used to instantiate a new StorageServiceClient from an Azure
    28  // client.
    29  func NewClient(s management.Client) StorageServiceClient {
    30  	return StorageServiceClient{client: s}
    31  }
    32  
    33  func (s StorageServiceClient) ListStorageServices() (ListStorageServicesResponse, error) {
    34  	var l ListStorageServicesResponse
    35  	response, err := s.client.SendAzureGetRequest(azureStorageServiceListURL)
    36  	if err != nil {
    37  		return l, err
    38  	}
    39  
    40  	err = xml.Unmarshal(response, &l)
    41  	return l, err
    42  }
    43  
    44  func (s StorageServiceClient) GetStorageService(serviceName string) (StorageServiceResponse, error) {
    45  	var svc StorageServiceResponse
    46  	if serviceName == "" {
    47  		return svc, fmt.Errorf(errParamNotSpecified, "serviceName")
    48  	}
    49  
    50  	requestURL := fmt.Sprintf(azureStorageServiceURL, serviceName)
    51  	response, err := s.client.SendAzureGetRequest(requestURL)
    52  	if err != nil {
    53  		return svc, err
    54  	}
    55  
    56  	err = xml.Unmarshal(response, &svc)
    57  	return svc, err
    58  }
    59  
    60  func (s StorageServiceClient) GetStorageServiceKeys(serviceName string) (GetStorageServiceKeysResponse, error) {
    61  	var r GetStorageServiceKeysResponse
    62  	if serviceName == "" {
    63  		return r, fmt.Errorf(errParamNotSpecified, "serviceName")
    64  	}
    65  
    66  	requestURL := fmt.Sprintf(azureStorageServiceKeysURL, serviceName)
    67  	data, err := s.client.SendAzureGetRequest(requestURL)
    68  	if err != nil {
    69  		return r, err
    70  	}
    71  
    72  	err = xml.Unmarshal(data, &r)
    73  	return r, err
    74  }
    75  
    76  func (s StorageServiceClient) CreateStorageService(parameters StorageAccountCreateParameters) (management.OperationID, error) {
    77  	data, err := xml.Marshal(CreateStorageServiceInput{
    78  		StorageAccountCreateParameters: parameters})
    79  	if err != nil {
    80  		return "", err
    81  	}
    82  
    83  	return s.client.SendAzurePostRequest(azureStorageServiceListURL, data)
    84  }
    85  
    86  func (s StorageServiceClient) DeleteStorageService(serviceName string) (management.OperationID, error) {
    87  	if serviceName == "" {
    88  		return "", fmt.Errorf(errParamNotSpecified, "serviceName")
    89  	}
    90  
    91  	requestURL := fmt.Sprintf(azureStorageServiceURL, serviceName)
    92  	return s.client.SendAzureDeleteRequest(requestURL)
    93  }
    94  
    95  // CheckStorageAccountNameAvailability checks to if the specified storage account
    96  // name is available.
    97  //
    98  // See https://msdn.microsoft.com/en-us/library/azure/jj154125.aspx
    99  func (s StorageServiceClient) CheckStorageAccountNameAvailability(name string) (AvailabilityResponse, error) {
   100  	var r AvailabilityResponse
   101  	if name == "" {
   102  		return r, fmt.Errorf(errParamNotSpecified, "name")
   103  	}
   104  
   105  	requestURL := fmt.Sprintf(azureStorageAccountAvailabilityURL, name)
   106  	response, err := s.client.SendAzureGetRequest(requestURL)
   107  	if err != nil {
   108  		return r, err
   109  	}
   110  
   111  	err = xml.Unmarshal(response, &r)
   112  	return r, err
   113  }
   114  

View as plain text