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// RestorableDroppedDatabasesClient is the the Azure SQL Database management API provides a RESTful set of web services
18// that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve,
19// update, and delete databases.
20type RestorableDroppedDatabasesClient struct {
21	BaseClient
22}
23
24// NewRestorableDroppedDatabasesClient creates an instance of the RestorableDroppedDatabasesClient client.
25func NewRestorableDroppedDatabasesClient(subscriptionID string) RestorableDroppedDatabasesClient {
26	return NewRestorableDroppedDatabasesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewRestorableDroppedDatabasesClientWithBaseURI creates an instance of the RestorableDroppedDatabasesClient client
30// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
31// clouds, Azure stack).
32func NewRestorableDroppedDatabasesClientWithBaseURI(baseURI string, subscriptionID string) RestorableDroppedDatabasesClient {
33	return RestorableDroppedDatabasesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// Get gets a deleted database that can be restored
37// Parameters:
38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
39// from the Azure Resource Manager API or the portal.
40// serverName - the name of the server.
41// restorableDroppededDatabaseID - the id of the deleted database in the form of
42// databaseName,deletionTimeInFileTimeFormat
43func (client RestorableDroppedDatabasesClient) Get(ctx context.Context, resourceGroupName string, serverName string, restorableDroppededDatabaseID string) (result RestorableDroppedDatabase, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedDatabasesClient.Get")
46		defer func() {
47			sc := -1
48			if result.Response.Response != nil {
49				sc = result.Response.Response.StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, restorableDroppededDatabaseID)
55	if err != nil {
56		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", nil, "Failure preparing request")
57		return
58	}
59
60	resp, err := client.GetSender(req)
61	if err != nil {
62		result.Response = autorest.Response{Response: resp}
63		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", resp, "Failure sending request")
64		return
65	}
66
67	result, err = client.GetResponder(resp)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "Get", resp, "Failure responding to request")
70		return
71	}
72
73	return
74}
75
76// GetPreparer prepares the Get request.
77func (client RestorableDroppedDatabasesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, restorableDroppededDatabaseID string) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
80		"restorableDroppededDatabaseId": autorest.Encode("path", restorableDroppededDatabaseID),
81		"serverName":                    autorest.Encode("path", serverName),
82		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
83	}
84
85	const APIVersion = "2014-04-01"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsGet(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppededDatabaseId}", pathParameters),
94		autorest.WithQueryParameters(queryParameters))
95	return preparer.Prepare((&http.Request{}).WithContext(ctx))
96}
97
98// GetSender sends the Get request. The method will close the
99// http.Response Body if it receives an error.
100func (client RestorableDroppedDatabasesClient) GetSender(req *http.Request) (*http.Response, error) {
101	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
102}
103
104// GetResponder handles the response to the Get request. The method always
105// closes the http.Response Body.
106func (client RestorableDroppedDatabasesClient) GetResponder(resp *http.Response) (result RestorableDroppedDatabase, err error) {
107	err = autorest.Respond(
108		resp,
109		azure.WithErrorUnlessStatusCode(http.StatusOK),
110		autorest.ByUnmarshallingJSON(&result),
111		autorest.ByClosing())
112	result.Response = autorest.Response{Response: resp}
113	return
114}
115
116// ListByServer gets a list of deleted databases that can be restored
117// Parameters:
118// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
119// from the Azure Resource Manager API or the portal.
120// serverName - the name of the server.
121func (client RestorableDroppedDatabasesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result RestorableDroppedDatabaseListResult, err error) {
122	if tracing.IsEnabled() {
123		ctx = tracing.StartSpan(ctx, fqdn+"/RestorableDroppedDatabasesClient.ListByServer")
124		defer func() {
125			sc := -1
126			if result.Response.Response != nil {
127				sc = result.Response.Response.StatusCode
128			}
129			tracing.EndSpan(ctx, sc, err)
130		}()
131	}
132	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
133	if err != nil {
134		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", nil, "Failure preparing request")
135		return
136	}
137
138	resp, err := client.ListByServerSender(req)
139	if err != nil {
140		result.Response = autorest.Response{Response: resp}
141		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", resp, "Failure sending request")
142		return
143	}
144
145	result, err = client.ListByServerResponder(resp)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "sql.RestorableDroppedDatabasesClient", "ListByServer", resp, "Failure responding to request")
148		return
149	}
150
151	return
152}
153
154// ListByServerPreparer prepares the ListByServer request.
155func (client RestorableDroppedDatabasesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
156	pathParameters := map[string]interface{}{
157		"resourceGroupName": autorest.Encode("path", resourceGroupName),
158		"serverName":        autorest.Encode("path", serverName),
159		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
160	}
161
162	const APIVersion = "2014-04-01"
163	queryParameters := map[string]interface{}{
164		"api-version": APIVersion,
165	}
166
167	preparer := autorest.CreatePreparer(
168		autorest.AsGet(),
169		autorest.WithBaseURL(client.BaseURI),
170		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases", pathParameters),
171		autorest.WithQueryParameters(queryParameters))
172	return preparer.Prepare((&http.Request{}).WithContext(ctx))
173}
174
175// ListByServerSender sends the ListByServer request. The method will close the
176// http.Response Body if it receives an error.
177func (client RestorableDroppedDatabasesClient) ListByServerSender(req *http.Request) (*http.Response, error) {
178	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
179}
180
181// ListByServerResponder handles the response to the ListByServer request. The method always
182// closes the http.Response Body.
183func (client RestorableDroppedDatabasesClient) ListByServerResponder(resp *http.Response) (result RestorableDroppedDatabaseListResult, err error) {
184	err = autorest.Respond(
185		resp,
186		azure.WithErrorUnlessStatusCode(http.StatusOK),
187		autorest.ByUnmarshallingJSON(&result),
188		autorest.ByClosing())
189	result.Response = autorest.Response{Response: resp}
190	return
191}
192