1package backup
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// ProtectionIntentClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
18type ProtectionIntentClient struct {
19	BaseClient
20}
21
22// NewProtectionIntentClient creates an instance of the ProtectionIntentClient client.
23func NewProtectionIntentClient(subscriptionID string) ProtectionIntentClient {
24	return NewProtectionIntentClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewProtectionIntentClientWithBaseURI creates an instance of the ProtectionIntentClient client using a custom
28// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
29// stack).
30func NewProtectionIntentClientWithBaseURI(baseURI string, subscriptionID string) ProtectionIntentClient {
31	return ProtectionIntentClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate create Intent for Enabling backup of an item. This is a synchronous operation.
35// Parameters:
36// vaultName - the name of the recovery services vault.
37// resourceGroupName - the name of the resource group where the recovery services vault is present.
38// fabricName - fabric name associated with the backup item.
39// intentObjectName - intent object name.
40// parameters - resource backed up item
41func (client ProtectionIntentClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string, parameters ProtectionIntentResource) (result ProtectionIntentResource, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName, parameters)
53	if err != nil {
54		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", nil, "Failure preparing request")
55		return
56	}
57
58	resp, err := client.CreateOrUpdateSender(req)
59	if err != nil {
60		result.Response = autorest.Response{Response: resp}
61		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", resp, "Failure sending request")
62		return
63	}
64
65	result, err = client.CreateOrUpdateResponder(resp)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "CreateOrUpdate", resp, "Failure responding to request")
68		return
69	}
70
71	return
72}
73
74// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
75func (client ProtectionIntentClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string, parameters ProtectionIntentResource) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"fabricName":        autorest.Encode("path", fabricName),
78		"intentObjectName":  autorest.Encode("path", intentObjectName),
79		"resourceGroupName": autorest.Encode("path", resourceGroupName),
80		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
81		"vaultName":         autorest.Encode("path", vaultName),
82	}
83
84	const APIVersion = "2017-07-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsContentType("application/json; charset=utf-8"),
91		autorest.AsPut(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
94		autorest.WithJSON(parameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
100// http.Response Body if it receives an error.
101func (client ProtectionIntentClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103}
104
105// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
106// closes the http.Response Body.
107func (client ProtectionIntentClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionIntentResource, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116
117// Delete used to remove intent from an item
118// Parameters:
119// vaultName - the name of the recovery services vault.
120// resourceGroupName - the name of the resource group where the recovery services vault is present.
121// fabricName - fabric name associated with the intent.
122// intentObjectName - intent to be deleted.
123func (client ProtectionIntentClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (result autorest.Response, err error) {
124	if tracing.IsEnabled() {
125		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Delete")
126		defer func() {
127			sc := -1
128			if result.Response != nil {
129				sc = result.Response.StatusCode
130			}
131			tracing.EndSpan(ctx, sc, err)
132		}()
133	}
134	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", nil, "Failure preparing request")
137		return
138	}
139
140	resp, err := client.DeleteSender(req)
141	if err != nil {
142		result.Response = resp
143		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", resp, "Failure sending request")
144		return
145	}
146
147	result, err = client.DeleteResponder(resp)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Delete", resp, "Failure responding to request")
150		return
151	}
152
153	return
154}
155
156// DeletePreparer prepares the Delete request.
157func (client ProtectionIntentClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (*http.Request, error) {
158	pathParameters := map[string]interface{}{
159		"fabricName":        autorest.Encode("path", fabricName),
160		"intentObjectName":  autorest.Encode("path", intentObjectName),
161		"resourceGroupName": autorest.Encode("path", resourceGroupName),
162		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
163		"vaultName":         autorest.Encode("path", vaultName),
164	}
165
166	const APIVersion = "2017-07-01"
167	queryParameters := map[string]interface{}{
168		"api-version": APIVersion,
169	}
170
171	preparer := autorest.CreatePreparer(
172		autorest.AsDelete(),
173		autorest.WithBaseURL(client.BaseURI),
174		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// DeleteSender sends the Delete request. The method will close the
180// http.Response Body if it receives an error.
181func (client ProtectionIntentClient) DeleteSender(req *http.Request) (*http.Response, error) {
182	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
183}
184
185// DeleteResponder handles the response to the Delete request. The method always
186// closes the http.Response Body.
187func (client ProtectionIntentClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
188	err = autorest.Respond(
189		resp,
190		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
191		autorest.ByClosing())
192	result.Response = resp
193	return
194}
195
196// Get provides the details of the protection intent up item. This is an asynchronous operation. To know the status of
197// the operation,
198// call the GetItemOperationResult API.
199// Parameters:
200// vaultName - the name of the recovery services vault.
201// resourceGroupName - the name of the resource group where the recovery services vault is present.
202// fabricName - fabric name associated with the backed up item.
203// intentObjectName - backed up item name whose details are to be fetched.
204func (client ProtectionIntentClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (result ProtectionIntentResource, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Get")
207		defer func() {
208			sc := -1
209			if result.Response.Response != nil {
210				sc = result.Response.Response.StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, intentObjectName)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", nil, "Failure preparing request")
218		return
219	}
220
221	resp, err := client.GetSender(req)
222	if err != nil {
223		result.Response = autorest.Response{Response: resp}
224		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", resp, "Failure sending request")
225		return
226	}
227
228	result, err = client.GetResponder(resp)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Get", resp, "Failure responding to request")
231		return
232	}
233
234	return
235}
236
237// GetPreparer prepares the Get request.
238func (client ProtectionIntentClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, intentObjectName string) (*http.Request, error) {
239	pathParameters := map[string]interface{}{
240		"fabricName":        autorest.Encode("path", fabricName),
241		"intentObjectName":  autorest.Encode("path", intentObjectName),
242		"resourceGroupName": autorest.Encode("path", resourceGroupName),
243		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
244		"vaultName":         autorest.Encode("path", vaultName),
245	}
246
247	const APIVersion = "2017-07-01"
248	queryParameters := map[string]interface{}{
249		"api-version": APIVersion,
250	}
251
252	preparer := autorest.CreatePreparer(
253		autorest.AsGet(),
254		autorest.WithBaseURL(client.BaseURI),
255		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/backupProtectionIntent/{intentObjectName}", pathParameters),
256		autorest.WithQueryParameters(queryParameters))
257	return preparer.Prepare((&http.Request{}).WithContext(ctx))
258}
259
260// GetSender sends the Get request. The method will close the
261// http.Response Body if it receives an error.
262func (client ProtectionIntentClient) GetSender(req *http.Request) (*http.Response, error) {
263	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
264}
265
266// GetResponder handles the response to the Get request. The method always
267// closes the http.Response Body.
268func (client ProtectionIntentClient) GetResponder(resp *http.Response) (result ProtectionIntentResource, err error) {
269	err = autorest.Respond(
270		resp,
271		azure.WithErrorUnlessStatusCode(http.StatusOK),
272		autorest.ByUnmarshallingJSON(&result),
273		autorest.ByClosing())
274	result.Response = autorest.Response{Response: resp}
275	return
276}
277
278// Validate sends the validate request.
279// Parameters:
280// azureRegion - azure region to hit Api
281// parameters - enable backup validation request on Virtual Machine
282func (client ProtectionIntentClient) Validate(ctx context.Context, azureRegion string, parameters PreValidateEnableBackupRequest) (result PreValidateEnableBackupResponse, err error) {
283	if tracing.IsEnabled() {
284		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentClient.Validate")
285		defer func() {
286			sc := -1
287			if result.Response.Response != nil {
288				sc = result.Response.Response.StatusCode
289			}
290			tracing.EndSpan(ctx, sc, err)
291		}()
292	}
293	req, err := client.ValidatePreparer(ctx, azureRegion, parameters)
294	if err != nil {
295		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", nil, "Failure preparing request")
296		return
297	}
298
299	resp, err := client.ValidateSender(req)
300	if err != nil {
301		result.Response = autorest.Response{Response: resp}
302		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", resp, "Failure sending request")
303		return
304	}
305
306	result, err = client.ValidateResponder(resp)
307	if err != nil {
308		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentClient", "Validate", resp, "Failure responding to request")
309		return
310	}
311
312	return
313}
314
315// ValidatePreparer prepares the Validate request.
316func (client ProtectionIntentClient) ValidatePreparer(ctx context.Context, azureRegion string, parameters PreValidateEnableBackupRequest) (*http.Request, error) {
317	pathParameters := map[string]interface{}{
318		"azureRegion":    autorest.Encode("path", azureRegion),
319		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
320	}
321
322	const APIVersion = "2017-07-01"
323	queryParameters := map[string]interface{}{
324		"api-version": APIVersion,
325	}
326
327	preparer := autorest.CreatePreparer(
328		autorest.AsContentType("application/json; charset=utf-8"),
329		autorest.AsPost(),
330		autorest.WithBaseURL(client.BaseURI),
331		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{azureRegion}/backupPreValidateProtection", pathParameters),
332		autorest.WithJSON(parameters),
333		autorest.WithQueryParameters(queryParameters))
334	return preparer.Prepare((&http.Request{}).WithContext(ctx))
335}
336
337// ValidateSender sends the Validate request. The method will close the
338// http.Response Body if it receives an error.
339func (client ProtectionIntentClient) ValidateSender(req *http.Request) (*http.Response, error) {
340	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
341}
342
343// ValidateResponder handles the response to the Validate request. The method always
344// closes the http.Response Body.
345func (client ProtectionIntentClient) ValidateResponder(resp *http.Response) (result PreValidateEnableBackupResponse, err error) {
346	err = autorest.Respond(
347		resp,
348		azure.WithErrorUnlessStatusCode(http.StatusOK),
349		autorest.ByUnmarshallingJSON(&result),
350		autorest.ByClosing())
351	result.Response = autorest.Response{Response: resp}
352	return
353}
354