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	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// ResourceVaultConfigsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
29type ResourceVaultConfigsClient struct {
30	BaseClient
31}
32
33// NewResourceVaultConfigsClient creates an instance of the ResourceVaultConfigsClient client.
34func NewResourceVaultConfigsClient(subscriptionID string) ResourceVaultConfigsClient {
35	return NewResourceVaultConfigsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewResourceVaultConfigsClientWithBaseURI creates an instance of the ResourceVaultConfigsClient client using a custom
39// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
40// stack).
41func NewResourceVaultConfigsClientWithBaseURI(baseURI string, subscriptionID string) ResourceVaultConfigsClient {
42	return ResourceVaultConfigsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get fetches resource vault config.
46// Parameters:
47// vaultName - the name of the recovery services vault.
48// resourceGroupName - the name of the resource group where the recovery services vault is present.
49func (client ResourceVaultConfigsClient) Get(ctx context.Context, vaultName string, resourceGroupName string) (result ResourceVaultConfigResource, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceVaultConfigsClient.Get")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Get", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.GetSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Get", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.GetResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Get", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// GetPreparer prepares the Get request.
83func (client ResourceVaultConfigsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"resourceGroupName": autorest.Encode("path", resourceGroupName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87		"vaultName":         autorest.Encode("path", vaultName),
88	}
89
90	const APIVersion = "2019-06-15"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsGet(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupconfig/vaultconfig", pathParameters),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// GetSender sends the Get request. The method will close the
104// http.Response Body if it receives an error.
105func (client ResourceVaultConfigsClient) GetSender(req *http.Request) (*http.Response, error) {
106	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
107}
108
109// GetResponder handles the response to the Get request. The method always
110// closes the http.Response Body.
111func (client ResourceVaultConfigsClient) GetResponder(resp *http.Response) (result ResourceVaultConfigResource, err error) {
112	err = autorest.Respond(
113		resp,
114		azure.WithErrorUnlessStatusCode(http.StatusOK),
115		autorest.ByUnmarshallingJSON(&result),
116		autorest.ByClosing())
117	result.Response = autorest.Response{Response: resp}
118	return
119}
120
121// Put updates vault security config.
122// Parameters:
123// vaultName - the name of the recovery services vault.
124// resourceGroupName - the name of the resource group where the recovery services vault is present.
125// parameters - resource config request
126func (client ResourceVaultConfigsClient) Put(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceVaultConfigResource) (result ResourceVaultConfigResource, err error) {
127	if tracing.IsEnabled() {
128		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceVaultConfigsClient.Put")
129		defer func() {
130			sc := -1
131			if result.Response.Response != nil {
132				sc = result.Response.Response.StatusCode
133			}
134			tracing.EndSpan(ctx, sc, err)
135		}()
136	}
137	req, err := client.PutPreparer(ctx, vaultName, resourceGroupName, parameters)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Put", nil, "Failure preparing request")
140		return
141	}
142
143	resp, err := client.PutSender(req)
144	if err != nil {
145		result.Response = autorest.Response{Response: resp}
146		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Put", resp, "Failure sending request")
147		return
148	}
149
150	result, err = client.PutResponder(resp)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Put", resp, "Failure responding to request")
153		return
154	}
155
156	return
157}
158
159// PutPreparer prepares the Put request.
160func (client ResourceVaultConfigsClient) PutPreparer(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceVaultConfigResource) (*http.Request, error) {
161	pathParameters := map[string]interface{}{
162		"resourceGroupName": autorest.Encode("path", resourceGroupName),
163		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
164		"vaultName":         autorest.Encode("path", vaultName),
165	}
166
167	const APIVersion = "2019-06-15"
168	queryParameters := map[string]interface{}{
169		"api-version": APIVersion,
170	}
171
172	preparer := autorest.CreatePreparer(
173		autorest.AsContentType("application/json; charset=utf-8"),
174		autorest.AsPut(),
175		autorest.WithBaseURL(client.BaseURI),
176		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupconfig/vaultconfig", pathParameters),
177		autorest.WithJSON(parameters),
178		autorest.WithQueryParameters(queryParameters))
179	return preparer.Prepare((&http.Request{}).WithContext(ctx))
180}
181
182// PutSender sends the Put request. The method will close the
183// http.Response Body if it receives an error.
184func (client ResourceVaultConfigsClient) PutSender(req *http.Request) (*http.Response, error) {
185	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
186}
187
188// PutResponder handles the response to the Put request. The method always
189// closes the http.Response Body.
190func (client ResourceVaultConfigsClient) PutResponder(resp *http.Response) (result ResourceVaultConfigResource, err error) {
191	err = autorest.Respond(
192		resp,
193		azure.WithErrorUnlessStatusCode(http.StatusOK),
194		autorest.ByUnmarshallingJSON(&result),
195		autorest.ByClosing())
196	result.Response = autorest.Response{Response: resp}
197	return
198}
199
200// Update updates vault security config.
201// Parameters:
202// vaultName - the name of the recovery services vault.
203// resourceGroupName - the name of the resource group where the recovery services vault is present.
204// parameters - resource config request
205func (client ResourceVaultConfigsClient) Update(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceVaultConfigResource) (result ResourceVaultConfigResource, err error) {
206	if tracing.IsEnabled() {
207		ctx = tracing.StartSpan(ctx, fqdn+"/ResourceVaultConfigsClient.Update")
208		defer func() {
209			sc := -1
210			if result.Response.Response != nil {
211				sc = result.Response.Response.StatusCode
212			}
213			tracing.EndSpan(ctx, sc, err)
214		}()
215	}
216	req, err := client.UpdatePreparer(ctx, vaultName, resourceGroupName, parameters)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Update", nil, "Failure preparing request")
219		return
220	}
221
222	resp, err := client.UpdateSender(req)
223	if err != nil {
224		result.Response = autorest.Response{Response: resp}
225		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Update", resp, "Failure sending request")
226		return
227	}
228
229	result, err = client.UpdateResponder(resp)
230	if err != nil {
231		err = autorest.NewErrorWithError(err, "backup.ResourceVaultConfigsClient", "Update", resp, "Failure responding to request")
232		return
233	}
234
235	return
236}
237
238// UpdatePreparer prepares the Update request.
239func (client ResourceVaultConfigsClient) UpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, parameters ResourceVaultConfigResource) (*http.Request, error) {
240	pathParameters := map[string]interface{}{
241		"resourceGroupName": autorest.Encode("path", resourceGroupName),
242		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
243		"vaultName":         autorest.Encode("path", vaultName),
244	}
245
246	const APIVersion = "2019-06-15"
247	queryParameters := map[string]interface{}{
248		"api-version": APIVersion,
249	}
250
251	preparer := autorest.CreatePreparer(
252		autorest.AsContentType("application/json; charset=utf-8"),
253		autorest.AsPatch(),
254		autorest.WithBaseURL(client.BaseURI),
255		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupconfig/vaultconfig", pathParameters),
256		autorest.WithJSON(parameters),
257		autorest.WithQueryParameters(queryParameters))
258	return preparer.Prepare((&http.Request{}).WithContext(ctx))
259}
260
261// UpdateSender sends the Update request. The method will close the
262// http.Response Body if it receives an error.
263func (client ResourceVaultConfigsClient) UpdateSender(req *http.Request) (*http.Response, error) {
264	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
265}
266
267// UpdateResponder handles the response to the Update request. The method always
268// closes the http.Response Body.
269func (client ResourceVaultConfigsClient) UpdateResponder(resp *http.Response) (result ResourceVaultConfigResource, err error) {
270	err = autorest.Respond(
271		resp,
272		azure.WithErrorUnlessStatusCode(http.StatusOK),
273		autorest.ByUnmarshallingJSON(&result),
274		autorest.ByClosing())
275	result.Response = autorest.Response{Response: resp}
276	return
277}
278