diff --git a/profiles/preview/preview/customproviders/mgmt/customproviders/customprovidersapi/models.go b/profiles/preview/preview/customproviders/mgmt/customproviders/customprovidersapi/models.go index c90ddd7aac4a..4bdcc67d7847 100644 --- a/profiles/preview/preview/customproviders/mgmt/customproviders/customprovidersapi/models.go +++ b/profiles/preview/preview/customproviders/mgmt/customproviders/customprovidersapi/models.go @@ -21,5 +21,6 @@ package customprovidersapi import original "github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customprovidersapi" +type AssociationsClientAPI = original.AssociationsClientAPI type CustomResourceProviderClientAPI = original.CustomResourceProviderClientAPI type OperationsClientAPI = original.OperationsClientAPI diff --git a/profiles/preview/preview/customproviders/mgmt/customproviders/models.go b/profiles/preview/preview/customproviders/mgmt/customproviders/models.go index 5c31a7c5a6ee..4faf35e5cdbc 100644 --- a/profiles/preview/preview/customproviders/mgmt/customproviders/models.go +++ b/profiles/preview/preview/customproviders/mgmt/customproviders/models.go @@ -58,6 +58,14 @@ const ( Swagger ValidationType = original.Swagger ) +type Association = original.Association +type AssociationProperties = original.AssociationProperties +type AssociationsClient = original.AssociationsClient +type AssociationsCreateOrUpdateFuture = original.AssociationsCreateOrUpdateFuture +type AssociationsDeleteFuture = original.AssociationsDeleteFuture +type AssociationsList = original.AssociationsList +type AssociationsListIterator = original.AssociationsListIterator +type AssociationsListPage = original.AssociationsListPage type BaseClient = original.BaseClient type CustomRPActionRouteDefinition = original.CustomRPActionRouteDefinition type CustomRPManifest = original.CustomRPManifest @@ -85,6 +93,18 @@ type ResourceProvidersUpdate = original.ResourceProvidersUpdate func New(subscriptionID string) BaseClient { return original.New(subscriptionID) } +func NewAssociationsClient(subscriptionID string) AssociationsClient { + return original.NewAssociationsClient(subscriptionID) +} +func NewAssociationsClientWithBaseURI(baseURI string, subscriptionID string) AssociationsClient { + return original.NewAssociationsClientWithBaseURI(baseURI, subscriptionID) +} +func NewAssociationsListIterator(page AssociationsListPage) AssociationsListIterator { + return original.NewAssociationsListIterator(page) +} +func NewAssociationsListPage(getNextPage func(context.Context, AssociationsList) (AssociationsList, error)) AssociationsListPage { + return original.NewAssociationsListPage(getNextPage) +} func NewCustomResourceProviderClient(subscriptionID string) CustomResourceProviderClient { return original.NewCustomResourceProviderClient(subscriptionID) } diff --git a/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go new file mode 100644 index 000000000000..bc43cb9eda62 --- /dev/null +++ b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go @@ -0,0 +1,388 @@ +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AssociationsClient is the allows extension of ARM control plane with custom resource providers. +type AssociationsClient struct { + BaseClient +} + +// NewAssociationsClient creates an instance of the AssociationsClient client. +func NewAssociationsClient(subscriptionID string) AssociationsClient { + return NewAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAssociationsClientWithBaseURI creates an instance of the AssociationsClient client. +func NewAssociationsClientWithBaseURI(baseURI string, subscriptionID string) AssociationsClient { + return AssociationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create or update an association. +// Parameters: +// scope - the scope of the association. The scope can be any valid REST resource instance. For example, use +// '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}' +// for a virtual machine resource. +// associationName - the name of the association. +// association - the parameters required to create or update an association. +func (client AssociationsClient) CreateOrUpdate(ctx context.Context, scope string, associationName string, association Association) (result AssociationsCreateOrUpdateFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdatePreparer(ctx, scope, associationName, association) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "CreateOrUpdate", result.Response(), "Failure sending request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client AssociationsClient) CreateOrUpdatePreparer(ctx context.Context, scope string, associationName string, association Association) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + association.ID = nil + association.Name = nil + association.Type = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithJSON(association), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) CreateOrUpdateSender(req *http.Request) (future AssociationsCreateOrUpdateFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client AssociationsClient) CreateOrUpdateResponder(resp *http.Response) (result Association, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete an association. +// Parameters: +// scope - the scope of the association. +// associationName - the name of the association. +func (client AssociationsClient) Delete(ctx context.Context, scope string, associationName string) (result AssociationsDeleteFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.Delete") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, scope, associationName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Delete", result.Response(), "Failure sending request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AssociationsClient) DeletePreparer(ctx context.Context, scope string, associationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + 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 AssociationsClient) DeleteSender(req *http.Request) (future AssociationsDeleteFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AssociationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get an association. +// Parameters: +// scope - the scope of the association. +// associationName - the name of the association. +func (client AssociationsClient) Get(ctx context.Context, scope string, associationName string) (result Association, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, scope, associationName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AssociationsClient) GetPreparer(ctx context.Context, scope string, associationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AssociationsClient) GetResponder(resp *http.Response) (result Association, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListAll gets all association for the given scope. +// Parameters: +// scope - the scope of the association. +func (client AssociationsClient) ListAll(ctx context.Context, scope string) (result AssociationsListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.ListAll") + defer func() { + sc := -1 + if result.al.Response.Response != nil { + sc = result.al.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listAllNextResults + req, err := client.ListAllPreparer(ctx, scope) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", nil, "Failure preparing request") + return + } + + resp, err := client.ListAllSender(req) + if err != nil { + result.al.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", resp, "Failure sending request") + return + } + + result.al, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", resp, "Failure responding to request") + } + + return +} + +// ListAllPreparer prepares the ListAll request. +func (client AssociationsClient) ListAllPreparer(ctx context.Context, scope string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAllSender sends the ListAll request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) ListAllSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListAllResponder handles the response to the ListAll request. The method always +// closes the http.Response Body. +func (client AssociationsClient) ListAllResponder(resp *http.Response) (result AssociationsList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listAllNextResults retrieves the next set of results, if any. +func (client AssociationsClient) listAllNextResults(ctx context.Context, lastResults AssociationsList) (result AssociationsList, err error) { + req, err := lastResults.associationsListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListAllSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", resp, "Failure sending next results request") + } + result, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListAllComplete enumerates all values, automatically crossing page boundaries as required. +func (client AssociationsClient) ListAllComplete(ctx context.Context, scope string) (result AssociationsListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.ListAll") + 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.ListAll(ctx, scope) + return +} diff --git a/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customprovidersapi/interfaces.go b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customprovidersapi/interfaces.go index 4db5bafb89de..8a08d10565c9 100644 --- a/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customprovidersapi/interfaces.go +++ b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customprovidersapi/interfaces.go @@ -40,3 +40,13 @@ type CustomResourceProviderClientAPI interface { } var _ CustomResourceProviderClientAPI = (*customproviders.CustomResourceProviderClient)(nil) + +// AssociationsClientAPI contains the set of methods on the AssociationsClient type. +type AssociationsClientAPI interface { + CreateOrUpdate(ctx context.Context, scope string, associationName string, association customproviders.Association) (result customproviders.AssociationsCreateOrUpdateFuture, err error) + Delete(ctx context.Context, scope string, associationName string) (result customproviders.AssociationsDeleteFuture, err error) + Get(ctx context.Context, scope string, associationName string) (result customproviders.Association, err error) + ListAll(ctx context.Context, scope string) (result customproviders.AssociationsListPage, err error) +} + +var _ AssociationsClientAPI = (*customproviders.AssociationsClient)(nil) diff --git a/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go index c3a3f664265c..b29e63aaef12 100644 --- a/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go +++ b/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go @@ -92,6 +92,285 @@ func PossibleValidationTypeValues() []ValidationType { return []ValidationType{Swagger} } +// Association the resource definition of this association. +type Association struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; The association id. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The association name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The association type. + Type *string `json:"type,omitempty"` + // AssociationProperties - The properties of the association. + *AssociationProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for Association. +func (a Association) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if a.AssociationProperties != nil { + objectMap["properties"] = a.AssociationProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Association struct. +func (a *Association) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + a.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + a.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + a.Type = &typeVar + } + case "properties": + if v != nil { + var associationProperties AssociationProperties + err = json.Unmarshal(*v, &associationProperties) + if err != nil { + return err + } + a.AssociationProperties = &associationProperties + } + } + } + + return nil +} + +// AssociationProperties the properties of the association. +type AssociationProperties struct { + // TargetResourceID - The REST resource instance of the target resource for this association. + TargetResourceID *string `json:"targetResourceId,omitempty"` + // ProvisioningState - READ-ONLY; The provisioning state of the association. Possible values include: 'Accepted', 'Deleting', 'Running', 'Succeeded', 'Failed' + ProvisioningState ProvisioningState `json:"provisioningState,omitempty"` +} + +// AssociationsCreateOrUpdateFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type AssociationsCreateOrUpdateFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *AssociationsCreateOrUpdateFuture) Result(client AssociationsClient) (a Association, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.AssociationsCreateOrUpdateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if a.Response.Response, err = future.GetResult(sender); err == nil && a.Response.Response.StatusCode != http.StatusNoContent { + a, err = client.CreateOrUpdateResponder(a.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsCreateOrUpdateFuture", "Result", a.Response.Response, "Failure responding to request") + } + } + return +} + +// AssociationsDeleteFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type AssociationsDeleteFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *AssociationsDeleteFuture) Result(client AssociationsClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsDeleteFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.AssociationsDeleteFuture") + return + } + ar.Response = future.Response() + return +} + +// AssociationsList list of associations. +type AssociationsList struct { + autorest.Response `json:"-"` + // Value - The array of associations. + Value *[]Association `json:"value,omitempty"` + // NextLink - The URL to use for getting the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// AssociationsListIterator provides access to a complete listing of Association values. +type AssociationsListIterator struct { + i int + page AssociationsListPage +} + +// 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 *AssociationsListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsListIterator.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 *AssociationsListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AssociationsListIterator) 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 AssociationsListIterator) Response() AssociationsList { + 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 AssociationsListIterator) Value() Association { + if !iter.page.NotDone() { + return Association{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AssociationsListIterator type. +func NewAssociationsListIterator(page AssociationsListPage) AssociationsListIterator { + return AssociationsListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (al AssociationsList) IsEmpty() bool { + return al.Value == nil || len(*al.Value) == 0 +} + +// associationsListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (al AssociationsList) associationsListPreparer(ctx context.Context) (*http.Request, error) { + if al.NextLink == nil || len(to.String(al.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(al.NextLink))) +} + +// AssociationsListPage contains a page of Association values. +type AssociationsListPage struct { + fn func(context.Context, AssociationsList) (AssociationsList, error) + al AssociationsList +} + +// 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 *AssociationsListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsListPage.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.al) + if err != nil { + return err + } + page.al = 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 *AssociationsListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AssociationsListPage) NotDone() bool { + return !page.al.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AssociationsListPage) Response() AssociationsList { + return page.al +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AssociationsListPage) Values() []Association { + if page.al.IsEmpty() { + return nil + } + return *page.al.Value +} + +// Creates a new instance of the AssociationsListPage type. +func NewAssociationsListPage(getNextPage func(context.Context, AssociationsList) (AssociationsList, error)) AssociationsListPage { + return AssociationsListPage{fn: getNextPage} +} + // CustomResourceProviderCreateOrUpdateFuture an abstraction for monitoring and retrieving the results of a // long-running operation. type CustomResourceProviderCreateOrUpdateFuture struct {