From 003fbff92299673ce4d40066abe28ee9936aa23e Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 11 Jul 2019 18:16:37 +0200 Subject: [PATCH 1/6] r/storage_queue: switching to use the new sdk --- azurerm/config.go | 19 -- azurerm/internal/services/storage/client.go | 12 ++ azurerm/resource_arm_storage_queue.go | 164 +++++++--------- azurerm/resource_arm_storage_queue_test.go | 114 ++++++----- .../2018-11-09/blob/containers/README.md | 45 +++++ .../2018-11-09/blob/containers/client.go | 34 ++++ .../2018-11-09/blob/containers/create.go | 123 ++++++++++++ .../2018-11-09/blob/containers/delete.go | 85 +++++++++ .../blob/containers/get_properties.go | 124 ++++++++++++ .../blob/containers/lease_acquire.go | 115 +++++++++++ .../2018-11-09/blob/containers/lease_break.go | 129 +++++++++++++ .../blob/containers/lease_change.go | 111 +++++++++++ .../blob/containers/lease_release.go | 92 +++++++++ .../2018-11-09/blob/containers/lease_renew.go | 92 +++++++++ .../2018-11-09/blob/containers/list_blobs.go | 179 ++++++++++++++++++ .../2018-11-09/blob/containers/models.go | 75 ++++++++ .../2018-11-09/blob/containers/resource_id.go | 46 +++++ .../2018-11-09/blob/containers/set_acl.go | 100 ++++++++++ .../blob/containers/set_metadata.go | 105 ++++++++++ .../2018-11-09/blob/containers/version.go | 14 ++ .../guides/2.0-upgrade-guide.html.markdown | 6 +- website/docs/r/storage_queue.html.markdown | 11 +- 22 files changed, 1622 insertions(+), 173 deletions(-) create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go diff --git a/azurerm/config.go b/azurerm/config.go index e4866046b029..fa298d5df6f7 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -1260,22 +1260,3 @@ func (c *ArmClient) getTableServiceClientForStorageAccount(ctx context.Context, tableClient := storageClient.GetTableService() return &tableClient, true, nil } - -func (c *ArmClient) getQueueServiceClientForStorageAccount(ctx context.Context, resourceGroupName, storageAccountName string) (*mainStorage.QueueServiceClient, bool, error) { - key, accountExists, err := c.getKeyForStorageAccount(ctx, resourceGroupName, storageAccountName) - if err != nil { - return nil, accountExists, err - } - if !accountExists { - return nil, false, nil - } - - storageClient, err := mainStorage.NewClient(storageAccountName, key, c.environment.StorageEndpointSuffix, - mainStorage.DefaultAPIVersion, true) - if err != nil { - return nil, true, fmt.Errorf("Error creating storage client for storage storeAccount %q: %s", storageAccountName, err) - } - - queueClient := storageClient.GetQueueService() - return &queueClient, true, nil -} diff --git a/azurerm/internal/services/storage/client.go b/azurerm/internal/services/storage/client.go index a69e9e27cea1..fe9f9a89b8cd 100644 --- a/azurerm/internal/services/storage/client.go +++ b/azurerm/internal/services/storage/client.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/authorizers" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/directories" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares" + "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities" ) @@ -82,6 +83,17 @@ func (client Client) FileSharesClient(ctx context.Context, resourceGroup, accoun return &directoriesClient, nil } +func (client Client) QueuesClient(ctx context.Context, resourceGroup, accountName string) (*queues.Client, error) { + accountKey, err := client.findAccountKey(ctx, resourceGroup, accountName) + if err != nil { + return nil, fmt.Errorf("Error retrieving Account Key: %s", err) + } + + storageAuth := authorizers.NewSharedKeyLiteAuthorizer(accountName, *accountKey) + queuesClient := queues.New() + queuesClient.Client.Authorizer = storageAuth + return &queuesClient, nil +} func (client Client) TableEntityClient(ctx context.Context, resourceGroup, accountName string) (*entities.Client, error) { accountKey, err := client.findAccountKey(ctx, resourceGroup, accountName) if err != nil { diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index f87fe98f583e..a7460d2a3d7b 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -3,14 +3,14 @@ package azurerm import ( "fmt" "log" - "net/url" "regexp" - "strings" - "github.com/Azure/azure-sdk-for-go/storage" "github.com/hashicorp/terraform/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" ) func resourceArmStorageQueue() *schema.Resource { @@ -31,12 +31,18 @@ func resourceArmStorageQueue() *schema.Resource { ForceNew: true, ValidateFunc: validateArmStorageQueueName, }, - "resource_group_name": azure.SchemaResourceGroupName(), + "storage_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, }, + + // TODO: deprecate me + "resource_group_name": azure.SchemaResourceGroupName(), + + // TODO: MetaData & properties }, } } @@ -71,157 +77,121 @@ func validateArmStorageQueueName(v interface{}, k string) (warnings []string, er } func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) error { - armClient := meta.(*ArmClient) - ctx := armClient.StopContext - environment := armClient.environment + storageClient := meta.(*ArmClient).storage + ctx := meta.(*ArmClient).StopContext - name := d.Get("name").(string) - resourceGroupName := d.Get("resource_group_name").(string) - storageAccountName := d.Get("storage_account_name").(string) + queueName := d.Get("name").(string) + accountName := d.Get("storage_account_name").(string) - queueClient, accountExists, err := armClient.getQueueServiceClientForStorageAccount(ctx, resourceGroupName, storageAccountName) + // TODO: support for MetaData + metaData := make(map[string]string) + + resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName) if err != nil { - return err + return fmt.Errorf("Error locating Resource Group: %s", err) } - if !accountExists { - return fmt.Errorf("Storage Account %q Not Found", storageAccountName) + + client, err := storageClient.QueuesClient(ctx, *resourceGroup, accountName) + if err != nil { + return fmt.Errorf("Error building Queues Client: %s", err) } - queueReference := queueClient.GetQueueReference(name) - id := fmt.Sprintf("https://%s.queue.%s/%s", storageAccountName, environment.StorageEndpointSuffix, name) + resourceID := client.GetResourceID(accountName, queueName) if requireResourcesToBeImported { - exists, e := queueReference.Exists() - if e != nil { - return fmt.Errorf("Error checking if Queue %q exists (Account %q / Resource Group %q): %s", name, storageAccountName, resourceGroupName, e) + existing, err := client.GetMetaData(ctx, accountName, queueName) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Queue %q (Storage Account %q / Resource Group %q): %s", queueName, accountName, *resourceGroup, err) + } } - if exists { - return tf.ImportAsExistsError("azurerm_storage_queue", id) + if !utils.ResponseWasNotFound(existing.Response) { + return tf.ImportAsExistsError("azurerm_storage_queue", resourceID) } } - log.Printf("[INFO] Creating queue %q in storage account %q", name, storageAccountName) - options := &storage.QueueServiceOptions{} - err = queueReference.Create(options) - if err != nil { - return fmt.Errorf("Error creating storage queue on Azure: %s", err) + if _, err := client.Create(ctx, accountName, accountName, metaData); err != nil { + return fmt.Errorf("Error creating Queue %q (Account %q): %+v", queueName, accountName, err) } - d.SetId(id) + d.SetId(resourceID) + return resourceArmStorageQueueRead(d, meta) } func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error { - armClient := meta.(*ArmClient) - ctx := armClient.StopContext + storageClient := meta.(*ArmClient).storage + ctx := meta.(*ArmClient).StopContext - id, err := parseStorageQueueID(d.Id()) + id, err := queues.ParseResourceID(d.Id()) if err != nil { return err } - resourceGroup, err := determineResourceGroupForStorageAccount(id.storageAccountName, armClient) + resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName) if err != nil { - return err + return fmt.Errorf("Error locating Resource Group: %s", err) } if resourceGroup == nil { - log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.storageAccountName) + log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.AccountName) d.SetId("") return nil } - queueClient, accountExists, err := armClient.getQueueServiceClientForStorageAccount(ctx, *resourceGroup, id.storageAccountName) + client, err := storageClient.QueuesClient(ctx, *resourceGroup, id.AccountName) if err != nil { - return err - } - if !accountExists { - log.Printf("[DEBUG] Storage account %q not found, removing queue %q from state", id.storageAccountName, id.queueName) - d.SetId("") - return nil + return fmt.Errorf("Error building Queues Client: %s", err) } - log.Printf("[INFO] Checking for existence of storage queue %q.", id.queueName) - queueReference := queueClient.GetQueueReference(id.queueName) - exists, err := queueReference.Exists() + metaData, err := client.GetMetaData(ctx, id.AccountName, id.QueueName) if err != nil { - return fmt.Errorf("error checking if storage queue %q exists: %s", id.queueName, err) - } + if utils.ResponseWasNotFound(metaData.Response) { + log.Printf("[INFO] Storage Queue %q no longer exists, removing from state...", id.QueueName) + d.SetId("") + return nil + } - if !exists { - log.Printf("[INFO] Storage queue %q no longer exists, removing from state...", id.queueName) - d.SetId("") return nil } - d.Set("name", id.queueName) - d.Set("storage_account_name", id.storageAccountName) + d.Set("name", id.QueueName) + d.Set("storage_account_name", id.AccountName) d.Set("resource_group_name", *resourceGroup) + // TODO: support for MetaData + return nil } func resourceArmStorageQueueDelete(d *schema.ResourceData, meta interface{}) error { - armClient := meta.(*ArmClient) - ctx := armClient.StopContext + storageClient := meta.(*ArmClient).storage + ctx := meta.(*ArmClient).StopContext - id, err := parseStorageQueueID(d.Id()) + id, err := queues.ParseResourceID(d.Id()) if err != nil { return err } - resourceGroup, err := determineResourceGroupForStorageAccount(id.storageAccountName, armClient) + resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName) if err != nil { - return err + return fmt.Errorf("Error locating Resource Group: %s", err) } if resourceGroup == nil { - log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.storageAccountName) + log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.AccountName) + d.SetId("") return nil } - queueClient, accountExists, err := armClient.getQueueServiceClientForStorageAccount(ctx, *resourceGroup, id.storageAccountName) + client, err := storageClient.QueuesClient(ctx, *resourceGroup, id.AccountName) if err != nil { - return err - } - if !accountExists { - log.Printf("[INFO]Storage Account %q doesn't exist so the blob won't exist", id.storageAccountName) - return nil + return fmt.Errorf("Error building Queues Client: %s", err) } - log.Printf("[INFO] Deleting storage queue %q", id.queueName) - queueReference := queueClient.GetQueueReference(id.queueName) - options := &storage.QueueServiceOptions{} - if err = queueReference.Delete(options); err != nil { - return fmt.Errorf("Error deleting storage queue %q: %s", id.queueName, err) + if _, err := client.Delete(ctx, id.AccountName, id.QueueName); err != nil { + return fmt.Errorf("Error deleting Storage Queue %q: %s", id.QueueName, err) } return nil } - -type storageQueueId struct { - storageAccountName string - queueName string -} - -func parseStorageQueueID(input string) (*storageQueueId, error) { - // https://myaccount.queue.core.windows.net/myqueue - uri, err := url.Parse(input) - if err != nil { - return nil, fmt.Errorf("Error parsing %q as a URI: %+v", input, err) - } - - segments := strings.Split(uri.Host, ".") - if len(segments) > 0 { - storageAccountName := segments[0] - // remove the leading `/` - queue := strings.TrimPrefix(uri.Path, "/") - id := storageQueueId{ - storageAccountName: storageAccountName, - queueName: queue, - } - return &id, nil - } - - return nil, nil -} diff --git a/azurerm/resource_arm_storage_queue_test.go b/azurerm/resource_arm_storage_queue_test.go index 66ef960de07c..3c407a686e2d 100644 --- a/azurerm/resource_arm_storage_queue_test.go +++ b/azurerm/resource_arm_storage_queue_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestResourceAzureRMStorageQueueName_Validation(t *testing.T) { @@ -55,7 +56,7 @@ func TestAccAzureRMStorageQueue_basic(t *testing.T) { resourceName := "azurerm_storage_queue.test" ri := tf.AccRandTimeInt() rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMStorageQueue_basic(ri, rs, testLocation()) + location := testLocation() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -63,7 +64,7 @@ func TestAccAzureRMStorageQueue_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageQueueDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMStorageQueue_basic(ri, rs, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageQueueExists(resourceName), ), @@ -116,30 +117,31 @@ func testCheckAzureRMStorageQueueExists(resourceName string) resource.TestCheckF } name := rs.Primary.Attributes["name"] - storageAccountName := rs.Primary.Attributes["storage_account_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for storage queue: %s", name) - } + accountName := rs.Primary.Attributes["storage_account_name"] + + storageClient := testAccProvider.Meta().(*ArmClient).storage + ctx := testAccProvider.Meta().(*ArmClient).StopContext - armClient := testAccProvider.Meta().(*ArmClient) - ctx := armClient.StopContext - queueClient, accountExists, err := armClient.getQueueServiceClientForStorageAccount(ctx, resourceGroup, storageAccountName) + resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName) if err != nil { - return err + return fmt.Errorf("Error locating Resource Group: %s", err) } - if !accountExists { - return fmt.Errorf("Bad: Storage Account %q does not exist", storageAccountName) + if resourceGroup == nil { + return fmt.Errorf("Unable to determine Resource Group for Storage Account %q", accountName) } - queueReference := queueClient.GetQueueReference(name) - exists, err := queueReference.Exists() + client, err := storageClient.QueuesClient(ctx, *resourceGroup, accountName) if err != nil { - return err + return fmt.Errorf("Error building Queues Client: %s", err) } - if !exists { - return fmt.Errorf("Bad: Storage Queue %q (storage account: %q) does not exist", name, storageAccountName) + metaData, err := client.GetMetaData(ctx, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(metaData.Response) { + return fmt.Errorf("Bad: Storage Queue %q (storage account: %q) does not exist", name, accountName) + } + + return fmt.Errorf("Bad: error retrieving Storage Queue %q (storage account: %q): %s", name, accountName, err) } return nil @@ -153,61 +155,51 @@ func testCheckAzureRMStorageQueueDestroy(s *terraform.State) error { } name := rs.Primary.Attributes["name"] - storageAccountName := rs.Primary.Attributes["storage_account_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for storage queue: %s", name) - } + accountName := rs.Primary.Attributes["storage_account_name"] - armClient := testAccProvider.Meta().(*ArmClient) - ctx := armClient.StopContext - queueClient, accountExists, err := armClient.getQueueServiceClientForStorageAccount(ctx, resourceGroup, storageAccountName) + storageClient := testAccProvider.Meta().(*ArmClient).storage + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName) if err != nil { - return nil + return fmt.Errorf("Error locating Resource Group: %s", err) } - if !accountExists { + + if resourceGroup == nil { return nil } - queueReference := queueClient.GetQueueReference(name) - exists, err := queueReference.Exists() + client, err := storageClient.QueuesClient(ctx, *resourceGroup, accountName) if err != nil { - return nil + return fmt.Errorf("Error building Queues Client: %s", err) } - if exists { - return fmt.Errorf("Bad: Storage Queue %q (storage account: %q) still exists", name, storageAccountName) + metaData, err := client.GetMetaData(ctx, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(metaData.Response) { + return nil + } + + return fmt.Errorf("Unexpected error getting MetaData for Queue %q: %s", name, err) } + + return fmt.Errorf("Bad: Storage Queue %q (storage account: %q) still exists", name, accountName) } return nil } func testAccAzureRMStorageQueue_basic(rInt int, rString string, location string) string { + template := testAccAzureRMStorageQueue_template(rInt, rString, location) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - - tags = { - environment = "staging" - } -} +%s resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } -`, rInt, location, rString, rInt) +`, template, rInt) } func testAccAzureRMStorageQueue_requiresImport(rInt int, rString string, location string) string { @@ -222,3 +214,25 @@ resource "azurerm_storage_queue" "import" { } `, template) } + +func testAccAzureRMStorageQueue_template(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestacc%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" + + tags = { + environment = "staging" + } +} + +`, rInt, location, rString) +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md new file mode 100644 index 000000000000..37d2878cc5ee --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md @@ -0,0 +1,45 @@ +## Blob Storage Container SDK for API version 2018-11-09 + +This package allows you to interact with the Containers Blob Storage API + +### Supported Authorizers + +* Azure Active Directory (for the Resource Endpoint `https://storage.azure.com`) +* SharedKeyLite (Blob, File & Queue) + +Note: when using the `ListBlobs` operation, only `SharedKeyLite` authentication is supported. + +### Example Usage + +```go +package main + +import ( + "context" + "fmt" + "time" + + "github.com/Azure/go-autorest/autorest" + "github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers" +) + +func Example() error { + accountName := "storageaccount1" + storageAccountKey := "ABC123...." + containerName := "mycontainer" + + storageAuth := autorest.NewSharedKeyLiteAuthorizer(accountName, storageAccountKey) + containersClient := containers.New() + containersClient.Client.Authorizer = storageAuth + + ctx := context.TODO() + createInput := containers.CreateInput{ + AccessLevel: containers.Private, + } + if _, err := containersClient.Create(ctx, accountName, containerName, createInput); err != nil { + return fmt.Errorf("Error creating Container: %s", err) + } + + return nil +} +``` \ No newline at end of file diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go new file mode 100644 index 000000000000..7bf494734484 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go @@ -0,0 +1,34 @@ +package containers + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Client is the base client for Blob Storage Containers. +type Client struct { + autorest.Client + BaseURI string +} + +// New creates an instance of the Client client. +func New() Client { + return NewWithEnvironment(azure.PublicCloud) +} + +// NewWithBaseURI creates an instance of the Client client. +func NewWithEnvironment(environment azure.Environment) Client { + return Client{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: environment.StorageEndpointSuffix, + } +} + +func (client Client) setAccessLevelIntoHeaders(headers map[string]interface{}, level AccessLevel) map[string]interface{} { + // If this header is not included in the request, container data is private to the account owner. + if level != Private { + headers["x-ms-blob-public-access"] = string(level) + } + + return headers +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go new file mode 100644 index 000000000000..84c2887d7d1a --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go @@ -0,0 +1,123 @@ +package containers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +type CreateInput struct { + // Specifies whether data in the container may be accessed publicly and the level of access + AccessLevel AccessLevel + + // A name-value pair to associate with the container as metadata. + MetaData map[string]string +} + +type CreateResponse struct { + autorest.Response + Error *ErrorResponse `xml:"Error"` +} + +// Create creates a new container under the specified account. +// If the container with the same name already exists, the operation fails. +func (client Client) Create(ctx context.Context, accountName, containerName string, input CreateInput) (result CreateResponse, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "Create", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "Create", "`containerName` cannot be an empty string.") + } + if err := metadata.Validate(input.MetaData); err != nil { + return result, validation.NewError("containers.Client", "Create", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + } + + req, err := client.CreatePreparer(ctx, accountName, containerName, input) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client Client) CreatePreparer(ctx context.Context, accountName string, containerName string, input CreateInput) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + headers = client.setAccessLevelIntoHeaders(headers, input.AccessLevel) + headers = metadata.SetIntoHeaders(headers, input.MetaData) + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client Client) CreateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client Client) CreateResponder(resp *http.Response) (result CreateResponse, err error) { + successfulStatusCodes := []int{ + http.StatusCreated, + } + if autorest.ResponseHasStatusCode(resp, successfulStatusCodes...) { + // when successful there's no response + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(successfulStatusCodes...), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + } else { + // however when there's an error the error's in the response + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(successfulStatusCodes...), + autorest.ByUnmarshallingXML(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + } + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go new file mode 100644 index 000000000000..30958295388e --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go @@ -0,0 +1,85 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// Delete marks the specified container for deletion. +// The container and any blobs contained within it are later deleted during garbage collection. +func (client Client) Delete(ctx context.Context, accountName, containerName string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "Delete", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "Delete", "`containerName` cannot be an empty string.") + } + + req, err := client.DeletePreparer(ctx, accountName, containerName) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client Client) DeletePreparer(ctx context.Context, accountName string, containerName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client Client) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go new file mode 100644 index 000000000000..1e308da67c55 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go @@ -0,0 +1,124 @@ +package containers + +import ( + "context" + "net/http" + "strings" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +// GetProperties returns the properties for this Container without a Lease +func (client Client) GetProperties(ctx context.Context, accountName, containerName string) (ContainerProperties, error) { + // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. + // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. + return client.GetPropertiesWithLeaseID(ctx, accountName, containerName, "") +} + +// GetPropertiesWithLeaseID returns the properties for this Container using the specified LeaseID +func (client Client) GetPropertiesWithLeaseID(ctx context.Context, accountName, containerName, leaseID string) (result ContainerProperties, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`containerName` cannot be an empty string.") + } + + req, err := client.GetPropertiesWithLeaseIDPreparer(ctx, accountName, containerName, leaseID) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetPropertiesWithLeaseIDSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", resp, "Failure sending request") + return + } + + result, err = client.GetPropertiesWithLeaseIDResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetPropertiesWithLeaseIDPreparer prepares the GetPropertiesWithLeaseID request. +func (client Client) GetPropertiesWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. + // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. + if leaseID != "" { + headers["x-ms-lease-id"] = leaseID + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetPropertiesWithLeaseIDSender sends the GetPropertiesWithLeaseID request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetPropertiesWithLeaseIDSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetPropertiesWithLeaseIDResponder handles the response to the GetPropertiesWithLeaseID request. The method always +// closes the http.Response Body. +func (client Client) GetPropertiesWithLeaseIDResponder(resp *http.Response) (result ContainerProperties, err error) { + if resp != nil { + result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status")) + result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state")) + if result.LeaseStatus == Locked { + duration := LeaseDuration(resp.Header.Get("x-ms-lease-duration")) + result.LeaseDuration = &duration + } + + // If this header is not returned in the response, the container is private to the account owner. + accessLevel := resp.Header.Get("x-ms-blob-public-access") + if accessLevel != "" { + result.AccessLevel = AccessLevel(accessLevel) + } else { + result.AccessLevel = Private + } + + // we can't necessarily use strconv.ParseBool here since this could be nil (only in some API versions) + result.HasImmutabilityPolicy = strings.EqualFold(resp.Header.Get("x-ms-has-immutability-policy"), "true") + result.HasLegalHold = strings.EqualFold(resp.Header.Get("x-ms-has-legal-hold"), "true") + + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go new file mode 100644 index 000000000000..061c863c43f9 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go @@ -0,0 +1,115 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +type AcquireLeaseInput struct { + // Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. + // A non-infinite lease can be between 15 and 60 seconds + LeaseDuration int + + ProposedLeaseID string +} + +type AcquireLeaseResponse struct { + autorest.Response + + LeaseID string +} + +// AcquireLease establishes and manages a lock on a container for delete operations. +func (client Client) AcquireLease(ctx context.Context, accountName, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "AcquireLease", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "AcquireLease", "`containerName` cannot be an empty string.") + } + // An infinite lease duration is -1 seconds. A non-infinite lease can be between 15 and 60 seconds + if input.LeaseDuration != -1 && (input.LeaseDuration <= 15 || input.LeaseDuration >= 60) { + return result, validation.NewError("containers.Client", "AcquireLease", "`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds.") + } + + req, err := client.AcquireLeasePreparer(ctx, accountName, containerName, input) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", nil, "Failure preparing request") + return + } + + resp, err := client.AcquireLeaseSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", resp, "Failure sending request") + return + } + + result, err = client.AcquireLeaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", resp, "Failure responding to request") + return + } + + return +} + +// AcquireLeasePreparer prepares the AcquireLease request. +func (client Client) AcquireLeasePreparer(ctx context.Context, accountName string, containerName string, input AcquireLeaseInput) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + "comp": autorest.Encode("path", "lease"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + "x-ms-lease-action": "acquire", + "x-ms-lease-duration": input.LeaseDuration, + } + + if input.ProposedLeaseID != "" { + headers["x-ms-proposed-lease-id"] = input.ProposedLeaseID + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// AcquireLeaseSender sends the AcquireLease request. The method will close the +// http.Response Body if it receives an error. +func (client Client) AcquireLeaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// AcquireLeaseResponder handles the response to the AcquireLease request. The method always +// closes the http.Response Body. +func (client Client) AcquireLeaseResponder(resp *http.Response) (result AcquireLeaseResponse, err error) { + if resp != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusCreated), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go new file mode 100644 index 000000000000..08acfb7a3116 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go @@ -0,0 +1,129 @@ +package containers + +import ( + "context" + "net/http" + "strconv" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +type BreakLeaseInput struct { + // For a break operation, proposed duration the lease should continue + // before it is broken, in seconds, between 0 and 60. + // This break period is only used if it is shorter than the time remaining on the lease. + // If longer, the time remaining on the lease is used. + // A new lease will not be available before the break period has expired, + // but the lease may be held for longer than the break period. + // If this header does not appear with a break operation, a fixed-duration lease breaks + // after the remaining lease period elapses, and an infinite lease breaks immediately. + BreakPeriod *int + + LeaseID string +} + +type BreakLeaseResponse struct { + autorest.Response + + // Approximate time remaining in the lease period, in seconds. + // If the break is immediate, 0 is returned. + LeaseTime int +} + +// BreakLease breaks a lock based on it's Lease ID +func (client Client) BreakLease(ctx context.Context, accountName, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "BreakLease", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "BreakLease", "`containerName` cannot be an empty string.") + } + if input.LeaseID == "" { + return result, validation.NewError("containers.Client", "BreakLease", "`input.LeaseID` cannot be an empty string.") + } + + req, err := client.BreakLeasePreparer(ctx, accountName, containerName, input) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", nil, "Failure preparing request") + return + } + + resp, err := client.BreakLeaseSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", resp, "Failure sending request") + return + } + + result, err = client.BreakLeaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", resp, "Failure responding to request") + return + } + + return +} + +// BreakLeasePreparer prepares the BreakLease request. +func (client Client) BreakLeasePreparer(ctx context.Context, accountName string, containerName string, input BreakLeaseInput) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + "comp": autorest.Encode("path", "lease"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + "x-ms-lease-action": "break", + "x-ms-lease-id": input.LeaseID, + } + + if input.BreakPeriod != nil { + headers["x-ms-lease-break-period"] = *input.BreakPeriod + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// BreakLeaseSender sends the BreakLease request. The method will close the +// http.Response Body if it receives an error. +func (client Client) BreakLeaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// BreakLeaseResponder handles the response to the BreakLease request. The method always +// closes the http.Response Body. +func (client Client) BreakLeaseResponder(resp *http.Response) (result BreakLeaseResponse, err error) { + if resp != nil { + leaseRaw := resp.Header.Get("x-ms-lease-time") + if leaseRaw != "" { + i, err := strconv.Atoi(leaseRaw) + if err == nil { + result.LeaseTime = i + } + } + } + + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go new file mode 100644 index 000000000000..dfbcb132dae3 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go @@ -0,0 +1,111 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +type ChangeLeaseInput struct { + ExistingLeaseID string + ProposedLeaseID string +} + +type ChangeLeaseResponse struct { + autorest.Response + + LeaseID string +} + +// ChangeLease changes the lock from one Lease ID to another Lease ID +func (client Client) ChangeLease(ctx context.Context, accountName, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "ChangeLease", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "ChangeLease", "`containerName` cannot be an empty string.") + } + if input.ExistingLeaseID == "" { + return result, validation.NewError("containers.Client", "ChangeLease", "`input.ExistingLeaseID` cannot be an empty string.") + } + if input.ProposedLeaseID == "" { + return result, validation.NewError("containers.Client", "ChangeLease", "`input.ProposedLeaseID` cannot be an empty string.") + } + + req, err := client.ChangeLeasePreparer(ctx, accountName, containerName, input) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", nil, "Failure preparing request") + return + } + + resp, err := client.ChangeLeaseSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", resp, "Failure sending request") + return + } + + result, err = client.ChangeLeaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", resp, "Failure responding to request") + return + } + + return +} + +// ChangeLeasePreparer prepares the ChangeLease request. +func (client Client) ChangeLeasePreparer(ctx context.Context, accountName string, containerName string, input ChangeLeaseInput) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + "comp": autorest.Encode("path", "lease"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + "x-ms-lease-action": "change", + "x-ms-lease-id": input.ExistingLeaseID, + "x-ms-proposed-lease-id": input.ProposedLeaseID, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ChangeLeaseSender sends the ChangeLease request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ChangeLeaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ChangeLeaseResponder handles the response to the ChangeLease request. The method always +// closes the http.Response Body. +func (client Client) ChangeLeaseResponder(resp *http.Response) (result ChangeLeaseResponse, err error) { + if resp != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go new file mode 100644 index 000000000000..fafcf98f1e67 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go @@ -0,0 +1,92 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// ReleaseLease releases the lock based on the Lease ID +func (client Client) ReleaseLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "ReleaseLease", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "ReleaseLease", "`containerName` cannot be an empty string.") + } + if leaseID == "" { + return result, validation.NewError("containers.Client", "ReleaseLease", "`leaseID` cannot be an empty string.") + } + + req, err := client.ReleaseLeasePreparer(ctx, accountName, containerName, leaseID) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", nil, "Failure preparing request") + return + } + + resp, err := client.ReleaseLeaseSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", resp, "Failure sending request") + return + } + + result, err = client.ReleaseLeaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", resp, "Failure responding to request") + return + } + + return +} + +// ReleaseLeasePreparer prepares the ReleaseLease request. +func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + "comp": autorest.Encode("path", "lease"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + "x-ms-lease-action": "release", + "x-ms-lease-id": leaseID, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReleaseLeaseSender sends the ReleaseLease request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ReleaseLeaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ReleaseLeaseResponder handles the response to the ReleaseLease request. The method always +// closes the http.Response Body. +func (client Client) ReleaseLeaseResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go new file mode 100644 index 000000000000..3fe17656cd87 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go @@ -0,0 +1,92 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// RenewLease renewes the lock based on the Lease ID +func (client Client) RenewLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "RenewLease", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "RenewLease", "`containerName` cannot be an empty string.") + } + if leaseID == "" { + return result, validation.NewError("containers.Client", "RenewLease", "`leaseID` cannot be an empty string.") + } + + req, err := client.RenewLeasePreparer(ctx, accountName, containerName, leaseID) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", nil, "Failure preparing request") + return + } + + resp, err := client.RenewLeaseSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure sending request") + return + } + + result, err = client.RenewLeaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure responding to request") + return + } + + return +} + +// RenewLeasePreparer prepares the RenewLease request. +func (client Client) RenewLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "restype": autorest.Encode("path", "container"), + "comp": autorest.Encode("path", "lease"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + "x-ms-lease-action": "renew", + "x-ms-lease-id": leaseID, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RenewLeaseSender sends the RenewLease request. The method will close the +// http.Response Body if it receives an error. +func (client Client) RenewLeaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// RenewLeaseResponder handles the response to the RenewLease request. The method always +// closes the http.Response Body. +func (client Client) RenewLeaseResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go new file mode 100644 index 000000000000..82797d091d36 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go @@ -0,0 +1,179 @@ +package containers + +import ( + "context" + "net/http" + "strings" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +type ListBlobsInput struct { + Delimiter *string + Include *[]Dataset + Marker *string + MaxResults *int + Prefix *string +} + +type ListBlobsResult struct { + autorest.Response + + Delimiter string `xml:"Delimiter"` + Marker string `xml:"Marker"` + MaxResults int `xml:"MaxResults"` + NextMarker *string `xml:"NextMarker,omitempty"` + Prefix string `xml:"Prefix"` + Blobs Blobs `xml:"Blobs"` +} + +type Blobs struct { + Blobs []BlobDetails `xml:"Blob"` + BlobPrefix *BlobPrefix `xml:"BlobPrefix"` +} + +type BlobDetails struct { + Name string `xml:"Name"` + Deleted bool `xml:"Deleted,omitempty"` + MetaData map[string]interface{} `map:"Metadata,omitempty"` + Properties *BlobProperties `xml:"Properties,omitempty"` + Snapshot *string `xml:"Snapshot,omitempty"` +} + +type BlobProperties struct { + AccessTier *string `xml:"AccessTier,omitempty"` + AccessTierInferred *bool `xml:"AccessTierInferred,omitempty"` + AccessTierChangeTime *string `xml:"AccessTierChangeTime,omitempty"` + BlobType *string `xml:"BlobType,omitempty"` + BlobSequenceNumber *string `xml:"x-ms-blob-sequence-number,omitempty"` + CacheControl *string `xml:"Cache-Control,omitempty"` + ContentEncoding *string `xml:"ContentEncoding,omitempty"` + ContentLanguage *string `xml:"Content-Language,omitempty"` + ContentLength *int64 `xml:"Content-Length,omitempty"` + ContentMD5 *string `xml:"Content-MD5,omitempty"` + ContentType *string `xml:"Content-Type,omitempty"` + CopyCompletionTime *string `xml:"CopyCompletionTime,omitempty"` + CopyId *string `xml:"CopyId,omitempty"` + CopyStatus *string `xml:"CopyStatus,omitempty"` + CopySource *string `xml:"CopySource,omitempty"` + CopyProgress *string `xml:"CopyProgress,omitempty"` + CopyStatusDescription *string `xml:"CopyStatusDescription,omitempty"` + CreationTime *string `xml:"CreationTime,omitempty"` + ETag *string `xml:"Etag,omitempty"` + DeletedTime *string `xml:"DeletedTime,omitempty"` + IncrementalCopy *bool `xml:"IncrementalCopy,omitempty"` + LastModified *string `xml:"Last-Modified,omitempty"` + LeaseDuration *string `xml:"LeaseDuration,omitempty"` + LeaseState *string `xml:"LeaseState,omitempty"` + LeaseStatus *string `xml:"LeaseStatus,omitempty"` + RemainingRetentionDays *string `xml:"RemainingRetentionDays,omitempty"` + ServerEncrypted *bool `xml:"ServerEncrypted,omitempty"` +} + +type BlobPrefix struct { + Name string `xml:"Name"` +} + +// ListBlobs lists the blobs matching the specified query within the specified Container +func (client Client) ListBlobs(ctx context.Context, accountName, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "ListBlobs", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "ListBlobs", "`containerName` cannot be an empty string.") + } + if input.MaxResults != nil && (*input.MaxResults <= 0 || *input.MaxResults > 5000) { + return result, validation.NewError("containers.Client", "ListBlobs", "`input.MaxResults` can either be nil or between 0 and 5000.") + } + + req, err := client.ListBlobsPreparer(ctx, accountName, containerName, input) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", nil, "Failure preparing request") + return + } + + resp, err := client.ListBlobsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", resp, "Failure sending request") + return + } + + result, err = client.ListBlobsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", resp, "Failure responding to request") + return + } + + return +} + +// ListBlobsPreparer prepares the ListBlobs request. +func (client Client) ListBlobsPreparer(ctx context.Context, accountName, containerName string, input ListBlobsInput) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("query", "list"), + "restype": autorest.Encode("query", "container"), + } + + if input.Delimiter != nil { + queryParameters["delimiter"] = autorest.Encode("query", *input.Delimiter) + } + if input.Include != nil { + vals := make([]string, 0) + for _, v := range *input.Include { + vals = append(vals, string(v)) + } + include := strings.Join(vals, ",") + queryParameters["include"] = autorest.Encode("query", include) + } + if input.Marker != nil { + queryParameters["marker"] = autorest.Encode("query", *input.Marker) + } + if input.MaxResults != nil { + queryParameters["maxresults"] = autorest.Encode("query", *input.MaxResults) + } + if input.Prefix != nil { + queryParameters["prefix"] = autorest.Encode("query", *input.Prefix) + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBlobsSender sends the ListBlobs request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ListBlobsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListBlobsResponder handles the response to the ListBlobs request. The method always +// closes the http.Response Body. +func (client Client) ListBlobsResponder(resp *http.Response) (result ListBlobsResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingXML(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go new file mode 100644 index 000000000000..adba36818aa1 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go @@ -0,0 +1,75 @@ +package containers + +import "github.com/Azure/go-autorest/autorest" + +type AccessLevel string + +var ( + // Blob specifies public read access for blobs. + // Blob data within this container can be read via anonymous request, + // but container data is not available. + // Clients cannot enumerate blobs within the container via anonymous request. + Blob AccessLevel = "blob" + + // Container specifies full public read access for container and blob data. + // Clients can enumerate blobs within the container via anonymous request, + // but cannot enumerate containers within the storage account. + Container AccessLevel = "container" + + // Private specifies that container data is private to the account owner + Private AccessLevel = "" +) + +type ContainerProperties struct { + autorest.Response + + AccessLevel AccessLevel + LeaseStatus LeaseStatus + LeaseState LeaseState + LeaseDuration *LeaseDuration + MetaData map[string]string + HasImmutabilityPolicy bool + HasLegalHold bool +} + +type Dataset string + +var ( + Copy Dataset = "copy" + Deleted Dataset = "deleted" + MetaData Dataset = "metadata" + Snapshots Dataset = "snapshots" + UncommittedBlobs Dataset = "uncommittedblobs" +) + +type ErrorResponse struct { + Code *string `xml:"Code"` + Message *string `xml:"Message"` +} + +type LeaseDuration string + +var ( + // If this lease is for a Fixed Duration + Fixed LeaseDuration = "fixed" + + // If this lease is for an Indefinite Duration + Infinite LeaseDuration = "infinite" +) + +type LeaseState string + +var ( + Available LeaseState = "available" + Breaking LeaseState = "breaking" + Broken LeaseState = "broken" + Expired LeaseState = "expired" + Leased LeaseState = "leased" +) + +type LeaseStatus string + +var ( + Locked LeaseStatus = "locked" + Unlocked LeaseStatus = "unlocked" +) diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go new file mode 100644 index 000000000000..651dd84aed55 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go @@ -0,0 +1,46 @@ +package containers + +import ( + "fmt" + "net/url" + "strings" + + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// GetResourceID returns the Resource ID for the given Container +// This can be useful when, for example, you're using this as a unique identifier +func (client Client) GetResourceID(accountName, containerName string) string { + domain := endpoints.GetBlobEndpoint(client.BaseURI, accountName) + return fmt.Sprintf("%s/%s", domain, containerName) +} + +type ResourceID struct { + AccountName string + ContainerName string +} + +// ParseResourceID parses the Resource ID and returns an object which can be used +// to interact with the Container Resource +func ParseResourceID(id string) (*ResourceID, error) { + // example: https://foo.blob.core.windows.net/Bar + if id == "" { + return nil, fmt.Errorf("`id` was empty") + } + + uri, err := url.Parse(id) + if err != nil { + return nil, fmt.Errorf("Error parsing ID as a URL: %s", err) + } + + accountName, err := endpoints.GetAccountNameFromEndpoint(uri.Host) + if err != nil { + return nil, fmt.Errorf("Error parsing Account Name: %s", err) + } + + containerName := strings.TrimPrefix(uri.Path, "/") + return &ResourceID{ + AccountName: *accountName, + ContainerName: containerName, + }, nil +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go new file mode 100644 index 000000000000..fcf4e1056fa4 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go @@ -0,0 +1,100 @@ +package containers + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// SetAccessControl sets the Access Control for a Container without a Lease ID +func (client Client) SetAccessControl(ctx context.Context, accountName, containerName string, level AccessLevel) (autorest.Response, error) { + return client.SetAccessControlWithLeaseID(ctx, accountName, containerName, "", level) +} + +// SetAccessControlWithLeaseID sets the Access Control for a Container using the specified Lease ID +func (client Client) SetAccessControlWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "SetAccessControl", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "SetAccessControl", "`containerName` cannot be an empty string.") + } + + req, err := client.SetAccessControlWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, level) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", nil, "Failure preparing request") + return + } + + resp, err := client.SetAccessControlWithLeaseIDSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", resp, "Failure sending request") + return + } + + result, err = client.SetAccessControlWithLeaseIDResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", resp, "Failure responding to request") + return + } + + return +} + +// SetAccessControlWithLeaseIDPreparer prepares the SetAccessControlWithLeaseID request. +func (client Client) SetAccessControlWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "acl"), + "restype": autorest.Encode("path", "container"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + headers = client.setAccessLevelIntoHeaders(headers, level) + + // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. + // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. + if leaseID != "" { + headers["x-ms-lease-id"] = leaseID + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SetAccessControlWithLeaseIDSender sends the SetAccessControlWithLeaseID request. The method will close the +// http.Response Body if it receives an error. +func (client Client) SetAccessControlWithLeaseIDSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// SetAccessControlWithLeaseIDResponder handles the response to the SetAccessControlWithLeaseID request. The method always +// closes the http.Response Body. +func (client Client) SetAccessControlWithLeaseIDResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go new file mode 100644 index 000000000000..fb9e07fdefa9 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go @@ -0,0 +1,105 @@ +package containers + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +// SetMetaData sets the specified MetaData on the Container without a Lease ID +func (client Client) SetMetaData(ctx context.Context, accountName, containerName string, metaData map[string]string) (autorest.Response, error) { + return client.SetMetaDataWithLeaseID(ctx, accountName, containerName, "", metaData) +} + +// SetMetaDataWithLeaseID sets the specified MetaData on the Container using the specified Lease ID +func (client Client) SetMetaDataWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("containers.Client", "SetMetaData", "`accountName` cannot be an empty string.") + } + if containerName == "" { + return result, validation.NewError("containers.Client", "SetMetaData", "`containerName` cannot be an empty string.") + } + if err := metadata.Validate(metaData); err != nil { + return result, validation.NewError("containers.Client", "SetMetaData", fmt.Sprintf("`metaData` is not valid: %s.", err)) + } + + req, err := client.SetMetaDataWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, metaData) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", nil, "Failure preparing request") + return + } + + resp, err := client.SetMetaDataWithLeaseIDSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", resp, "Failure sending request") + return + } + + result, err = client.SetMetaDataWithLeaseIDResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", resp, "Failure responding to request") + return + } + + return +} + +// SetMetaDataWithLeaseIDPreparer prepares the SetMetaDataWithLeaseID request. +func (client Client) SetMetaDataWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "containerName": autorest.Encode("path", containerName), + } + + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "metadata"), + "restype": autorest.Encode("path", "container"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + headers = metadata.SetIntoHeaders(headers, metaData) + + // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. + // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. + if leaseID != "" { + headers["x-ms-lease-id"] = leaseID + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{containerName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SetMetaDataWithLeaseIDSender sends the SetMetaDataWithLeaseID request. The method will close the +// http.Response Body if it receives an error. +func (client Client) SetMetaDataWithLeaseIDSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// SetMetaDataWithLeaseIDResponder handles the response to the SetMetaDataWithLeaseID request. The method always +// closes the http.Response Body. +func (client Client) SetMetaDataWithLeaseIDResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go new file mode 100644 index 000000000000..7047f301b179 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go @@ -0,0 +1,14 @@ +package containers + +import ( + "fmt" + + "github.com/tombuildsstuff/giovanni/version" +) + +// APIVersion is the version of the API used for all Storage API Operations +const APIVersion = "2018-11-09" + +func UserAgent() string { + return fmt.Sprintf("tombuildsstuff/giovanni/%s storage/%s", version.Number, APIVersion) +} diff --git a/website/docs/guides/2.0-upgrade-guide.html.markdown b/website/docs/guides/2.0-upgrade-guide.html.markdown index b6a727e3c3d3..e9c8a9cbea28 100644 --- a/website/docs/guides/2.0-upgrade-guide.html.markdown +++ b/website/docs/guides/2.0-upgrade-guide.html.markdown @@ -339,9 +339,13 @@ The deprecated `enable_filtering_messages_before_publishing` field will be remov The deprecated `account_type` field will be removed. This has been split into the fields `account_tier` and `account_replication_type`. +### Resource: `azurerm_storage_queue` + +The deprecated `resource_group_name` field will be removed, since this is no longer used. + ### Resource: `azurerm_storage_share` -The deprecated `resource_group_name` field will be removed as this field is no longer used. +The deprecated `resource_group_name` field will be removed, since this is no longer used. ### Resource: `azurerm_subnet` diff --git a/website/docs/r/storage_queue.html.markdown b/website/docs/r/storage_queue.html.markdown index 022b8a255eff..17bf01f23364 100644 --- a/website/docs/r/storage_queue.html.markdown +++ b/website/docs/r/storage_queue.html.markdown @@ -3,19 +3,19 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_storage_queue" sidebar_current: "docs-azurerm-resource-storage-queue" description: |- - Manages a Azure Storage Queue. + Manages a Queue within an Azure Storage Account. --- # azurerm_storage_queue -Manage an Azure Storage Queue. +Manages a Queue within an Azure Storage Account. ## Example Usage ```hcl resource "azurerm_resource_group" "test" { name = "example-resources" - location = "westus" + location = "West Europe" } resource "azurerm_storage_account" "test" { @@ -39,12 +39,11 @@ The following arguments are supported: * `name` - (Required) The name of the storage queue. Must be unique within the storage account the queue is located. -* `resource_group_name` - (Required) The name of the resource group in which to - create the storage queue. Changing this forces a new resource to be created. - * `storage_account_name` - (Required) Specifies the storage account in which to create the storage queue. Changing this forces a new resource to be created. +* `resource_group_name` - (Optional / **Deprecated**) The name of the resource group in which to create the storage queue. + ## Attributes Reference The following attributes are exported in addition to the arguments listed above: From 155b789340cd51076052279b172ea6f6642cba4b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 11 Jul 2019 18:25:34 +0200 Subject: [PATCH 2/6] r/storage_queue: support for metadata --- azurerm/resource_arm_storage_queue.go | 59 ++++++++++++++++-- azurerm/resource_arm_storage_queue_test.go | 72 +++++++++++++++++++++- website/docs/r/storage_queue.html.markdown | 7 ++- 3 files changed, 127 insertions(+), 11 deletions(-) diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index a7460d2a3d7b..b5e64974dd8d 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -9,6 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" ) @@ -17,6 +18,7 @@ func resourceArmStorageQueue() *schema.Resource { return &schema.Resource{ Create: resourceArmStorageQueueCreate, Read: resourceArmStorageQueueRead, + Update: resourceArmStorageQueueUpdate, Delete: resourceArmStorageQueueDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -39,10 +41,20 @@ func resourceArmStorageQueue() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - // TODO: deprecate me - "resource_group_name": azure.SchemaResourceGroupName(), + // TODO: switch to using the common deprecated RG name function + "resource_group_name": func() *schema.Schema { + s := azure.SchemaResourceGroupName() + s.Required = false + s.ForceNew = false + s.Optional = true + s.Computed = true + s.Deprecated = "This is no longer used and will be removed in 2.0" + return s + }(), - // TODO: MetaData & properties + "metadata": storage.MetaDataSchema(), + + // TODO: properties }, } } @@ -83,8 +95,8 @@ func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) err queueName := d.Get("name").(string) accountName := d.Get("storage_account_name").(string) - // TODO: support for MetaData - metaData := make(map[string]string) + metaDataRaw := d.Get("metadata").(map[string]interface{}) + metaData := storage.ExpandMetaData(metaDataRaw) resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName) if err != nil { @@ -119,6 +131,39 @@ func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) err return resourceArmStorageQueueRead(d, meta) } +func resourceArmStorageQueueUpdate(d *schema.ResourceData, meta interface{}) error { + storageClient := meta.(*ArmClient).storage + ctx := meta.(*ArmClient).StopContext + + id, err := queues.ParseResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName) + if err != nil { + return fmt.Errorf("Error locating Resource Group: %s", err) + } + + if resourceGroup == nil { + return fmt.Errorf("Error determine Resource Group for Storage Account %q: %s", id.AccountName, err) + } + + client, err := storageClient.QueuesClient(ctx, *resourceGroup, id.AccountName) + if err != nil { + return fmt.Errorf("Error building Queues Client: %s", err) + } + + metaDataRaw := d.Get("metadata").(map[string]interface{}) + metaData := storage.ExpandMetaData(metaDataRaw) + + if _, err := client.SetMetaData(ctx, id.AccountName, id.QueueName, metaData); err != nil { + return fmt.Errorf("Error setting MetaData for Queue %q (Storage Account %q): %s", id.QueueName, id.AccountName, err) + } + + return resourceArmStorageQueueRead(d, metaDataRaw) +} + func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error { storageClient := meta.(*ArmClient).storage ctx := meta.(*ArmClient).StopContext @@ -159,7 +204,9 @@ func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error d.Set("storage_account_name", id.AccountName) d.Set("resource_group_name", *resourceGroup) - // TODO: support for MetaData + if err := d.Set("metadata", storage.FlattenMetaData(metaData.MetaData)); err != nil { + return fmt.Errorf("Error setting `metadata`: %s", err) + } return nil } diff --git a/azurerm/resource_arm_storage_queue_test.go b/azurerm/resource_arm_storage_queue_test.go index 3c407a686e2d..655d133c30de 100644 --- a/azurerm/resource_arm_storage_queue_test.go +++ b/azurerm/resource_arm_storage_queue_test.go @@ -108,6 +108,43 @@ func TestAccAzureRMStorageQueue_requiresImport(t *testing.T) { }) } +func TestAccAzureRMStorageQueue_metaData(t *testing.T) { + resourceName := "azurerm_storage_queue.test" + ri := tf.AccRandTimeInt() + rs := strings.ToLower(acctest.RandString(11)) + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMStorageQueueDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageQueue_metaData(ri, rs, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageQueueExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAzureRMStorageQueue_metaDataUpdated(ri, rs, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageQueueExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testCheckAzureRMStorageQueueExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -196,7 +233,6 @@ func testAccAzureRMStorageQueue_basic(rInt int, rString string, location string) resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" - resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } `, template, rInt) @@ -209,12 +245,44 @@ func testAccAzureRMStorageQueue_requiresImport(rInt int, rString string, locatio resource "azurerm_storage_queue" "import" { name = "${azurerm_storage_queue.test.name}" - resource_group_name = "${azurerm_storage_queue.test.resource_group_name}" storage_account_name = "${azurerm_storage_queue.test.storage_account_name}" } `, template) } +func testAccAzureRMStorageQueue_metaData(rInt int, rString string, location string) string { + template := testAccAzureRMStorageQueue_template(rInt, rString, location) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_queue" "test" { + name = "mysamplequeue-%d" + storage_account_name = "${azurerm_storage_account.test.name}" + + metadata { + hello = "world" + } +} +`, template, rInt) +} + +func testAccAzureRMStorageQueue_metaDataUpdated(rInt int, rString string, location string) string { + template := testAccAzureRMStorageQueue_template(rInt, rString, location) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_queue" "test" { + name = "mysamplequeue-%d" + storage_account_name = "${azurerm_storage_account.test.name}" + + metadata { + hello = "world" + rick = "morty" + } +} +`, template, rInt) +} + func testAccAzureRMStorageQueue_template(rInt int, rString string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { diff --git a/website/docs/r/storage_queue.html.markdown b/website/docs/r/storage_queue.html.markdown index 17bf01f23364..e7da7ffebe98 100644 --- a/website/docs/r/storage_queue.html.markdown +++ b/website/docs/r/storage_queue.html.markdown @@ -37,13 +37,14 @@ resource "azurerm_storage_queue" "test" { The following arguments are supported: -* `name` - (Required) The name of the storage queue. Must be unique within the storage account the queue is located. +* `name` - (Required) The name of the Queue which should be created within the Storage Account. Must be unique within the storage account the queue is located. -* `storage_account_name` - (Required) Specifies the storage account in which to create the storage queue. - Changing this forces a new resource to be created. +* `storage_account_name` - (Required) Specifies the Storage Account in which the Storage Queue should exist. Changing this forces a new resource to be created. * `resource_group_name` - (Optional / **Deprecated**) The name of the resource group in which to create the storage queue. +* `metadata` - (Optional) A mapping of MetaData which should be assigned to this Storage Queue. + ## Attributes Reference The following attributes are exported in addition to the arguments listed above: From abf1c223f22f81fc02ccc075e82d9ccada269e15 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 11 Jul 2019 19:31:54 +0100 Subject: [PATCH 3/6] Switching to use the newly available function --- azurerm/resource_arm_storage_queue.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index b5e64974dd8d..2b08f2e16a51 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -41,16 +41,7 @@ func resourceArmStorageQueue() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - // TODO: switch to using the common deprecated RG name function - "resource_group_name": func() *schema.Schema { - s := azure.SchemaResourceGroupName() - s.Required = false - s.ForceNew = false - s.Optional = true - s.Computed = true - s.Deprecated = "This is no longer used and will be removed in 2.0" - return s - }(), + "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), "metadata": storage.MetaDataSchema(), From 51f15cbad6b4bf67004d65d7dac66a1e6dae35a1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 11 Jul 2019 19:33:14 +0100 Subject: [PATCH 4/6] Vendoring the Queues SDK from github.com/tombuildsstuff/giovanni --- .../2018-11-09/blob/containers/README.md | 45 ----- .../2018-11-09/blob/containers/create.go | 123 ------------ .../blob/containers/get_properties.go | 124 ------------ .../blob/containers/lease_acquire.go | 115 ----------- .../2018-11-09/blob/containers/lease_break.go | 129 ------------- .../blob/containers/lease_change.go | 111 ----------- .../blob/containers/lease_release.go | 92 --------- .../2018-11-09/blob/containers/lease_renew.go | 92 --------- .../2018-11-09/blob/containers/list_blobs.go | 179 ------------------ .../2018-11-09/blob/containers/models.go | 75 -------- .../2018-11-09/blob/containers/set_acl.go | 100 ---------- .../blob/containers/set_metadata.go | 105 ---------- .../storage/2018-11-09/queue/queues/README.md | 43 +++++ .../containers => queue/queues}/client.go | 15 +- .../storage/2018-11-09/queue/queues/create.go | 92 +++++++++ .../containers => queue/queues}/delete.go | 42 ++-- .../2018-11-09/queue/queues/metadata_get.go | 101 ++++++++++ .../2018-11-09/queue/queues/metadata_set.go | 97 ++++++++++ .../storage/2018-11-09/queue/queues/models.go | 42 ++++ .../2018-11-09/queue/queues/properties_get.go | 85 +++++++++ .../2018-11-09/queue/queues/properties_set.go | 80 ++++++++ .../queues}/resource_id.go | 26 +-- .../containers => queue/queues}/version.go | 2 +- vendor/modules.txt | 1 + 24 files changed, 579 insertions(+), 1337 deletions(-) delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go delete mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/README.md rename vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/{blob/containers => queue/queues}/client.go (50%) create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/create.go rename vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/{blob/containers => queue/queues}/delete.go (52%) create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_get.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_set.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/models.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_get.go create mode 100644 vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_set.go rename vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/{blob/containers => queue/queues}/resource_id.go (50%) rename vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/{blob/containers => queue/queues}/version.go (93%) diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md deleted file mode 100644 index 37d2878cc5ee..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/README.md +++ /dev/null @@ -1,45 +0,0 @@ -## Blob Storage Container SDK for API version 2018-11-09 - -This package allows you to interact with the Containers Blob Storage API - -### Supported Authorizers - -* Azure Active Directory (for the Resource Endpoint `https://storage.azure.com`) -* SharedKeyLite (Blob, File & Queue) - -Note: when using the `ListBlobs` operation, only `SharedKeyLite` authentication is supported. - -### Example Usage - -```go -package main - -import ( - "context" - "fmt" - "time" - - "github.com/Azure/go-autorest/autorest" - "github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers" -) - -func Example() error { - accountName := "storageaccount1" - storageAccountKey := "ABC123...." - containerName := "mycontainer" - - storageAuth := autorest.NewSharedKeyLiteAuthorizer(accountName, storageAccountKey) - containersClient := containers.New() - containersClient.Client.Authorizer = storageAuth - - ctx := context.TODO() - createInput := containers.CreateInput{ - AccessLevel: containers.Private, - } - if _, err := containersClient.Create(ctx, accountName, containerName, createInput); err != nil { - return fmt.Errorf("Error creating Container: %s", err) - } - - return nil -} -``` \ No newline at end of file diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go deleted file mode 100644 index 84c2887d7d1a..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/create.go +++ /dev/null @@ -1,123 +0,0 @@ -package containers - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" - "github.com/tombuildsstuff/giovanni/storage/internal/metadata" -) - -type CreateInput struct { - // Specifies whether data in the container may be accessed publicly and the level of access - AccessLevel AccessLevel - - // A name-value pair to associate with the container as metadata. - MetaData map[string]string -} - -type CreateResponse struct { - autorest.Response - Error *ErrorResponse `xml:"Error"` -} - -// Create creates a new container under the specified account. -// If the container with the same name already exists, the operation fails. -func (client Client) Create(ctx context.Context, accountName, containerName string, input CreateInput) (result CreateResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "Create", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "Create", "`containerName` cannot be an empty string.") - } - if err := metadata.Validate(input.MetaData); err != nil { - return result, validation.NewError("containers.Client", "Create", fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) - } - - req, err := client.CreatePreparer(ctx, accountName, containerName, input) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "Create", nil, "Failure preparing request") - return - } - - resp, err := client.CreateSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "Create", resp, "Failure sending request") - return - } - - result, err = client.CreateResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "Create", resp, "Failure responding to request") - return - } - - return -} - -// CreatePreparer prepares the Create request. -func (client Client) CreatePreparer(ctx context.Context, accountName string, containerName string, input CreateInput) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - } - - headers = client.setAccessLevelIntoHeaders(headers, input.AccessLevel) - headers = metadata.SetIntoHeaders(headers, input.MetaData) - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// CreateSender sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (client Client) CreateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// CreateResponder handles the response to the Create request. The method always -// closes the http.Response Body. -func (client Client) CreateResponder(resp *http.Response) (result CreateResponse, err error) { - successfulStatusCodes := []int{ - http.StatusCreated, - } - if autorest.ResponseHasStatusCode(resp, successfulStatusCodes...) { - // when successful there's no response - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(successfulStatusCodes...), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - } else { - // however when there's an error the error's in the response - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(successfulStatusCodes...), - autorest.ByUnmarshallingXML(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - } - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go deleted file mode 100644 index 1e308da67c55..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/get_properties.go +++ /dev/null @@ -1,124 +0,0 @@ -package containers - -import ( - "context" - "net/http" - "strings" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" - "github.com/tombuildsstuff/giovanni/storage/internal/metadata" -) - -// GetProperties returns the properties for this Container without a Lease -func (client Client) GetProperties(ctx context.Context, accountName, containerName string) (ContainerProperties, error) { - // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. - // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. - return client.GetPropertiesWithLeaseID(ctx, accountName, containerName, "") -} - -// GetPropertiesWithLeaseID returns the properties for this Container using the specified LeaseID -func (client Client) GetPropertiesWithLeaseID(ctx context.Context, accountName, containerName, leaseID string) (result ContainerProperties, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "GetPropertiesWithLeaseID", "`containerName` cannot be an empty string.") - } - - req, err := client.GetPropertiesWithLeaseIDPreparer(ctx, accountName, containerName, leaseID) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", nil, "Failure preparing request") - return - } - - resp, err := client.GetPropertiesWithLeaseIDSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", resp, "Failure sending request") - return - } - - result, err = client.GetPropertiesWithLeaseIDResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "GetProperties", resp, "Failure responding to request") - return - } - - return -} - -// GetPropertiesWithLeaseIDPreparer prepares the GetPropertiesWithLeaseID request. -func (client Client) GetPropertiesWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - } - - // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. - // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. - if leaseID != "" { - headers["x-ms-lease-id"] = leaseID - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetPropertiesWithLeaseIDSender sends the GetPropertiesWithLeaseID request. The method will close the -// http.Response Body if it receives an error. -func (client Client) GetPropertiesWithLeaseIDSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// GetPropertiesWithLeaseIDResponder handles the response to the GetPropertiesWithLeaseID request. The method always -// closes the http.Response Body. -func (client Client) GetPropertiesWithLeaseIDResponder(resp *http.Response) (result ContainerProperties, err error) { - if resp != nil { - result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status")) - result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state")) - if result.LeaseStatus == Locked { - duration := LeaseDuration(resp.Header.Get("x-ms-lease-duration")) - result.LeaseDuration = &duration - } - - // If this header is not returned in the response, the container is private to the account owner. - accessLevel := resp.Header.Get("x-ms-blob-public-access") - if accessLevel != "" { - result.AccessLevel = AccessLevel(accessLevel) - } else { - result.AccessLevel = Private - } - - // we can't necessarily use strconv.ParseBool here since this could be nil (only in some API versions) - result.HasImmutabilityPolicy = strings.EqualFold(resp.Header.Get("x-ms-has-immutability-policy"), "true") - result.HasLegalHold = strings.EqualFold(resp.Header.Get("x-ms-has-legal-hold"), "true") - - result.MetaData = metadata.ParseFromHeaders(resp.Header) - } - - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go deleted file mode 100644 index 061c863c43f9..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_acquire.go +++ /dev/null @@ -1,115 +0,0 @@ -package containers - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -type AcquireLeaseInput struct { - // Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - // A non-infinite lease can be between 15 and 60 seconds - LeaseDuration int - - ProposedLeaseID string -} - -type AcquireLeaseResponse struct { - autorest.Response - - LeaseID string -} - -// AcquireLease establishes and manages a lock on a container for delete operations. -func (client Client) AcquireLease(ctx context.Context, accountName, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "AcquireLease", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "AcquireLease", "`containerName` cannot be an empty string.") - } - // An infinite lease duration is -1 seconds. A non-infinite lease can be between 15 and 60 seconds - if input.LeaseDuration != -1 && (input.LeaseDuration <= 15 || input.LeaseDuration >= 60) { - return result, validation.NewError("containers.Client", "AcquireLease", "`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds.") - } - - req, err := client.AcquireLeasePreparer(ctx, accountName, containerName, input) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", nil, "Failure preparing request") - return - } - - resp, err := client.AcquireLeaseSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", resp, "Failure sending request") - return - } - - result, err = client.AcquireLeaseResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "AcquireLease", resp, "Failure responding to request") - return - } - - return -} - -// AcquireLeasePreparer prepares the AcquireLease request. -func (client Client) AcquireLeasePreparer(ctx context.Context, accountName string, containerName string, input AcquireLeaseInput) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - "comp": autorest.Encode("path", "lease"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - "x-ms-lease-action": "acquire", - "x-ms-lease-duration": input.LeaseDuration, - } - - if input.ProposedLeaseID != "" { - headers["x-ms-proposed-lease-id"] = input.ProposedLeaseID - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// AcquireLeaseSender sends the AcquireLease request. The method will close the -// http.Response Body if it receives an error. -func (client Client) AcquireLeaseSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// AcquireLeaseResponder handles the response to the AcquireLease request. The method always -// closes the http.Response Body. -func (client Client) AcquireLeaseResponder(resp *http.Response) (result AcquireLeaseResponse, err error) { - if resp != nil { - result.LeaseID = resp.Header.Get("x-ms-lease-id") - } - - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusCreated), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go deleted file mode 100644 index 08acfb7a3116..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_break.go +++ /dev/null @@ -1,129 +0,0 @@ -package containers - -import ( - "context" - "net/http" - "strconv" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -type BreakLeaseInput struct { - // For a break operation, proposed duration the lease should continue - // before it is broken, in seconds, between 0 and 60. - // This break period is only used if it is shorter than the time remaining on the lease. - // If longer, the time remaining on the lease is used. - // A new lease will not be available before the break period has expired, - // but the lease may be held for longer than the break period. - // If this header does not appear with a break operation, a fixed-duration lease breaks - // after the remaining lease period elapses, and an infinite lease breaks immediately. - BreakPeriod *int - - LeaseID string -} - -type BreakLeaseResponse struct { - autorest.Response - - // Approximate time remaining in the lease period, in seconds. - // If the break is immediate, 0 is returned. - LeaseTime int -} - -// BreakLease breaks a lock based on it's Lease ID -func (client Client) BreakLease(ctx context.Context, accountName, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "BreakLease", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "BreakLease", "`containerName` cannot be an empty string.") - } - if input.LeaseID == "" { - return result, validation.NewError("containers.Client", "BreakLease", "`input.LeaseID` cannot be an empty string.") - } - - req, err := client.BreakLeasePreparer(ctx, accountName, containerName, input) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", nil, "Failure preparing request") - return - } - - resp, err := client.BreakLeaseSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", resp, "Failure sending request") - return - } - - result, err = client.BreakLeaseResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "BreakLease", resp, "Failure responding to request") - return - } - - return -} - -// BreakLeasePreparer prepares the BreakLease request. -func (client Client) BreakLeasePreparer(ctx context.Context, accountName string, containerName string, input BreakLeaseInput) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - "comp": autorest.Encode("path", "lease"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - "x-ms-lease-action": "break", - "x-ms-lease-id": input.LeaseID, - } - - if input.BreakPeriod != nil { - headers["x-ms-lease-break-period"] = *input.BreakPeriod - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// BreakLeaseSender sends the BreakLease request. The method will close the -// http.Response Body if it receives an error. -func (client Client) BreakLeaseSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// BreakLeaseResponder handles the response to the BreakLease request. The method always -// closes the http.Response Body. -func (client Client) BreakLeaseResponder(resp *http.Response) (result BreakLeaseResponse, err error) { - if resp != nil { - leaseRaw := resp.Header.Get("x-ms-lease-time") - if leaseRaw != "" { - i, err := strconv.Atoi(leaseRaw) - if err == nil { - result.LeaseTime = i - } - } - } - - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusAccepted), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go deleted file mode 100644 index dfbcb132dae3..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_change.go +++ /dev/null @@ -1,111 +0,0 @@ -package containers - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -type ChangeLeaseInput struct { - ExistingLeaseID string - ProposedLeaseID string -} - -type ChangeLeaseResponse struct { - autorest.Response - - LeaseID string -} - -// ChangeLease changes the lock from one Lease ID to another Lease ID -func (client Client) ChangeLease(ctx context.Context, accountName, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ChangeLease", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "ChangeLease", "`containerName` cannot be an empty string.") - } - if input.ExistingLeaseID == "" { - return result, validation.NewError("containers.Client", "ChangeLease", "`input.ExistingLeaseID` cannot be an empty string.") - } - if input.ProposedLeaseID == "" { - return result, validation.NewError("containers.Client", "ChangeLease", "`input.ProposedLeaseID` cannot be an empty string.") - } - - req, err := client.ChangeLeasePreparer(ctx, accountName, containerName, input) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", nil, "Failure preparing request") - return - } - - resp, err := client.ChangeLeaseSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", resp, "Failure sending request") - return - } - - result, err = client.ChangeLeaseResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ChangeLease", resp, "Failure responding to request") - return - } - - return -} - -// ChangeLeasePreparer prepares the ChangeLease request. -func (client Client) ChangeLeasePreparer(ctx context.Context, accountName string, containerName string, input ChangeLeaseInput) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - "comp": autorest.Encode("path", "lease"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - "x-ms-lease-action": "change", - "x-ms-lease-id": input.ExistingLeaseID, - "x-ms-proposed-lease-id": input.ProposedLeaseID, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ChangeLeaseSender sends the ChangeLease request. The method will close the -// http.Response Body if it receives an error. -func (client Client) ChangeLeaseSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// ChangeLeaseResponder handles the response to the ChangeLease request. The method always -// closes the http.Response Body. -func (client Client) ChangeLeaseResponder(resp *http.Response) (result ChangeLeaseResponse, err error) { - if resp != nil { - result.LeaseID = resp.Header.Get("x-ms-lease-id") - } - - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go deleted file mode 100644 index fafcf98f1e67..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_release.go +++ /dev/null @@ -1,92 +0,0 @@ -package containers - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -// ReleaseLease releases the lock based on the Lease ID -func (client Client) ReleaseLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ReleaseLease", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "ReleaseLease", "`containerName` cannot be an empty string.") - } - if leaseID == "" { - return result, validation.NewError("containers.Client", "ReleaseLease", "`leaseID` cannot be an empty string.") - } - - req, err := client.ReleaseLeasePreparer(ctx, accountName, containerName, leaseID) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", nil, "Failure preparing request") - return - } - - resp, err := client.ReleaseLeaseSender(req) - if err != nil { - result = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", resp, "Failure sending request") - return - } - - result, err = client.ReleaseLeaseResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ReleaseLease", resp, "Failure responding to request") - return - } - - return -} - -// ReleaseLeasePreparer prepares the ReleaseLease request. -func (client Client) ReleaseLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - "comp": autorest.Encode("path", "lease"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - "x-ms-lease-action": "release", - "x-ms-lease-id": leaseID, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ReleaseLeaseSender sends the ReleaseLease request. The method will close the -// http.Response Body if it receives an error. -func (client Client) ReleaseLeaseSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// ReleaseLeaseResponder handles the response to the ReleaseLease request. The method always -// closes the http.Response Body. -func (client Client) ReleaseLeaseResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go deleted file mode 100644 index 3fe17656cd87..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/lease_renew.go +++ /dev/null @@ -1,92 +0,0 @@ -package containers - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -// RenewLease renewes the lock based on the Lease ID -func (client Client) RenewLease(ctx context.Context, accountName, containerName, leaseID string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "RenewLease", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "RenewLease", "`containerName` cannot be an empty string.") - } - if leaseID == "" { - return result, validation.NewError("containers.Client", "RenewLease", "`leaseID` cannot be an empty string.") - } - - req, err := client.RenewLeasePreparer(ctx, accountName, containerName, leaseID) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", nil, "Failure preparing request") - return - } - - resp, err := client.RenewLeaseSender(req) - if err != nil { - result = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure sending request") - return - } - - result, err = client.RenewLeaseResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "RenewLease", resp, "Failure responding to request") - return - } - - return -} - -// RenewLeasePreparer prepares the RenewLease request. -func (client Client) RenewLeasePreparer(ctx context.Context, accountName string, containerName string, leaseID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), - "comp": autorest.Encode("path", "lease"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - "x-ms-lease-action": "renew", - "x-ms-lease-id": leaseID, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// RenewLeaseSender sends the RenewLease request. The method will close the -// http.Response Body if it receives an error. -func (client Client) RenewLeaseSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// RenewLeaseResponder handles the response to the RenewLease request. The method always -// closes the http.Response Body. -func (client Client) RenewLeaseResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go deleted file mode 100644 index 82797d091d36..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/list_blobs.go +++ /dev/null @@ -1,179 +0,0 @@ -package containers - -import ( - "context" - "net/http" - "strings" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -type ListBlobsInput struct { - Delimiter *string - Include *[]Dataset - Marker *string - MaxResults *int - Prefix *string -} - -type ListBlobsResult struct { - autorest.Response - - Delimiter string `xml:"Delimiter"` - Marker string `xml:"Marker"` - MaxResults int `xml:"MaxResults"` - NextMarker *string `xml:"NextMarker,omitempty"` - Prefix string `xml:"Prefix"` - Blobs Blobs `xml:"Blobs"` -} - -type Blobs struct { - Blobs []BlobDetails `xml:"Blob"` - BlobPrefix *BlobPrefix `xml:"BlobPrefix"` -} - -type BlobDetails struct { - Name string `xml:"Name"` - Deleted bool `xml:"Deleted,omitempty"` - MetaData map[string]interface{} `map:"Metadata,omitempty"` - Properties *BlobProperties `xml:"Properties,omitempty"` - Snapshot *string `xml:"Snapshot,omitempty"` -} - -type BlobProperties struct { - AccessTier *string `xml:"AccessTier,omitempty"` - AccessTierInferred *bool `xml:"AccessTierInferred,omitempty"` - AccessTierChangeTime *string `xml:"AccessTierChangeTime,omitempty"` - BlobType *string `xml:"BlobType,omitempty"` - BlobSequenceNumber *string `xml:"x-ms-blob-sequence-number,omitempty"` - CacheControl *string `xml:"Cache-Control,omitempty"` - ContentEncoding *string `xml:"ContentEncoding,omitempty"` - ContentLanguage *string `xml:"Content-Language,omitempty"` - ContentLength *int64 `xml:"Content-Length,omitempty"` - ContentMD5 *string `xml:"Content-MD5,omitempty"` - ContentType *string `xml:"Content-Type,omitempty"` - CopyCompletionTime *string `xml:"CopyCompletionTime,omitempty"` - CopyId *string `xml:"CopyId,omitempty"` - CopyStatus *string `xml:"CopyStatus,omitempty"` - CopySource *string `xml:"CopySource,omitempty"` - CopyProgress *string `xml:"CopyProgress,omitempty"` - CopyStatusDescription *string `xml:"CopyStatusDescription,omitempty"` - CreationTime *string `xml:"CreationTime,omitempty"` - ETag *string `xml:"Etag,omitempty"` - DeletedTime *string `xml:"DeletedTime,omitempty"` - IncrementalCopy *bool `xml:"IncrementalCopy,omitempty"` - LastModified *string `xml:"Last-Modified,omitempty"` - LeaseDuration *string `xml:"LeaseDuration,omitempty"` - LeaseState *string `xml:"LeaseState,omitempty"` - LeaseStatus *string `xml:"LeaseStatus,omitempty"` - RemainingRetentionDays *string `xml:"RemainingRetentionDays,omitempty"` - ServerEncrypted *bool `xml:"ServerEncrypted,omitempty"` -} - -type BlobPrefix struct { - Name string `xml:"Name"` -} - -// ListBlobs lists the blobs matching the specified query within the specified Container -func (client Client) ListBlobs(ctx context.Context, accountName, containerName string, input ListBlobsInput) (result ListBlobsResult, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "ListBlobs", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "ListBlobs", "`containerName` cannot be an empty string.") - } - if input.MaxResults != nil && (*input.MaxResults <= 0 || *input.MaxResults > 5000) { - return result, validation.NewError("containers.Client", "ListBlobs", "`input.MaxResults` can either be nil or between 0 and 5000.") - } - - req, err := client.ListBlobsPreparer(ctx, accountName, containerName, input) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", nil, "Failure preparing request") - return - } - - resp, err := client.ListBlobsSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", resp, "Failure sending request") - return - } - - result, err = client.ListBlobsResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "ListBlobs", resp, "Failure responding to request") - return - } - - return -} - -// ListBlobsPreparer prepares the ListBlobs request. -func (client Client) ListBlobsPreparer(ctx context.Context, accountName, containerName string, input ListBlobsInput) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "comp": autorest.Encode("query", "list"), - "restype": autorest.Encode("query", "container"), - } - - if input.Delimiter != nil { - queryParameters["delimiter"] = autorest.Encode("query", *input.Delimiter) - } - if input.Include != nil { - vals := make([]string, 0) - for _, v := range *input.Include { - vals = append(vals, string(v)) - } - include := strings.Join(vals, ",") - queryParameters["include"] = autorest.Encode("query", include) - } - if input.Marker != nil { - queryParameters["marker"] = autorest.Encode("query", *input.Marker) - } - if input.MaxResults != nil { - queryParameters["maxresults"] = autorest.Encode("query", *input.MaxResults) - } - if input.Prefix != nil { - queryParameters["prefix"] = autorest.Encode("query", *input.Prefix) - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListBlobsSender sends the ListBlobs request. The method will close the -// http.Response Body if it receives an error. -func (client Client) ListBlobsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// ListBlobsResponder handles the response to the ListBlobs request. The method always -// closes the http.Response Body. -func (client Client) ListBlobsResponder(resp *http.Response) (result ListBlobsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingXML(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go deleted file mode 100644 index adba36818aa1..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/models.go +++ /dev/null @@ -1,75 +0,0 @@ -package containers - -import "github.com/Azure/go-autorest/autorest" - -type AccessLevel string - -var ( - // Blob specifies public read access for blobs. - // Blob data within this container can be read via anonymous request, - // but container data is not available. - // Clients cannot enumerate blobs within the container via anonymous request. - Blob AccessLevel = "blob" - - // Container specifies full public read access for container and blob data. - // Clients can enumerate blobs within the container via anonymous request, - // but cannot enumerate containers within the storage account. - Container AccessLevel = "container" - - // Private specifies that container data is private to the account owner - Private AccessLevel = "" -) - -type ContainerProperties struct { - autorest.Response - - AccessLevel AccessLevel - LeaseStatus LeaseStatus - LeaseState LeaseState - LeaseDuration *LeaseDuration - MetaData map[string]string - HasImmutabilityPolicy bool - HasLegalHold bool -} - -type Dataset string - -var ( - Copy Dataset = "copy" - Deleted Dataset = "deleted" - MetaData Dataset = "metadata" - Snapshots Dataset = "snapshots" - UncommittedBlobs Dataset = "uncommittedblobs" -) - -type ErrorResponse struct { - Code *string `xml:"Code"` - Message *string `xml:"Message"` -} - -type LeaseDuration string - -var ( - // If this lease is for a Fixed Duration - Fixed LeaseDuration = "fixed" - - // If this lease is for an Indefinite Duration - Infinite LeaseDuration = "infinite" -) - -type LeaseState string - -var ( - Available LeaseState = "available" - Breaking LeaseState = "breaking" - Broken LeaseState = "broken" - Expired LeaseState = "expired" - Leased LeaseState = "leased" -) - -type LeaseStatus string - -var ( - Locked LeaseStatus = "locked" - Unlocked LeaseStatus = "unlocked" -) diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go deleted file mode 100644 index fcf4e1056fa4..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_acl.go +++ /dev/null @@ -1,100 +0,0 @@ -package containers - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" -) - -// SetAccessControl sets the Access Control for a Container without a Lease ID -func (client Client) SetAccessControl(ctx context.Context, accountName, containerName string, level AccessLevel) (autorest.Response, error) { - return client.SetAccessControlWithLeaseID(ctx, accountName, containerName, "", level) -} - -// SetAccessControlWithLeaseID sets the Access Control for a Container using the specified Lease ID -func (client Client) SetAccessControlWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "SetAccessControl", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "SetAccessControl", "`containerName` cannot be an empty string.") - } - - req, err := client.SetAccessControlWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, level) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", nil, "Failure preparing request") - return - } - - resp, err := client.SetAccessControlWithLeaseIDSender(req) - if err != nil { - result = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", resp, "Failure sending request") - return - } - - result, err = client.SetAccessControlWithLeaseIDResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "SetAccessControl", resp, "Failure responding to request") - return - } - - return -} - -// SetAccessControlWithLeaseIDPreparer prepares the SetAccessControlWithLeaseID request. -func (client Client) SetAccessControlWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, level AccessLevel) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "comp": autorest.Encode("path", "acl"), - "restype": autorest.Encode("path", "container"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - } - - headers = client.setAccessLevelIntoHeaders(headers, level) - - // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. - // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. - if leaseID != "" { - headers["x-ms-lease-id"] = leaseID - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// SetAccessControlWithLeaseIDSender sends the SetAccessControlWithLeaseID request. The method will close the -// http.Response Body if it receives an error. -func (client Client) SetAccessControlWithLeaseIDSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// SetAccessControlWithLeaseIDResponder handles the response to the SetAccessControlWithLeaseID request. The method always -// closes the http.Response Body. -func (client Client) SetAccessControlWithLeaseIDResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go deleted file mode 100644 index fb9e07fdefa9..000000000000 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/set_metadata.go +++ /dev/null @@ -1,105 +0,0 @@ -package containers - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" - "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" - "github.com/tombuildsstuff/giovanni/storage/internal/metadata" -) - -// SetMetaData sets the specified MetaData on the Container without a Lease ID -func (client Client) SetMetaData(ctx context.Context, accountName, containerName string, metaData map[string]string) (autorest.Response, error) { - return client.SetMetaDataWithLeaseID(ctx, accountName, containerName, "", metaData) -} - -// SetMetaDataWithLeaseID sets the specified MetaData on the Container using the specified Lease ID -func (client Client) SetMetaDataWithLeaseID(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (result autorest.Response, err error) { - if accountName == "" { - return result, validation.NewError("containers.Client", "SetMetaData", "`accountName` cannot be an empty string.") - } - if containerName == "" { - return result, validation.NewError("containers.Client", "SetMetaData", "`containerName` cannot be an empty string.") - } - if err := metadata.Validate(metaData); err != nil { - return result, validation.NewError("containers.Client", "SetMetaData", fmt.Sprintf("`metaData` is not valid: %s.", err)) - } - - req, err := client.SetMetaDataWithLeaseIDPreparer(ctx, accountName, containerName, leaseID, metaData) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", nil, "Failure preparing request") - return - } - - resp, err := client.SetMetaDataWithLeaseIDSender(req) - if err != nil { - result = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", resp, "Failure sending request") - return - } - - result, err = client.SetMetaDataWithLeaseIDResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "SetMetaData", resp, "Failure responding to request") - return - } - - return -} - -// SetMetaDataWithLeaseIDPreparer prepares the SetMetaDataWithLeaseID request. -func (client Client) SetMetaDataWithLeaseIDPreparer(ctx context.Context, accountName, containerName, leaseID string, metaData map[string]string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "comp": autorest.Encode("path", "metadata"), - "restype": autorest.Encode("path", "container"), - } - - headers := map[string]interface{}{ - "x-ms-version": APIVersion, - } - - headers = metadata.SetIntoHeaders(headers, metaData) - - // If specified, Get Container Properties only succeeds if the container’s lease is active and matches this ID. - // If there is no active lease or the ID does not match, 412 (Precondition Failed) is returned. - if leaseID != "" { - headers["x-ms-lease-id"] = leaseID - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/xml; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), - autorest.WithHeaders(headers)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// SetMetaDataWithLeaseIDSender sends the SetMetaDataWithLeaseID request. The method will close the -// http.Response Body if it receives an error. -func (client Client) SetMetaDataWithLeaseIDSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - azure.DoRetryWithRegistration(client.Client)) -} - -// SetMetaDataWithLeaseIDResponder handles the response to the SetMetaDataWithLeaseID request. The method always -// closes the http.Response Body. -func (client Client) SetMetaDataWithLeaseIDResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByClosing()) - result = autorest.Response{Response: resp} - - return -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/README.md b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/README.md new file mode 100644 index 000000000000..1769bfa56c39 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/README.md @@ -0,0 +1,43 @@ +## Queue Storage Queues SDK for API version 2018-11-09 + +This package allows you to interact with the Queues Queue Storage API + +### Supported Authorizers + +* Azure Active Directory (for the Resource Endpoint `https://storage.azure.com`) +* SharedKeyLite (Blob, File & Queue) + +### Example Usage + +```go +package main + +import ( + "context" + "fmt" + "time" + + "github.com/Azure/go-autorest/autorest" + "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" +) + +func Example() error { + accountName := "storageaccount1" + storageAccountKey := "ABC123...." + queueName := "myqueue" + + storageAuth := autorest.NewSharedKeyLiteAuthorizer(accountName, storageAccountKey) + queuesClient := queues.New() + queuesClient.Client.Authorizer = storageAuth + + ctx := context.TODO() + metadata := map[string]string{ + "hello": "world", + } + if _, err := queuesClient.Create(ctx, accountName, queueName, metadata); err != nil { + return fmt.Errorf("Error creating Queue: %s", err) + } + + return nil +} +``` \ No newline at end of file diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/client.go similarity index 50% rename from vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go rename to vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/client.go index 7bf494734484..2f8008582b93 100644 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/client.go +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/client.go @@ -1,11 +1,11 @@ -package containers +package queues import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" ) -// Client is the base client for Blob Storage Containers. +// Client is the base client for Queue Storage Shares. type Client struct { autorest.Client BaseURI string @@ -16,19 +16,10 @@ func New() Client { return NewWithEnvironment(azure.PublicCloud) } -// NewWithBaseURI creates an instance of the Client client. +// NewWithEnvironment creates an instance of the Client client. func NewWithEnvironment(environment azure.Environment) Client { return Client{ Client: autorest.NewClientWithUserAgent(UserAgent()), BaseURI: environment.StorageEndpointSuffix, } } - -func (client Client) setAccessLevelIntoHeaders(headers map[string]interface{}, level AccessLevel) map[string]interface{} { - // If this header is not included in the request, container data is private to the account owner. - if level != Private { - headers["x-ms-blob-public-access"] = string(level) - } - - return headers -} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/create.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/create.go new file mode 100644 index 000000000000..f18910a88d9e --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/create.go @@ -0,0 +1,92 @@ +package queues + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +// Create creates the specified Queue within the specified Storage Account +func (client Client) Create(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("queues.Client", "Create", "`accountName` cannot be an empty string.") + } + if queueName == "" { + return result, validation.NewError("queues.Client", "Create", "`queueName` cannot be an empty string.") + } + if strings.ToLower(queueName) != queueName { + return result, validation.NewError("queues.Client", "Create", "`queueName` must be a lower-cased string.") + } + if err := metadata.Validate(metaData); err != nil { + return result, validation.NewError("queues.Client", "Create", fmt.Sprintf("`metadata` is not valid: %s.", err)) + } + + req, err := client.CreatePreparer(ctx, accountName, queueName, metaData) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client Client) CreatePreparer(ctx context.Context, accountName string, queueName string, metaData map[string]string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "queueName": autorest.Encode("path", queueName), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + headers = metadata.SetIntoHeaders(headers, metaData) + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{queueName}", pathParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client Client) CreateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client Client) CreateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusCreated), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/delete.go similarity index 52% rename from vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go rename to vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/delete.go index 30958295388e..5f705959c446 100644 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/delete.go +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/delete.go @@ -1,8 +1,9 @@ -package containers +package queues import ( "context" "net/http" + "strings" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" @@ -10,31 +11,34 @@ import ( "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" ) -// Delete marks the specified container for deletion. -// The container and any blobs contained within it are later deleted during garbage collection. -func (client Client) Delete(ctx context.Context, accountName, containerName string) (result autorest.Response, err error) { +// Delete deletes the specified Queue within the specified Storage Account +func (client Client) Delete(ctx context.Context, accountName, queueName string) (result autorest.Response, err error) { if accountName == "" { - return result, validation.NewError("containers.Client", "Delete", "`accountName` cannot be an empty string.") + return result, validation.NewError("queues.Client", "Delete", "`accountName` cannot be an empty string.") } - if containerName == "" { - return result, validation.NewError("containers.Client", "Delete", "`containerName` cannot be an empty string.") + if queueName == "" { + return result, validation.NewError("queues.Client", "Delete", "`queueName` cannot be an empty string.") + } + if strings.ToLower(queueName) != queueName { + return result, validation.NewError("queues.Client", "Delete", "`queueName` must be a lower-cased string.") } - req, err := client.DeletePreparer(ctx, accountName, containerName) + req, err := client.DeletePreparer(ctx, accountName, queueName) if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "Delete", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "queues.Client", "Delete", nil, "Failure preparing request") return } resp, err := client.DeleteSender(req) if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "Delete", resp, "Failure sending request") + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "Delete", resp, "Failure sending request") return } result, err = client.DeleteResponder(resp) if err != nil { - err = autorest.NewErrorWithError(err, "containers.Client", "Delete", resp, "Failure responding to request") + err = autorest.NewErrorWithError(err, "queues.Client", "Delete", resp, "Failure responding to request") return } @@ -42,13 +46,9 @@ func (client Client) Delete(ctx context.Context, accountName, containerName stri } // DeletePreparer prepares the Delete request. -func (client Client) DeletePreparer(ctx context.Context, accountName string, containerName string) (*http.Request, error) { +func (client Client) DeletePreparer(ctx context.Context, accountName string, queueName string) (*http.Request, error) { pathParameters := map[string]interface{}{ - "containerName": autorest.Encode("path", containerName), - } - - queryParameters := map[string]interface{}{ - "restype": autorest.Encode("path", "container"), + "queueName": autorest.Encode("path", queueName), } headers := map[string]interface{}{ @@ -58,9 +58,8 @@ func (client Client) DeletePreparer(ctx context.Context, accountName string, con preparer := autorest.CreatePreparer( autorest.AsContentType("application/xml; charset=utf-8"), autorest.AsDelete(), - autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), - autorest.WithPathParameters("/{containerName}", pathParameters), - autorest.WithQueryParameters(queryParameters), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{queueName}", pathParameters), autorest.WithHeaders(headers)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } @@ -78,8 +77,9 @@ func (client Client) DeleteResponder(resp *http.Response) (result autorest.Respo err = autorest.Respond( resp, client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusAccepted), + azure.WithErrorUnlessStatusCode(http.StatusNoContent), autorest.ByClosing()) result = autorest.Response{Response: resp} + return } diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_get.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_get.go new file mode 100644 index 000000000000..9c230b613ad3 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_get.go @@ -0,0 +1,101 @@ +package queues + +import ( + "context" + "net/http" + "strings" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +type GetMetaDataResult struct { + autorest.Response + + MetaData map[string]string +} + +// GetMetaData returns the metadata for this Queue +func (client Client) GetMetaData(ctx context.Context, accountName, queueName string) (result GetMetaDataResult, err error) { + if accountName == "" { + return result, validation.NewError("queues.Client", "GetMetaData", "`accountName` cannot be an empty string.") + } + if queueName == "" { + return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` cannot be an empty string.") + } + if strings.ToLower(queueName) != queueName { + return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` must be a lower-cased string.") + } + + req, err := client.GetMetaDataPreparer(ctx, accountName, queueName) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", nil, "Failure preparing request") + return + } + + resp, err := client.GetMetaDataSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", resp, "Failure sending request") + return + } + + result, err = client.GetMetaDataResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", resp, "Failure responding to request") + return + } + + return +} + +// GetMetaDataPreparer prepares the GetMetaData request. +func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, queueName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "queueName": autorest.Encode("path", queueName), + } + + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "metadata"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{queueName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetMetaDataSender sends the GetMetaData request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetMetaDataSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetMetaDataResponder handles the response to the GetMetaData request. The method always +// closes the http.Response Body. +func (client Client) GetMetaDataResponder(resp *http.Response) (result GetMetaDataResult, err error) { + if resp != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_set.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_set.go new file mode 100644 index 000000000000..51154a5c4334 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/metadata_set.go @@ -0,0 +1,97 @@ +package queues + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" + "github.com/tombuildsstuff/giovanni/storage/internal/metadata" +) + +// SetMetaData returns the metadata for this Queue +func (client Client) SetMetaData(ctx context.Context, accountName, queueName string, metaData map[string]string) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("queues.Client", "SetMetaData", "`accountName` cannot be an empty string.") + } + if queueName == "" { + return result, validation.NewError("queues.Client", "SetMetaData", "`queueName` cannot be an empty string.") + } + if strings.ToLower(queueName) != queueName { + return result, validation.NewError("queues.Client", "SetMetaData", "`queueName` must be a lower-cased string.") + } + if err := metadata.Validate(metaData); err != nil { + return result, validation.NewError("queues.Client", "SetMetaData", fmt.Sprintf("`metadata` is not valid: %s.", err)) + } + + req, err := client.SetMetaDataPreparer(ctx, accountName, queueName, metaData) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetMetaData", nil, "Failure preparing request") + return + } + + resp, err := client.SetMetaDataSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "SetMetaData", resp, "Failure sending request") + return + } + + result, err = client.SetMetaDataResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetMetaData", resp, "Failure responding to request") + return + } + + return +} + +// SetMetaDataPreparer prepares the SetMetaData request. +func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, queueName string, metaData map[string]string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "queueName": autorest.Encode("path", queueName), + } + + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "metadata"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + headers = metadata.SetIntoHeaders(headers, metaData) + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithPathParameters("/{queueName}", pathParameters), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SetMetaDataSender sends the SetMetaData request. The method will close the +// http.Response Body if it receives an error. +func (client Client) SetMetaDataSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// SetMetaDataResponder handles the response to the SetMetaData request. The method always +// closes the http.Response Body. +func (client Client) SetMetaDataResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusNoContent), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/models.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/models.go new file mode 100644 index 000000000000..89c23801279e --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/models.go @@ -0,0 +1,42 @@ +package queues + +type StorageServiceProperties struct { + Logging *LoggingConfig `xml:"Logging,omitempty"` + HourMetrics *MetricsConfig `xml:"HourMetrics,omitempty"` + MinuteMetrics *MetricsConfig `xml:"MinuteMetrics,omitempty"` + Cors *Cors `xml:"Cors,omitempty"` +} + +type LoggingConfig struct { + Version string `xml:"Version"` + Delete bool `xml:"Delete"` + Read bool `xml:"Read"` + Write bool `xml:"Write"` + RetentionPolicy RetentionPolicy `xml:"RetentionPolicy"` +} + +type MetricsConfig struct { + Version string `xml:"Version"` + Enabled bool `xml:"Enabled"` + RetentionPolicy RetentionPolicy `xml:"RetentionPolicy"` + + // Element IncludeAPIs is only expected when Metrics is enabled + IncludeAPIs *bool `xml:"IncludeAPIs,omitempty"` +} + +type RetentionPolicy struct { + Enabled bool `xml:"Enabled"` + Days int `xml:"Days"` +} + +type Cors struct { + CorsRule CorsRule `xml:"CorsRule"` +} + +type CorsRule struct { + AllowedOrigins string `xml:"AllowedOrigins"` + AllowedMethods string `xml:"AllowedMethods"` + AllowedHeaders string `xml:"AllowedHeaders` + ExposedHeaders string `xml:"ExposedHeaders"` + MaxAgeInSeconds int `xml:"MaxAgeInSeconds"` +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_get.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_get.go new file mode 100644 index 000000000000..9d17fb2d2a59 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_get.go @@ -0,0 +1,85 @@ +package queues + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +type StorageServicePropertiesResponse struct { + StorageServiceProperties + autorest.Response +} + +// SetServiceProperties gets the properties for this queue +func (client Client) GetServiceProperties(ctx context.Context, accountName string) (result StorageServicePropertiesResponse, err error) { + if accountName == "" { + return result, validation.NewError("queues.Client", "SetServiceProperties", "`accountName` cannot be an empty string.") + } + + req, err := client.GetServicePropertiesPreparer(ctx, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetServicePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure sending request") + return + } + + result, err = client.GetServicePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetServicePropertiesPreparer prepares the GetServiceProperties request. +func (client Client) GetServicePropertiesPreparer(ctx context.Context, accountName string) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "properties"), + "restype": autorest.Encode("path", "service"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithQueryParameters(queryParameters), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetServicePropertiesSender sends the GetServiceProperties request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetServicePropertiesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetServicePropertiesResponder handles the response to the GetServiceProperties request. The method always +// closes the http.Response Body. +func (client Client) GetServicePropertiesResponder(resp *http.Response) (result StorageServicePropertiesResponse, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingXML(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_set.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_set.go new file mode 100644 index 000000000000..d6f639245d03 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/properties_set.go @@ -0,0 +1,80 @@ +package queues + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" +) + +// SetServiceProperties sets the properties for this queue +func (client Client) SetServiceProperties(ctx context.Context, accountName string, properties StorageServiceProperties) (result autorest.Response, err error) { + if accountName == "" { + return result, validation.NewError("queues.Client", "SetServiceProperties", "`accountName` cannot be an empty string.") + } + + req, err := client.SetServicePropertiesPreparer(ctx, accountName, properties) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", nil, "Failure preparing request") + return + } + + resp, err := client.SetServicePropertiesSender(req) + if err != nil { + result = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure sending request") + return + } + + result, err = client.SetServicePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure responding to request") + return + } + + return +} + +// SetServicePropertiesPreparer prepares the SetServiceProperties request. +func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountName string, properties StorageServiceProperties) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "comp": autorest.Encode("path", "properties"), + "restype": autorest.Encode("path", "service"), + } + + headers := map[string]interface{}{ + "x-ms-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/xml; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), + autorest.WithQueryParameters(queryParameters), + autorest.WithXML(properties), + autorest.WithHeaders(headers)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SetServicePropertiesSender sends the SetServiceProperties request. The method will close the +// http.Response Body if it receives an error. +func (client Client) SetServicePropertiesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// SetServicePropertiesResponder handles the response to the SetServiceProperties request. The method always +// closes the http.Response Body. +func (client Client) SetServicePropertiesResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusAccepted), + autorest.ByClosing()) + result = autorest.Response{Response: resp} + + return +} diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/resource_id.go similarity index 50% rename from vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go rename to vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/resource_id.go index 651dd84aed55..912923abca0d 100644 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/resource_id.go +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/resource_id.go @@ -1,4 +1,4 @@ -package containers +package queues import ( "fmt" @@ -8,22 +8,22 @@ import ( "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" ) -// GetResourceID returns the Resource ID for the given Container +// GetResourceID returns the Resource ID for the given Queue // This can be useful when, for example, you're using this as a unique identifier -func (client Client) GetResourceID(accountName, containerName string) string { - domain := endpoints.GetBlobEndpoint(client.BaseURI, accountName) - return fmt.Sprintf("%s/%s", domain, containerName) +func (client Client) GetResourceID(accountName, queueName string) string { + domain := endpoints.GetQueueEndpoint(client.BaseURI, accountName) + return fmt.Sprintf("%s/%s", domain, queueName) } type ResourceID struct { - AccountName string - ContainerName string + AccountName string + QueueName string } -// ParseResourceID parses the Resource ID and returns an object which can be used -// to interact with the Container Resource +// ParseResourceID parses the Resource ID and returns an Object which +// can be used to interact with a Queue within a Storage Account func ParseResourceID(id string) (*ResourceID, error) { - // example: https://foo.blob.core.windows.net/Bar + // example: https://foo.queue.core.windows.net/Bar if id == "" { return nil, fmt.Errorf("`id` was empty") } @@ -38,9 +38,9 @@ func ParseResourceID(id string) (*ResourceID, error) { return nil, fmt.Errorf("Error parsing Account Name: %s", err) } - containerName := strings.TrimPrefix(uri.Path, "/") + queueName := strings.TrimPrefix(uri.Path, "/") return &ResourceID{ - AccountName: *accountName, - ContainerName: containerName, + AccountName: *accountName, + QueueName: queueName, }, nil } diff --git a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/version.go similarity index 93% rename from vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go rename to vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/version.go index 7047f301b179..13c7d2fcd0ba 100644 --- a/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers/version.go +++ b/vendor/github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues/version.go @@ -1,4 +1,4 @@ -package containers +package queues import ( "fmt" diff --git a/vendor/modules.txt b/vendor/modules.txt index a33146422433..06b81aa87350 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -342,6 +342,7 @@ github.com/terraform-providers/terraform-provider-azuread/version github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/directories github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares +github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues github.com/tombuildsstuff/giovanni/storage/internal/endpoints github.com/tombuildsstuff/giovanni/storage/internal/metadata github.com/tombuildsstuff/giovanni/version From 38878fe688e70e67f95bde464c353f50466320da Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 11 Jul 2019 19:51:27 +0100 Subject: [PATCH 5/6] fixing the tests --- azurerm/resource_arm_storage_queue.go | 2 +- azurerm/resource_arm_storage_queue_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index 2b08f2e16a51..456ed7938169 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -152,7 +152,7 @@ func resourceArmStorageQueueUpdate(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error setting MetaData for Queue %q (Storage Account %q): %s", id.QueueName, id.AccountName, err) } - return resourceArmStorageQueueRead(d, metaDataRaw) + return resourceArmStorageQueueRead(d, meta) } func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_storage_queue_test.go b/azurerm/resource_arm_storage_queue_test.go index 655d133c30de..3717237cfaef 100644 --- a/azurerm/resource_arm_storage_queue_test.go +++ b/azurerm/resource_arm_storage_queue_test.go @@ -259,7 +259,7 @@ resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" storage_account_name = "${azurerm_storage_account.test.name}" - metadata { + metadata = { hello = "world" } } @@ -275,7 +275,7 @@ resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" storage_account_name = "${azurerm_storage_account.test.name}" - metadata { + metadata = { hello = "world" rick = "morty" } From afb8ee147d6c87fabbee5a9ee3c1d2b4d67495ee Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 12 Jul 2019 08:12:11 +0100 Subject: [PATCH 6/6] Fixing PR comments --- azurerm/resource_arm_storage_queue.go | 5 ++--- azurerm/resource_arm_storage_queue_test.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index 456ed7938169..c4b4618cff5b 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" @@ -38,7 +37,7 @@ func resourceArmStorageQueue() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, + ValidateFunc: validateArmStorageAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), @@ -113,7 +112,7 @@ func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) err } } - if _, err := client.Create(ctx, accountName, accountName, metaData); err != nil { + if _, err := client.Create(ctx, accountName, queueName, metaData); err != nil { return fmt.Errorf("Error creating Queue %q (Account %q): %+v", queueName, accountName, err) } diff --git a/azurerm/resource_arm_storage_queue_test.go b/azurerm/resource_arm_storage_queue_test.go index 3717237cfaef..5a6945d49779 100644 --- a/azurerm/resource_arm_storage_queue_test.go +++ b/azurerm/resource_arm_storage_queue_test.go @@ -277,7 +277,7 @@ resource "azurerm_storage_queue" "test" { metadata = { hello = "world" - rick = "morty" + rick = "M0rty" } } `, template, rInt)