1package sql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// RestorableDroppedDatabasesClient is the the Azure SQL Database management API provides a RESTful set of web services 29// that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, 30// update, and delete databases. 31type RestorableDroppedDatabasesClient struct { 32 BaseClient 33} 34 35// NewRestorableDroppedDatabasesClient creates an instance of the RestorableDroppedDatabasesClient client. 36func NewRestorableDroppedDatabasesClient(subscriptionID string) RestorableDroppedDatabasesClient { 37 return NewRestorableDroppedDatabasesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewRestorableDroppedDatabasesClientWithBaseURI creates an instance of the RestorableDroppedDatabasesClient client 41// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 42// clouds, Azure stack). 43func NewRestorableDroppedDatabasesClientWithBaseURI(baseURI string, subscriptionID string) RestorableDroppedDatabasesClient { 44 return RestorableDroppedDatabasesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Get gets a deleted database that can be restored 48// Parameters: 49// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 50// from the Azure Resource Manager API or the portal. 51// serverName - the name of the server. 52// restorableDroppededDatabaseID - the id of the deleted database in the form of 53// databaseName,deletionTimeInFileTimeFormat 54func (client RestorableDroppedDatabasesClient) Get(ctx context.Context, resourceGroupName string, serverName string, restorableDroppededDatabaseID string) (result RestorableDroppedDatabase, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedDatabasesClient.Get") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, restorableDroppededDatabaseID) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.GetSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.GetResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", resp, "Failure responding to request") 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client RestorableDroppedDatabasesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, restorableDroppededDatabaseID string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "resourceGroupName": autorest.Encode("path", resourceGroupName), 90 "restorableDroppededDatabaseId": autorest.Encode("path", restorableDroppededDatabaseID), 91 "serverName": autorest.Encode("path", serverName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2014-04-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppededDatabaseId}", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// GetSender sends the Get request. The method will close the 109// http.Response Body if it receives an error. 110func (client RestorableDroppedDatabasesClient) GetSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// GetResponder handles the response to the Get request. The method always 115// closes the http.Response Body. 116func (client RestorableDroppedDatabasesClient) GetResponder(resp *http.Response) (result RestorableDroppedDatabase, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// ListByServer gets a list of deleted databases that can be restored 128// Parameters: 129// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 130// from the Azure Resource Manager API or the portal. 131// serverName - the name of the server. 132func (client RestorableDroppedDatabasesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result RestorableDroppedDatabaseListResult, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedDatabasesClient.ListByServer") 135 defer func() { 136 sc := -1 137 if result.Response.Response != nil { 138 sc = result.Response.Response.StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", nil, "Failure preparing request") 146 return 147 } 148 149 resp, err := client.ListByServerSender(req) 150 if err != nil { 151 result.Response = autorest.Response{Response: resp} 152 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", resp, "Failure sending request") 153 return 154 } 155 156 result, err = client.ListByServerResponder(resp) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", resp, "Failure responding to request") 159 } 160 161 return 162} 163 164// ListByServerPreparer prepares the ListByServer request. 165func (client RestorableDroppedDatabasesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 166 pathParameters := map[string]interface{}{ 167 "resourceGroupName": autorest.Encode("path", resourceGroupName), 168 "serverName": autorest.Encode("path", serverName), 169 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 170 } 171 172 const APIVersion = "2014-04-01" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsGet(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// ListByServerSender sends the ListByServer request. The method will close the 186// http.Response Body if it receives an error. 187func (client RestorableDroppedDatabasesClient) ListByServerSender(req *http.Request) (*http.Response, error) { 188 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 189} 190 191// ListByServerResponder handles the response to the ListByServer request. The method always 192// closes the http.Response Body. 193func (client RestorableDroppedDatabasesClient) ListByServerResponder(resp *http.Response) (result RestorableDroppedDatabaseListResult, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK), 198 autorest.ByUnmarshallingJSON(&result), 199 autorest.ByClosing()) 200 result.Response = autorest.Response{Response: resp} 201 return 202} 203