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