diff --git a/services/preview/sql/mgmt/2017-03-01-preview/sql/managedinstanceadministrators.go b/services/preview/sql/mgmt/2017-03-01-preview/sql/managedinstanceadministrators.go new file mode 100644 index 000000000000..ce3fa15903af --- /dev/null +++ b/services/preview/sql/mgmt/2017-03-01-preview/sql/managedinstanceadministrators.go @@ -0,0 +1,413 @@ +package sql + +// 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/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ManagedInstanceAdministratorsClient is the the Azure SQL Database management API provides a RESTful set of web +// services that interact with Azure SQL Database services to manage your databases. The API enables you to create, +// retrieve, update, and delete databases. +type ManagedInstanceAdministratorsClient struct { + BaseClient +} + +// NewManagedInstanceAdministratorsClient creates an instance of the ManagedInstanceAdministratorsClient client. +func NewManagedInstanceAdministratorsClient(subscriptionID string) ManagedInstanceAdministratorsClient { + return NewManagedInstanceAdministratorsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewManagedInstanceAdministratorsClientWithBaseURI creates an instance of the ManagedInstanceAdministratorsClient +// client. +func NewManagedInstanceAdministratorsClientWithBaseURI(baseURI string, subscriptionID string) ManagedInstanceAdministratorsClient { + return ManagedInstanceAdministratorsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates a managed instance administrator. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// managedInstanceName - the name of the managed instance. +// administratorName - the requested administrator name. +// parameters - the requested administrator parameters. +func (client ManagedInstanceAdministratorsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string, parameters ManagedInstanceAdministrator) (result ManagedInstanceAdministratorsCreateOrUpdateFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.ManagedInstanceAdministratorProperties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.ManagedInstanceAdministratorProperties.AdministratorType", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.ManagedInstanceAdministratorProperties.Login", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.ManagedInstanceAdministratorProperties.Sid", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("sql.ManagedInstanceAdministratorsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, managedInstanceName, administratorName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "CreateOrUpdate", result.Response(), "Failure sending request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ManagedInstanceAdministratorsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string, parameters ManagedInstanceAdministrator) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "administratorName": autorest.Encode("path", administratorName), + "managedInstanceName": autorest.Encode("path", managedInstanceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", pathParameters), + autorest.WithJSON(parameters), + 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 ManagedInstanceAdministratorsClient) CreateOrUpdateSender(req *http.Request) (future ManagedInstanceAdministratorsCreateOrUpdateFuture, err error) { + sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, sd...) + 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 ManagedInstanceAdministratorsClient) CreateOrUpdateResponder(resp *http.Response) (result ManagedInstanceAdministrator, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes a managed instance administrator. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// managedInstanceName - the name of the managed instance. +// administratorName - the administrator name. +func (client ManagedInstanceAdministratorsClient) Delete(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (result ManagedInstanceAdministratorsDeleteFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorsClient.Delete") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, resourceGroupName, managedInstanceName, administratorName) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "Delete", result.Response(), "Failure sending request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ManagedInstanceAdministratorsClient) DeletePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "administratorName": autorest.Encode("path", administratorName), + "managedInstanceName": autorest.Encode("path", managedInstanceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", 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 ManagedInstanceAdministratorsClient) DeleteSender(req *http.Request) (future ManagedInstanceAdministratorsDeleteFuture, err error) { + sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, sd...) + 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 ManagedInstanceAdministratorsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets a managed instance administrator. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// managedInstanceName - the name of the managed instance. +// administratorName - the administrator name. +func (client ManagedInstanceAdministratorsClient) Get(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (result ManagedInstanceAdministrator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorsClient.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, resourceGroupName, managedInstanceName, administratorName) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ManagedInstanceAdministratorsClient) GetPreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "administratorName": autorest.Encode("path", administratorName), + "managedInstanceName": autorest.Encode("path", managedInstanceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", 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 ManagedInstanceAdministratorsClient) GetSender(req *http.Request) (*http.Response, error) { + sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) + return autorest.SendWithSender(client, req, sd...) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ManagedInstanceAdministratorsClient) GetResponder(resp *http.Response) (result ManagedInstanceAdministrator, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByInstance gets a list of managed instance administrators. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// managedInstanceName - the name of the managed instance. +func (client ManagedInstanceAdministratorsClient) ListByInstance(ctx context.Context, resourceGroupName string, managedInstanceName string) (result ManagedInstanceAdministratorListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorsClient.ListByInstance") + defer func() { + sc := -1 + if result.mialr.Response.Response != nil { + sc = result.mialr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listByInstanceNextResults + req, err := client.ListByInstancePreparer(ctx, resourceGroupName, managedInstanceName) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "ListByInstance", nil, "Failure preparing request") + return + } + + resp, err := client.ListByInstanceSender(req) + if err != nil { + result.mialr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "ListByInstance", resp, "Failure sending request") + return + } + + result.mialr, err = client.ListByInstanceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "ListByInstance", resp, "Failure responding to request") + } + + return +} + +// ListByInstancePreparer prepares the ListByInstance request. +func (client ManagedInstanceAdministratorsClient) ListByInstancePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managedInstanceName": autorest.Encode("path", managedInstanceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByInstanceSender sends the ListByInstance request. The method will close the +// http.Response Body if it receives an error. +func (client ManagedInstanceAdministratorsClient) ListByInstanceSender(req *http.Request) (*http.Response, error) { + sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) + return autorest.SendWithSender(client, req, sd...) +} + +// ListByInstanceResponder handles the response to the ListByInstance request. The method always +// closes the http.Response Body. +func (client ManagedInstanceAdministratorsClient) ListByInstanceResponder(resp *http.Response) (result ManagedInstanceAdministratorListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByInstanceNextResults retrieves the next set of results, if any. +func (client ManagedInstanceAdministratorsClient) listByInstanceNextResults(ctx context.Context, lastResults ManagedInstanceAdministratorListResult) (result ManagedInstanceAdministratorListResult, err error) { + req, err := lastResults.managedInstanceAdministratorListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "listByInstanceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByInstanceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "listByInstanceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByInstanceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsClient", "listByInstanceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByInstanceComplete enumerates all values, automatically crossing page boundaries as required. +func (client ManagedInstanceAdministratorsClient) ListByInstanceComplete(ctx context.Context, resourceGroupName string, managedInstanceName string) (result ManagedInstanceAdministratorListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorsClient.ListByInstance") + 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.ListByInstance(ctx, resourceGroupName, managedInstanceName) + return +} diff --git a/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go b/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go index 4c1fb4206cb4..3794bccb4a92 100644 --- a/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go +++ b/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go @@ -8608,6 +8608,290 @@ func (mi *ManagedInstance) UnmarshalJSON(body []byte) error { return nil } +// ManagedInstanceAdministrator an Azure SQL managed instance administrator. +type ManagedInstanceAdministrator struct { + autorest.Response `json:"-"` + // ManagedInstanceAdministratorProperties - Resource properties. + *ManagedInstanceAdministratorProperties `json:"properties,omitempty"` + // ID - READ-ONLY; Resource ID. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Resource name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Resource type. + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ManagedInstanceAdministrator. +func (mia ManagedInstanceAdministrator) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mia.ManagedInstanceAdministratorProperties != nil { + objectMap["properties"] = mia.ManagedInstanceAdministratorProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ManagedInstanceAdministrator struct. +func (mia *ManagedInstanceAdministrator) 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 "properties": + if v != nil { + var managedInstanceAdministratorProperties ManagedInstanceAdministratorProperties + err = json.Unmarshal(*v, &managedInstanceAdministratorProperties) + if err != nil { + return err + } + mia.ManagedInstanceAdministratorProperties = &managedInstanceAdministratorProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + mia.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + mia.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + mia.Type = &typeVar + } + } + } + + return nil +} + +// ManagedInstanceAdministratorListResult a list of managed instance administrators. +type ManagedInstanceAdministratorListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Array of results. + Value *[]ManagedInstanceAdministrator `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// ManagedInstanceAdministratorListResultIterator provides access to a complete listing of +// ManagedInstanceAdministrator values. +type ManagedInstanceAdministratorListResultIterator struct { + i int + page ManagedInstanceAdministratorListResultPage +} + +// 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 *ManagedInstanceAdministratorListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorListResultIterator.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 *ManagedInstanceAdministratorListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ManagedInstanceAdministratorListResultIterator) 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 ManagedInstanceAdministratorListResultIterator) Response() ManagedInstanceAdministratorListResult { + 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 ManagedInstanceAdministratorListResultIterator) Value() ManagedInstanceAdministrator { + if !iter.page.NotDone() { + return ManagedInstanceAdministrator{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ManagedInstanceAdministratorListResultIterator type. +func NewManagedInstanceAdministratorListResultIterator(page ManagedInstanceAdministratorListResultPage) ManagedInstanceAdministratorListResultIterator { + return ManagedInstanceAdministratorListResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (mialr ManagedInstanceAdministratorListResult) IsEmpty() bool { + return mialr.Value == nil || len(*mialr.Value) == 0 +} + +// managedInstanceAdministratorListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (mialr ManagedInstanceAdministratorListResult) managedInstanceAdministratorListResultPreparer(ctx context.Context) (*http.Request, error) { + if mialr.NextLink == nil || len(to.String(mialr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(mialr.NextLink))) +} + +// ManagedInstanceAdministratorListResultPage contains a page of ManagedInstanceAdministrator values. +type ManagedInstanceAdministratorListResultPage struct { + fn func(context.Context, ManagedInstanceAdministratorListResult) (ManagedInstanceAdministratorListResult, error) + mialr ManagedInstanceAdministratorListResult +} + +// 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 *ManagedInstanceAdministratorListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedInstanceAdministratorListResultPage.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.mialr) + if err != nil { + return err + } + page.mialr = 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 *ManagedInstanceAdministratorListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ManagedInstanceAdministratorListResultPage) NotDone() bool { + return !page.mialr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ManagedInstanceAdministratorListResultPage) Response() ManagedInstanceAdministratorListResult { + return page.mialr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ManagedInstanceAdministratorListResultPage) Values() []ManagedInstanceAdministrator { + if page.mialr.IsEmpty() { + return nil + } + return *page.mialr.Value +} + +// Creates a new instance of the ManagedInstanceAdministratorListResultPage type. +func NewManagedInstanceAdministratorListResultPage(getNextPage func(context.Context, ManagedInstanceAdministratorListResult) (ManagedInstanceAdministratorListResult, error)) ManagedInstanceAdministratorListResultPage { + return ManagedInstanceAdministratorListResultPage{fn: getNextPage} +} + +// ManagedInstanceAdministratorProperties the properties of a managed instance administrator. +type ManagedInstanceAdministratorProperties struct { + // AdministratorType - Type of the managed instance administrator. + AdministratorType *string `json:"administratorType,omitempty"` + // Login - Login name of the managed instance administrator. + Login *string `json:"login,omitempty"` + // Sid - SID (object ID) of the managed instance administrator. + Sid *uuid.UUID `json:"sid,omitempty"` + // TenantID - Tenant ID of the managed instance administrator. + TenantID *uuid.UUID `json:"tenantId,omitempty"` +} + +// ManagedInstanceAdministratorsCreateOrUpdateFuture an abstraction for monitoring and retrieving the +// results of a long-running operation. +type ManagedInstanceAdministratorsCreateOrUpdateFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ManagedInstanceAdministratorsCreateOrUpdateFuture) Result(client ManagedInstanceAdministratorsClient) (mia ManagedInstanceAdministrator, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("sql.ManagedInstanceAdministratorsCreateOrUpdateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if mia.Response.Response, err = future.GetResult(sender); err == nil && mia.Response.Response.StatusCode != http.StatusNoContent { + mia, err = client.CreateOrUpdateResponder(mia.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsCreateOrUpdateFuture", "Result", mia.Response.Response, "Failure responding to request") + } + } + return +} + +// ManagedInstanceAdministratorsDeleteFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type ManagedInstanceAdministratorsDeleteFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ManagedInstanceAdministratorsDeleteFuture) Result(client ManagedInstanceAdministratorsClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedInstanceAdministratorsDeleteFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("sql.ManagedInstanceAdministratorsDeleteFuture") + return + } + ar.Response = future.Response() + return +} + // ManagedInstanceListResult a list of managed instances. type ManagedInstanceListResult struct { autorest.Response `json:"-"` diff --git a/services/preview/sql/mgmt/2017-03-01-preview/sql/sqlapi/interfaces.go b/services/preview/sql/mgmt/2017-03-01-preview/sql/sqlapi/interfaces.go index 08673f8958ab..ae9f1936ba8c 100644 --- a/services/preview/sql/mgmt/2017-03-01-preview/sql/sqlapi/interfaces.go +++ b/services/preview/sql/mgmt/2017-03-01-preview/sql/sqlapi/interfaces.go @@ -577,6 +577,16 @@ type SensitivityLabelsClientAPI interface { var _ SensitivityLabelsClientAPI = (*sql.SensitivityLabelsClient)(nil) +// ManagedInstanceAdministratorsClientAPI contains the set of methods on the ManagedInstanceAdministratorsClient type. +type ManagedInstanceAdministratorsClientAPI interface { + CreateOrUpdate(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string, parameters sql.ManagedInstanceAdministrator) (result sql.ManagedInstanceAdministratorsCreateOrUpdateFuture, err error) + Delete(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (result sql.ManagedInstanceAdministratorsDeleteFuture, err error) + Get(ctx context.Context, resourceGroupName string, managedInstanceName string, administratorName string) (result sql.ManagedInstanceAdministrator, err error) + ListByInstance(ctx context.Context, resourceGroupName string, managedInstanceName string) (result sql.ManagedInstanceAdministratorListResultPage, err error) +} + +var _ ManagedInstanceAdministratorsClientAPI = (*sql.ManagedInstanceAdministratorsClient)(nil) + // ServerAutomaticTuningClientAPI contains the set of methods on the ServerAutomaticTuningClient type. type ServerAutomaticTuningClientAPI interface { Get(ctx context.Context, resourceGroupName string, serverName string) (result sql.ServerAutomaticTuning, err error)