From cef9f95d90f698798358704db15e8fe628864d4f Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Wed, 12 Jun 2019 11:46:05 -0700 Subject: [PATCH] Generated from ce8723ebeced362009ad903d0279b8e1e8ef30cb (#4997) Fix List containers --- .../latest/storage/mgmt/storage/models.go | 14 +- .../preview/storage/mgmt/storage/models.go | 14 +- .../mgmt/2019-04-01/storage/blobcontainers.go | 48 +++++- .../storage/mgmt/2019-04-01/storage/models.go | 139 ++++++++++++++++++ .../storage/storageapi/interfaces.go | 2 +- 5 files changed, 209 insertions(+), 8 deletions(-) diff --git a/profiles/latest/storage/mgmt/storage/models.go b/profiles/latest/storage/mgmt/storage/models.go index cbe62c5e4522..b97e84109424 100644 --- a/profiles/latest/storage/mgmt/storage/models.go +++ b/profiles/latest/storage/mgmt/storage/models.go @@ -19,7 +19,11 @@ package storage -import original "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" +import ( + "context" + + original "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" +) const ( DefaultBaseURI = original.DefaultBaseURI @@ -322,6 +326,8 @@ type LegalHoldProperties = original.LegalHoldProperties type ListAccountSasResponse = original.ListAccountSasResponse type ListContainerItem = original.ListContainerItem type ListContainerItems = original.ListContainerItems +type ListContainerItemsIterator = original.ListContainerItemsIterator +type ListContainerItemsPage = original.ListContainerItemsPage type ListServiceSasResponse = original.ListServiceSasResponse type ManagementPoliciesClient = original.ManagementPoliciesClient type ManagementPolicy = original.ManagementPolicy @@ -379,6 +385,12 @@ func NewBlobServicesClient(subscriptionID string) BlobServicesClient { func NewBlobServicesClientWithBaseURI(baseURI string, subscriptionID string) BlobServicesClient { return original.NewBlobServicesClientWithBaseURI(baseURI, subscriptionID) } +func NewListContainerItemsIterator(page ListContainerItemsPage) ListContainerItemsIterator { + return original.NewListContainerItemsIterator(page) +} +func NewListContainerItemsPage(getNextPage func(context.Context, ListContainerItems) (ListContainerItems, error)) ListContainerItemsPage { + return original.NewListContainerItemsPage(getNextPage) +} func NewManagementPoliciesClient(subscriptionID string) ManagementPoliciesClient { return original.NewManagementPoliciesClient(subscriptionID) } diff --git a/profiles/preview/storage/mgmt/storage/models.go b/profiles/preview/storage/mgmt/storage/models.go index 815089d8808d..25cbf490e4b5 100644 --- a/profiles/preview/storage/mgmt/storage/models.go +++ b/profiles/preview/storage/mgmt/storage/models.go @@ -19,7 +19,11 @@ package storage -import original "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" +import ( + "context" + + original "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" +) const ( DefaultBaseURI = original.DefaultBaseURI @@ -322,6 +326,8 @@ type LegalHoldProperties = original.LegalHoldProperties type ListAccountSasResponse = original.ListAccountSasResponse type ListContainerItem = original.ListContainerItem type ListContainerItems = original.ListContainerItems +type ListContainerItemsIterator = original.ListContainerItemsIterator +type ListContainerItemsPage = original.ListContainerItemsPage type ListServiceSasResponse = original.ListServiceSasResponse type ManagementPoliciesClient = original.ManagementPoliciesClient type ManagementPolicy = original.ManagementPolicy @@ -379,6 +385,12 @@ func NewBlobServicesClient(subscriptionID string) BlobServicesClient { func NewBlobServicesClientWithBaseURI(baseURI string, subscriptionID string) BlobServicesClient { return original.NewBlobServicesClientWithBaseURI(baseURI, subscriptionID) } +func NewListContainerItemsIterator(page ListContainerItemsPage) ListContainerItemsIterator { + return original.NewListContainerItemsIterator(page) +} +func NewListContainerItemsPage(getNextPage func(context.Context, ListContainerItems) (ListContainerItems, error)) ListContainerItemsPage { + return original.NewListContainerItemsPage(getNextPage) +} func NewManagementPoliciesClient(subscriptionID string) ManagementPoliciesClient { return original.NewManagementPoliciesClient(subscriptionID) } diff --git a/services/storage/mgmt/2019-04-01/storage/blobcontainers.go b/services/storage/mgmt/2019-04-01/storage/blobcontainers.go index 5154fd603f93..d6a603eef293 100644 --- a/services/storage/mgmt/2019-04-01/storage/blobcontainers.go +++ b/services/storage/mgmt/2019-04-01/storage/blobcontainers.go @@ -1020,13 +1020,13 @@ func (client BlobContainersClient) LeaseResponder(resp *http.Response) (result L // skipToken - optional. Continuation token for the list operation. // maxpagesize - optional. Specified maximum number of containers that can be included in the list. // filter - optional. When specified, only container names starting with the filter will be listed. -func (client BlobContainersClient) List(ctx context.Context, resourceGroupName string, accountName string, skipToken string, maxpagesize string, filter string) (result ListContainerItems, err error) { +func (client BlobContainersClient) List(ctx context.Context, resourceGroupName string, accountName string, skipToken string, maxpagesize string, filter string) (result ListContainerItemsPage, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/BlobContainersClient.List") defer func() { sc := -1 - if result.Response.Response != nil { - sc = result.Response.Response.StatusCode + if result.lci.Response.Response != nil { + sc = result.lci.Response.Response.StatusCode } tracing.EndSpan(ctx, sc, err) }() @@ -1044,6 +1044,7 @@ func (client BlobContainersClient) List(ctx context.Context, resourceGroupName s return result, validation.NewError("storage.BlobContainersClient", "List", err.Error()) } + result.fn = client.listNextResults req, err := client.ListPreparer(ctx, resourceGroupName, accountName, skipToken, maxpagesize, filter) if err != nil { err = autorest.NewErrorWithError(err, "storage.BlobContainersClient", "List", nil, "Failure preparing request") @@ -1052,12 +1053,12 @@ func (client BlobContainersClient) List(ctx context.Context, resourceGroupName s resp, err := client.ListSender(req) if err != nil { - result.Response = autorest.Response{Response: resp} + result.lci.Response = autorest.Response{Response: resp} err = autorest.NewErrorWithError(err, "storage.BlobContainersClient", "List", resp, "Failure sending request") return } - result, err = client.ListResponder(resp) + result.lci, err = client.ListResponder(resp) if err != nil { err = autorest.NewErrorWithError(err, "storage.BlobContainersClient", "List", resp, "Failure responding to request") } @@ -1115,6 +1116,43 @@ func (client BlobContainersClient) ListResponder(resp *http.Response) (result Li return } +// listNextResults retrieves the next set of results, if any. +func (client BlobContainersClient) listNextResults(ctx context.Context, lastResults ListContainerItems) (result ListContainerItems, err error) { + req, err := lastResults.listContainerItemsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "storage.BlobContainersClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "storage.BlobContainersClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobContainersClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client BlobContainersClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string, skipToken string, maxpagesize string, filter string) (result ListContainerItemsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlobContainersClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceGroupName, accountName, skipToken, maxpagesize, filter) + return +} + // LockImmutabilityPolicy sets the ImmutabilityPolicy to Locked state. The only action allowed on a Locked policy is // ExtendImmutabilityPolicy action. ETag in If-Match is required for this operation. // Parameters: diff --git a/services/storage/mgmt/2019-04-01/storage/models.go b/services/storage/mgmt/2019-04-01/storage/models.go index b879f2b0f7ac..7906385ba7d8 100644 --- a/services/storage/mgmt/2019-04-01/storage/models.go +++ b/services/storage/mgmt/2019-04-01/storage/models.go @@ -23,6 +23,8 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" "net/http" ) @@ -1750,6 +1752,143 @@ type ListContainerItems struct { NextLink *string `json:"nextLink,omitempty"` } +// ListContainerItemsIterator provides access to a complete listing of ListContainerItem values. +type ListContainerItemsIterator struct { + i int + page ListContainerItemsPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ListContainerItemsIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListContainerItemsIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ListContainerItemsIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ListContainerItemsIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ListContainerItemsIterator) Response() ListContainerItems { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ListContainerItemsIterator) Value() ListContainerItem { + if !iter.page.NotDone() { + return ListContainerItem{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ListContainerItemsIterator type. +func NewListContainerItemsIterator(page ListContainerItemsPage) ListContainerItemsIterator { + return ListContainerItemsIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (lci ListContainerItems) IsEmpty() bool { + return lci.Value == nil || len(*lci.Value) == 0 +} + +// listContainerItemsPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (lci ListContainerItems) listContainerItemsPreparer(ctx context.Context) (*http.Request, error) { + if lci.NextLink == nil || len(to.String(lci.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(lci.NextLink))) +} + +// ListContainerItemsPage contains a page of ListContainerItem values. +type ListContainerItemsPage struct { + fn func(context.Context, ListContainerItems) (ListContainerItems, error) + lci ListContainerItems +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ListContainerItemsPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListContainerItemsPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.lci) + if err != nil { + return err + } + page.lci = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ListContainerItemsPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ListContainerItemsPage) NotDone() bool { + return !page.lci.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ListContainerItemsPage) Response() ListContainerItems { + return page.lci +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ListContainerItemsPage) Values() []ListContainerItem { + if page.lci.IsEmpty() { + return nil + } + return *page.lci.Value +} + +// Creates a new instance of the ListContainerItemsPage type. +func NewListContainerItemsPage(getNextPage func(context.Context, ListContainerItems) (ListContainerItems, error)) ListContainerItemsPage { + return ListContainerItemsPage{fn: getNextPage} +} + // ListServiceSasResponse the List service SAS credentials operation response. type ListServiceSasResponse struct { autorest.Response `json:"-"` diff --git a/services/storage/mgmt/2019-04-01/storage/storageapi/interfaces.go b/services/storage/mgmt/2019-04-01/storage/storageapi/interfaces.go index 3a706749333f..38f976f21072 100644 --- a/services/storage/mgmt/2019-04-01/storage/storageapi/interfaces.go +++ b/services/storage/mgmt/2019-04-01/storage/storageapi/interfaces.go @@ -91,7 +91,7 @@ type BlobContainersClientAPI interface { Get(ctx context.Context, resourceGroupName string, accountName string, containerName string) (result storage.BlobContainer, err error) GetImmutabilityPolicy(ctx context.Context, resourceGroupName string, accountName string, containerName string, ifMatch string) (result storage.ImmutabilityPolicy, err error) Lease(ctx context.Context, resourceGroupName string, accountName string, containerName string, parameters *storage.LeaseContainerRequest) (result storage.LeaseContainerResponse, err error) - List(ctx context.Context, resourceGroupName string, accountName string, skipToken string, maxpagesize string, filter string) (result storage.ListContainerItems, err error) + List(ctx context.Context, resourceGroupName string, accountName string, skipToken string, maxpagesize string, filter string) (result storage.ListContainerItemsPage, err error) LockImmutabilityPolicy(ctx context.Context, resourceGroupName string, accountName string, containerName string, ifMatch string) (result storage.ImmutabilityPolicy, err error) SetLegalHold(ctx context.Context, resourceGroupName string, accountName string, containerName string, legalHold storage.LegalHold) (result storage.LegalHold, err error) Update(ctx context.Context, resourceGroupName string, accountName string, containerName string, blobContainer storage.BlobContainer) (result storage.BlobContainer, err error)