1package sql 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// RestorableDroppedManagedDatabasesClient is the the Azure SQL Database management API provides a RESTful set of web 18// services that interact with Azure SQL Database services to manage your databases. The API enables you to create, 19// retrieve, update, and delete databases. 20type RestorableDroppedManagedDatabasesClient struct { 21 BaseClient 22} 23 24// NewRestorableDroppedManagedDatabasesClient creates an instance of the RestorableDroppedManagedDatabasesClient 25// client. 26func NewRestorableDroppedManagedDatabasesClient(subscriptionID string) RestorableDroppedManagedDatabasesClient { 27 return NewRestorableDroppedManagedDatabasesClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewRestorableDroppedManagedDatabasesClientWithBaseURI creates an instance of the 31// RestorableDroppedManagedDatabasesClient client using a custom endpoint. Use this when interacting with an Azure 32// cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 33func NewRestorableDroppedManagedDatabasesClientWithBaseURI(baseURI string, subscriptionID string) RestorableDroppedManagedDatabasesClient { 34 return RestorableDroppedManagedDatabasesClient{NewWithBaseURI(baseURI, subscriptionID)} 35} 36 37// Get gets a restorable dropped managed database. 38// Parameters: 39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 40// from the Azure Resource Manager API or the portal. 41// managedInstanceName - the name of the managed instance. 42func (client RestorableDroppedManagedDatabasesClient) Get(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (result RestorableDroppedManagedDatabase, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedManagedDatabasesClient.Get") 45 defer func() { 46 sc := -1 47 if result.Response.Response != nil { 48 sc = result.Response.Response.StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 req, err := client.GetPreparer(ctx, resourceGroupName, managedInstanceName, restorableDroppedDatabaseID) 54 if err != nil { 55 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "Get", nil, "Failure preparing request") 56 return 57 } 58 59 resp, err := client.GetSender(req) 60 if err != nil { 61 result.Response = autorest.Response{Response: resp} 62 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "Get", resp, "Failure sending request") 63 return 64 } 65 66 result, err = client.GetResponder(resp) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "Get", resp, "Failure responding to request") 69 return 70 } 71 72 return 73} 74 75// GetPreparer prepares the Get request. 76func (client RestorableDroppedManagedDatabasesClient) GetPreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseID string) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "managedInstanceName": autorest.Encode("path", managedInstanceName), 79 "resourceGroupName": autorest.Encode("path", resourceGroupName), 80 "restorableDroppedDatabaseId": autorest.Encode("path", restorableDroppedDatabaseID), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2017-03-01-preview" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsGet(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}", pathParameters), 93 autorest.WithQueryParameters(queryParameters)) 94 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 95} 96 97// GetSender sends the Get request. The method will close the 98// http.Response Body if it receives an error. 99func (client RestorableDroppedManagedDatabasesClient) GetSender(req *http.Request) (*http.Response, error) { 100 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 101} 102 103// GetResponder handles the response to the Get request. The method always 104// closes the http.Response Body. 105func (client RestorableDroppedManagedDatabasesClient) GetResponder(resp *http.Response) (result RestorableDroppedManagedDatabase, err error) { 106 err = autorest.Respond( 107 resp, 108 azure.WithErrorUnlessStatusCode(http.StatusOK), 109 autorest.ByUnmarshallingJSON(&result), 110 autorest.ByClosing()) 111 result.Response = autorest.Response{Response: resp} 112 return 113} 114 115// ListByInstance gets a list of restorable dropped managed databases. 116// Parameters: 117// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 118// from the Azure Resource Manager API or the portal. 119// managedInstanceName - the name of the managed instance. 120func (client RestorableDroppedManagedDatabasesClient) ListByInstance(ctx context.Context, resourceGroupName string, managedInstanceName string) (result RestorableDroppedManagedDatabaseListResultPage, err error) { 121 if tracing.IsEnabled() { 122 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedManagedDatabasesClient.ListByInstance") 123 defer func() { 124 sc := -1 125 if result.rdmdlr.Response.Response != nil { 126 sc = result.rdmdlr.Response.Response.StatusCode 127 } 128 tracing.EndSpan(ctx, sc, err) 129 }() 130 } 131 result.fn = client.listByInstanceNextResults 132 req, err := client.ListByInstancePreparer(ctx, resourceGroupName, managedInstanceName) 133 if err != nil { 134 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "ListByInstance", nil, "Failure preparing request") 135 return 136 } 137 138 resp, err := client.ListByInstanceSender(req) 139 if err != nil { 140 result.rdmdlr.Response = autorest.Response{Response: resp} 141 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "ListByInstance", resp, "Failure sending request") 142 return 143 } 144 145 result.rdmdlr, err = client.ListByInstanceResponder(resp) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "ListByInstance", resp, "Failure responding to request") 148 return 149 } 150 if result.rdmdlr.hasNextLink() && result.rdmdlr.IsEmpty() { 151 err = result.NextWithContext(ctx) 152 return 153 } 154 155 return 156} 157 158// ListByInstancePreparer prepares the ListByInstance request. 159func (client RestorableDroppedManagedDatabasesClient) ListByInstancePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "managedInstanceName": autorest.Encode("path", managedInstanceName), 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 164 } 165 166 const APIVersion = "2017-03-01-preview" 167 queryParameters := map[string]interface{}{ 168 "api-version": APIVersion, 169 } 170 171 preparer := autorest.CreatePreparer( 172 autorest.AsGet(), 173 autorest.WithBaseURL(client.BaseURI), 174 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases", pathParameters), 175 autorest.WithQueryParameters(queryParameters)) 176 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 177} 178 179// ListByInstanceSender sends the ListByInstance request. The method will close the 180// http.Response Body if it receives an error. 181func (client RestorableDroppedManagedDatabasesClient) ListByInstanceSender(req *http.Request) (*http.Response, error) { 182 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 183} 184 185// ListByInstanceResponder handles the response to the ListByInstance request. The method always 186// closes the http.Response Body. 187func (client RestorableDroppedManagedDatabasesClient) ListByInstanceResponder(resp *http.Response) (result RestorableDroppedManagedDatabaseListResult, err error) { 188 err = autorest.Respond( 189 resp, 190 azure.WithErrorUnlessStatusCode(http.StatusOK), 191 autorest.ByUnmarshallingJSON(&result), 192 autorest.ByClosing()) 193 result.Response = autorest.Response{Response: resp} 194 return 195} 196 197// listByInstanceNextResults retrieves the next set of results, if any. 198func (client RestorableDroppedManagedDatabasesClient) listByInstanceNextResults(ctx context.Context, lastResults RestorableDroppedManagedDatabaseListResult) (result RestorableDroppedManagedDatabaseListResult, err error) { 199 req, err := lastResults.restorableDroppedManagedDatabaseListResultPreparer(ctx) 200 if err != nil { 201 return result, autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "listByInstanceNextResults", nil, "Failure preparing next results request") 202 } 203 if req == nil { 204 return 205 } 206 resp, err := client.ListByInstanceSender(req) 207 if err != nil { 208 result.Response = autorest.Response{Response: resp} 209 return result, autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "listByInstanceNextResults", resp, "Failure sending next results request") 210 } 211 result, err = client.ListByInstanceResponder(resp) 212 if err != nil { 213 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedManagedDatabasesClient", "listByInstanceNextResults", resp, "Failure responding to next results request") 214 } 215 return 216} 217 218// ListByInstanceComplete enumerates all values, automatically crossing page boundaries as required. 219func (client RestorableDroppedManagedDatabasesClient) ListByInstanceComplete(ctx context.Context, resourceGroupName string, managedInstanceName string) (result RestorableDroppedManagedDatabaseListResultIterator, err error) { 220 if tracing.IsEnabled() { 221 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedManagedDatabasesClient.ListByInstance") 222 defer func() { 223 sc := -1 224 if result.Response().Response.Response != nil { 225 sc = result.page.Response().Response.Response.StatusCode 226 } 227 tracing.EndSpan(ctx, sc, err) 228 }() 229 } 230 result.page, err = client.ListByInstance(ctx, resourceGroupName, managedInstanceName) 231 return 232} 233