1package backup
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	"net/http"
25)
26
27// OperationClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
28type OperationClient struct {
29	BaseClient
30}
31
32// NewOperationClient creates an instance of the OperationClient client.
33func NewOperationClient(subscriptionID string) OperationClient {
34	return NewOperationClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewOperationClientWithBaseURI creates an instance of the OperationClient client.
38func NewOperationClientWithBaseURI(baseURI string, subscriptionID string) OperationClient {
39	return OperationClient{NewWithBaseURI(baseURI, subscriptionID)}
40}
41
42// Validate validate operation for specified backed up item. This is a synchronous operation.
43// Parameters:
44// vaultName - the name of the recovery services vault.
45// resourceGroupName - the name of the resource group where the recovery services vault is present.
46// parameters - resource validate operation request
47func (client OperationClient) Validate(ctx context.Context, vaultName string, resourceGroupName string, parameters BasicValidateOperationRequest) (result ValidateOperationsResponse, err error) {
48	req, err := client.ValidatePreparer(ctx, vaultName, resourceGroupName, parameters)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.ValidateSender(req)
55	if err != nil {
56		result.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.ValidateResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", resp, "Failure responding to request")
64	}
65
66	return
67}
68
69// ValidatePreparer prepares the Validate request.
70func (client OperationClient) ValidatePreparer(ctx context.Context, vaultName string, resourceGroupName string, parameters BasicValidateOperationRequest) (*http.Request, error) {
71	pathParameters := map[string]interface{}{
72		"resourceGroupName": autorest.Encode("path", resourceGroupName),
73		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
74		"vaultName":         autorest.Encode("path", vaultName),
75	}
76
77	const APIVersion = "2017-07-01"
78	queryParameters := map[string]interface{}{
79		"api-version": APIVersion,
80	}
81
82	preparer := autorest.CreatePreparer(
83		autorest.AsContentType("application/json; charset=utf-8"),
84		autorest.AsPost(),
85		autorest.WithBaseURL(client.BaseURI),
86		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupValidateOperation", pathParameters),
87		autorest.WithJSON(parameters),
88		autorest.WithQueryParameters(queryParameters))
89	return preparer.Prepare((&http.Request{}).WithContext(ctx))
90}
91
92// ValidateSender sends the Validate request. The method will close the
93// http.Response Body if it receives an error.
94func (client OperationClient) ValidateSender(req *http.Request) (*http.Response, error) {
95	return autorest.SendWithSender(client, req,
96		azure.DoRetryWithRegistration(client.Client))
97}
98
99// ValidateResponder handles the response to the Validate request. The method always
100// closes the http.Response Body.
101func (client OperationClient) ValidateResponder(resp *http.Response) (result ValidateOperationsResponse, err error) {
102	err = autorest.Respond(
103		resp,
104		client.ByInspecting(),
105		azure.WithErrorUnlessStatusCode(http.StatusOK),
106		autorest.ByUnmarshallingJSON(&result),
107		autorest.ByClosing())
108	result.Response = autorest.Response{Response: resp}
109	return
110}
111