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