1package synapse
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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// SQLPoolRestorePointsClient is the azure Synapse Analytics Management Client
19type SQLPoolRestorePointsClient struct {
20	BaseClient
21}
22
23// NewSQLPoolRestorePointsClient creates an instance of the SQLPoolRestorePointsClient client.
24func NewSQLPoolRestorePointsClient(subscriptionID string) SQLPoolRestorePointsClient {
25	return NewSQLPoolRestorePointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewSQLPoolRestorePointsClientWithBaseURI creates an instance of the SQLPoolRestorePointsClient client using a custom
29// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
30// stack).
31func NewSQLPoolRestorePointsClientWithBaseURI(baseURI string, subscriptionID string) SQLPoolRestorePointsClient {
32	return SQLPoolRestorePointsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// Create creates a restore point for a data warehouse.
36// Parameters:
37// resourceGroupName - the name of the resource group. The name is case insensitive.
38// workspaceName - the name of the workspace
39// SQLPoolName - SQL pool name
40// parameters - the definition for creating the restore point of this Sql pool.
41func (client SQLPoolRestorePointsClient) Create(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters CreateSQLPoolRestorePointDefinition) (result SQLPoolRestorePointsCreateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolRestorePointsClient.Create")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: client.SubscriptionID,
54			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55		{TargetValue: resourceGroupName,
56			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
59		{TargetValue: parameters,
60			Constraints: []validation.Constraint{{Target: "parameters.RestorePointLabel", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
61		return result, validation.NewError("synapse.SQLPoolRestorePointsClient", "Create", err.Error())
62	}
63
64	req, err := client.CreatePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, parameters)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Create", nil, "Failure preparing request")
67		return
68	}
69
70	result, err = client.CreateSender(req)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Create", nil, "Failure sending request")
73		return
74	}
75
76	return
77}
78
79// CreatePreparer prepares the Create request.
80func (client SQLPoolRestorePointsClient) CreatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, parameters CreateSQLPoolRestorePointDefinition) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"resourceGroupName": autorest.Encode("path", resourceGroupName),
83		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
84		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
85		"workspaceName":     autorest.Encode("path", workspaceName),
86	}
87
88	const APIVersion = "2020-12-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPost(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/restorePoints", pathParameters),
98		autorest.WithJSON(parameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// CreateSender sends the Create request. The method will close the
104// http.Response Body if it receives an error.
105func (client SQLPoolRestorePointsClient) CreateSender(req *http.Request) (future SQLPoolRestorePointsCreateFuture, err error) {
106	var resp *http.Response
107	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
108	if err != nil {
109		return
110	}
111	var azf azure.Future
112	azf, err = azure.NewFutureFromResponse(resp)
113	future.FutureAPI = &azf
114	future.Result = future.result
115	return
116}
117
118// CreateResponder handles the response to the Create request. The method always
119// closes the http.Response Body.
120func (client SQLPoolRestorePointsClient) CreateResponder(resp *http.Response) (result RestorePoint, err error) {
121	err = autorest.Respond(
122		resp,
123		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129
130// Delete deletes a restore point.
131// Parameters:
132// resourceGroupName - the name of the resource group. The name is case insensitive.
133// workspaceName - the name of the workspace
134// SQLPoolName - SQL pool name
135// restorePointName - the name of the restore point.
136func (client SQLPoolRestorePointsClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, restorePointName string) (result autorest.Response, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolRestorePointsClient.Delete")
139		defer func() {
140			sc := -1
141			if result.Response != nil {
142				sc = result.Response.StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	if err := validation.Validate([]validation.Validation{
148		{TargetValue: client.SubscriptionID,
149			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
150		{TargetValue: resourceGroupName,
151			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
152				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
154		return result, validation.NewError("synapse.SQLPoolRestorePointsClient", "Delete", err.Error())
155	}
156
157	req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, restorePointName)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Delete", nil, "Failure preparing request")
160		return
161	}
162
163	resp, err := client.DeleteSender(req)
164	if err != nil {
165		result.Response = resp
166		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Delete", resp, "Failure sending request")
167		return
168	}
169
170	result, err = client.DeleteResponder(resp)
171	if err != nil {
172		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Delete", resp, "Failure responding to request")
173		return
174	}
175
176	return
177}
178
179// DeletePreparer prepares the Delete request.
180func (client SQLPoolRestorePointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, restorePointName string) (*http.Request, error) {
181	pathParameters := map[string]interface{}{
182		"resourceGroupName": autorest.Encode("path", resourceGroupName),
183		"restorePointName":  autorest.Encode("path", restorePointName),
184		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
185		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
186		"workspaceName":     autorest.Encode("path", workspaceName),
187	}
188
189	const APIVersion = "2020-12-01"
190	queryParameters := map[string]interface{}{
191		"api-version": APIVersion,
192	}
193
194	preparer := autorest.CreatePreparer(
195		autorest.AsDelete(),
196		autorest.WithBaseURL(client.BaseURI),
197		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/restorePoints/{restorePointName}", pathParameters),
198		autorest.WithQueryParameters(queryParameters))
199	return preparer.Prepare((&http.Request{}).WithContext(ctx))
200}
201
202// DeleteSender sends the Delete request. The method will close the
203// http.Response Body if it receives an error.
204func (client SQLPoolRestorePointsClient) DeleteSender(req *http.Request) (*http.Response, error) {
205	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
206}
207
208// DeleteResponder handles the response to the Delete request. The method always
209// closes the http.Response Body.
210func (client SQLPoolRestorePointsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
211	err = autorest.Respond(
212		resp,
213		azure.WithErrorUnlessStatusCode(http.StatusOK),
214		autorest.ByClosing())
215	result.Response = resp
216	return
217}
218
219// Get gets a restore point.
220// Parameters:
221// resourceGroupName - the name of the resource group. The name is case insensitive.
222// workspaceName - the name of the workspace
223// SQLPoolName - SQL pool name
224// restorePointName - the name of the restore point.
225func (client SQLPoolRestorePointsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, restorePointName string) (result RestorePoint, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolRestorePointsClient.Get")
228		defer func() {
229			sc := -1
230			if result.Response.Response != nil {
231				sc = result.Response.Response.StatusCode
232			}
233			tracing.EndSpan(ctx, sc, err)
234		}()
235	}
236	if err := validation.Validate([]validation.Validation{
237		{TargetValue: client.SubscriptionID,
238			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
239		{TargetValue: resourceGroupName,
240			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
241				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
242				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
243		return result, validation.NewError("synapse.SQLPoolRestorePointsClient", "Get", err.Error())
244	}
245
246	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, restorePointName)
247	if err != nil {
248		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Get", nil, "Failure preparing request")
249		return
250	}
251
252	resp, err := client.GetSender(req)
253	if err != nil {
254		result.Response = autorest.Response{Response: resp}
255		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Get", resp, "Failure sending request")
256		return
257	}
258
259	result, err = client.GetResponder(resp)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "Get", resp, "Failure responding to request")
262		return
263	}
264
265	return
266}
267
268// GetPreparer prepares the Get request.
269func (client SQLPoolRestorePointsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, restorePointName string) (*http.Request, error) {
270	pathParameters := map[string]interface{}{
271		"resourceGroupName": autorest.Encode("path", resourceGroupName),
272		"restorePointName":  autorest.Encode("path", restorePointName),
273		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
274		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
275		"workspaceName":     autorest.Encode("path", workspaceName),
276	}
277
278	const APIVersion = "2020-12-01"
279	queryParameters := map[string]interface{}{
280		"api-version": APIVersion,
281	}
282
283	preparer := autorest.CreatePreparer(
284		autorest.AsGet(),
285		autorest.WithBaseURL(client.BaseURI),
286		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/restorePoints/{restorePointName}", pathParameters),
287		autorest.WithQueryParameters(queryParameters))
288	return preparer.Prepare((&http.Request{}).WithContext(ctx))
289}
290
291// GetSender sends the Get request. The method will close the
292// http.Response Body if it receives an error.
293func (client SQLPoolRestorePointsClient) GetSender(req *http.Request) (*http.Response, error) {
294	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
295}
296
297// GetResponder handles the response to the Get request. The method always
298// closes the http.Response Body.
299func (client SQLPoolRestorePointsClient) GetResponder(resp *http.Response) (result RestorePoint, err error) {
300	err = autorest.Respond(
301		resp,
302		azure.WithErrorUnlessStatusCode(http.StatusOK),
303		autorest.ByUnmarshallingJSON(&result),
304		autorest.ByClosing())
305	result.Response = autorest.Response{Response: resp}
306	return
307}
308
309// List get SQL pool backup information
310// Parameters:
311// resourceGroupName - the name of the resource group. The name is case insensitive.
312// workspaceName - the name of the workspace
313// SQLPoolName - SQL pool name
314func (client SQLPoolRestorePointsClient) List(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result RestorePointListResultPage, err error) {
315	if tracing.IsEnabled() {
316		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolRestorePointsClient.List")
317		defer func() {
318			sc := -1
319			if result.rplr.Response.Response != nil {
320				sc = result.rplr.Response.Response.StatusCode
321			}
322			tracing.EndSpan(ctx, sc, err)
323		}()
324	}
325	if err := validation.Validate([]validation.Validation{
326		{TargetValue: client.SubscriptionID,
327			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
328		{TargetValue: resourceGroupName,
329			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
330				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
331				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
332		return result, validation.NewError("synapse.SQLPoolRestorePointsClient", "List", err.Error())
333	}
334
335	result.fn = client.listNextResults
336	req, err := client.ListPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName)
337	if err != nil {
338		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "List", nil, "Failure preparing request")
339		return
340	}
341
342	resp, err := client.ListSender(req)
343	if err != nil {
344		result.rplr.Response = autorest.Response{Response: resp}
345		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "List", resp, "Failure sending request")
346		return
347	}
348
349	result.rplr, err = client.ListResponder(resp)
350	if err != nil {
351		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "List", resp, "Failure responding to request")
352		return
353	}
354	if result.rplr.hasNextLink() && result.rplr.IsEmpty() {
355		err = result.NextWithContext(ctx)
356		return
357	}
358
359	return
360}
361
362// ListPreparer prepares the List request.
363func (client SQLPoolRestorePointsClient) ListPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (*http.Request, error) {
364	pathParameters := map[string]interface{}{
365		"resourceGroupName": autorest.Encode("path", resourceGroupName),
366		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
367		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
368		"workspaceName":     autorest.Encode("path", workspaceName),
369	}
370
371	const APIVersion = "2020-12-01"
372	queryParameters := map[string]interface{}{
373		"api-version": APIVersion,
374	}
375
376	preparer := autorest.CreatePreparer(
377		autorest.AsGet(),
378		autorest.WithBaseURL(client.BaseURI),
379		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/restorePoints", pathParameters),
380		autorest.WithQueryParameters(queryParameters))
381	return preparer.Prepare((&http.Request{}).WithContext(ctx))
382}
383
384// ListSender sends the List request. The method will close the
385// http.Response Body if it receives an error.
386func (client SQLPoolRestorePointsClient) ListSender(req *http.Request) (*http.Response, error) {
387	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
388}
389
390// ListResponder handles the response to the List request. The method always
391// closes the http.Response Body.
392func (client SQLPoolRestorePointsClient) ListResponder(resp *http.Response) (result RestorePointListResult, err error) {
393	err = autorest.Respond(
394		resp,
395		azure.WithErrorUnlessStatusCode(http.StatusOK),
396		autorest.ByUnmarshallingJSON(&result),
397		autorest.ByClosing())
398	result.Response = autorest.Response{Response: resp}
399	return
400}
401
402// listNextResults retrieves the next set of results, if any.
403func (client SQLPoolRestorePointsClient) listNextResults(ctx context.Context, lastResults RestorePointListResult) (result RestorePointListResult, err error) {
404	req, err := lastResults.restorePointListResultPreparer(ctx)
405	if err != nil {
406		return result, autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "listNextResults", nil, "Failure preparing next results request")
407	}
408	if req == nil {
409		return
410	}
411	resp, err := client.ListSender(req)
412	if err != nil {
413		result.Response = autorest.Response{Response: resp}
414		return result, autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "listNextResults", resp, "Failure sending next results request")
415	}
416	result, err = client.ListResponder(resp)
417	if err != nil {
418		err = autorest.NewErrorWithError(err, "synapse.SQLPoolRestorePointsClient", "listNextResults", resp, "Failure responding to next results request")
419	}
420	return
421}
422
423// ListComplete enumerates all values, automatically crossing page boundaries as required.
424func (client SQLPoolRestorePointsClient) ListComplete(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string) (result RestorePointListResultIterator, err error) {
425	if tracing.IsEnabled() {
426		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolRestorePointsClient.List")
427		defer func() {
428			sc := -1
429			if result.Response().Response.Response != nil {
430				sc = result.page.Response().Response.Response.StatusCode
431			}
432			tracing.EndSpan(ctx, sc, err)
433		}()
434	}
435	result.page, err = client.List(ctx, resourceGroupName, workspaceName, SQLPoolName)
436	return
437}
438