1 package backup
2
3
4
5
6
7
8
9 import (
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
18 type ProtectionPoliciesClient struct {
19 BaseClient
20 }
21
22
23 func NewProtectionPoliciesClient(subscriptionID string) ProtectionPoliciesClient {
24 return NewProtectionPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewProtectionPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPoliciesClient {
31 return ProtectionPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41 func (client ProtectionPoliciesClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, policyName string, resourceProtectionPolicy ProtectionPolicyResource) (result ProtectionPolicyResource, err error) {
42 if tracing.IsEnabled() {
43 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.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, policyName, resourceProtectionPolicy)
53 if err != nil {
54 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "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.ProtectionPoliciesClient", "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.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
68 return
69 }
70
71 return
72 }
73
74
75 func (client ProtectionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, resourceProtectionPolicy ProtectionPolicyResource) (*http.Request, error) {
76 pathParameters := map[string]interface{}{
77 "policyName": autorest.Encode("path", policyName),
78 "resourceGroupName": autorest.Encode("path", resourceGroupName),
79 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
80 "vaultName": autorest.Encode("path", vaultName),
81 }
82
83 const APIVersion = "2016-06-01"
84 queryParameters := map[string]interface{}{
85 "api-version": APIVersion,
86 }
87
88 preparer := autorest.CreatePreparer(
89 autorest.AsContentType("application/json; charset=utf-8"),
90 autorest.AsPut(),
91 autorest.WithBaseURL(client.BaseURI),
92 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
93 autorest.WithJSON(resourceProtectionPolicy),
94 autorest.WithQueryParameters(queryParameters))
95 return preparer.Prepare((&http.Request{}).WithContext(ctx))
96 }
97
98
99
100 func (client ProtectionPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
101 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
102 }
103
104
105
106 func (client ProtectionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
107 err = autorest.Respond(
108 resp,
109 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
110 autorest.ByUnmarshallingJSON(&result),
111 autorest.ByClosing())
112 result.Response = autorest.Response{Response: resp}
113 return
114 }
115
116
117
118
119
120
121
122 func (client ProtectionPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result autorest.Response, err error) {
123 if tracing.IsEnabled() {
124 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
125 defer func() {
126 sc := -1
127 if result.Response != nil {
128 sc = result.Response.StatusCode
129 }
130 tracing.EndSpan(ctx, sc, err)
131 }()
132 }
133 req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, policyName)
134 if err != nil {
135 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request")
136 return
137 }
138
139 resp, err := client.DeleteSender(req)
140 if err != nil {
141 result.Response = resp
142 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure sending request")
143 return
144 }
145
146 result, err = client.DeleteResponder(resp)
147 if err != nil {
148 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure responding to request")
149 return
150 }
151
152 return
153 }
154
155
156 func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
157 pathParameters := map[string]interface{}{
158 "policyName": autorest.Encode("path", policyName),
159 "resourceGroupName": autorest.Encode("path", resourceGroupName),
160 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
161 "vaultName": autorest.Encode("path", vaultName),
162 }
163
164 const APIVersion = "2016-06-01"
165 queryParameters := map[string]interface{}{
166 "api-version": APIVersion,
167 }
168
169 preparer := autorest.CreatePreparer(
170 autorest.AsDelete(),
171 autorest.WithBaseURL(client.BaseURI),
172 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
173 autorest.WithQueryParameters(queryParameters))
174 return preparer.Prepare((&http.Request{}).WithContext(ctx))
175 }
176
177
178
179 func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
180 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
181 }
182
183
184
185 func (client ProtectionPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
186 err = autorest.Respond(
187 resp,
188 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
189 autorest.ByClosing())
190 result.Response = resp
191 return
192 }
193
194
195
196
197
198
199
200 func (client ProtectionPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPolicyResource, err error) {
201 if tracing.IsEnabled() {
202 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Get")
203 defer func() {
204 sc := -1
205 if result.Response.Response != nil {
206 sc = result.Response.Response.StatusCode
207 }
208 tracing.EndSpan(ctx, sc, err)
209 }()
210 }
211 req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName)
212 if err != nil {
213 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", nil, "Failure preparing request")
214 return
215 }
216
217 resp, err := client.GetSender(req)
218 if err != nil {
219 result.Response = autorest.Response{Response: resp}
220 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure sending request")
221 return
222 }
223
224 result, err = client.GetResponder(resp)
225 if err != nil {
226 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure responding to request")
227 return
228 }
229
230 return
231 }
232
233
234 func (client ProtectionPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
235 pathParameters := map[string]interface{}{
236 "policyName": autorest.Encode("path", policyName),
237 "resourceGroupName": autorest.Encode("path", resourceGroupName),
238 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
239 "vaultName": autorest.Encode("path", vaultName),
240 }
241
242 const APIVersion = "2016-06-01"
243 queryParameters := map[string]interface{}{
244 "api-version": APIVersion,
245 }
246
247 preparer := autorest.CreatePreparer(
248 autorest.AsGet(),
249 autorest.WithBaseURL(client.BaseURI),
250 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
251 autorest.WithQueryParameters(queryParameters))
252 return preparer.Prepare((&http.Request{}).WithContext(ctx))
253 }
254
255
256
257 func (client ProtectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
258 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
259 }
260
261
262
263 func (client ProtectionPoliciesClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
264 err = autorest.Respond(
265 resp,
266 azure.WithErrorUnlessStatusCode(http.StatusOK),
267 autorest.ByUnmarshallingJSON(&result),
268 autorest.ByClosing())
269 result.Response = autorest.Response{Response: resp}
270 return
271 }
272
273
274
275
276
277
278
279
280 func (client ProtectionPoliciesClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionPolicyResourceList, err error) {
281 if tracing.IsEnabled() {
282 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.List")
283 defer func() {
284 sc := -1
285 if result.Response.Response != nil {
286 sc = result.Response.Response.StatusCode
287 }
288 tracing.EndSpan(ctx, sc, err)
289 }()
290 }
291 req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter)
292 if err != nil {
293 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", nil, "Failure preparing request")
294 return
295 }
296
297 resp, err := client.ListSender(req)
298 if err != nil {
299 result.Response = autorest.Response{Response: resp}
300 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", resp, "Failure sending request")
301 return
302 }
303
304 result, err = client.ListResponder(resp)
305 if err != nil {
306 err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", resp, "Failure responding to request")
307 return
308 }
309
310 return
311 }
312
313
314 func (client ProtectionPoliciesClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
315 pathParameters := map[string]interface{}{
316 "resourceGroupName": autorest.Encode("path", resourceGroupName),
317 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
318 "vaultName": autorest.Encode("path", vaultName),
319 }
320
321 const APIVersion = "2016-06-01"
322 queryParameters := map[string]interface{}{
323 "api-version": APIVersion,
324 }
325 if len(filter) > 0 {
326 queryParameters["$filter"] = autorest.Encode("query", filter)
327 }
328
329 preparer := autorest.CreatePreparer(
330 autorest.AsGet(),
331 autorest.WithBaseURL(client.BaseURI),
332 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies", pathParameters),
333 autorest.WithQueryParameters(queryParameters))
334 return preparer.Prepare((&http.Request{}).WithContext(ctx))
335 }
336
337
338
339 func (client ProtectionPoliciesClient) ListSender(req *http.Request) (*http.Response, error) {
340 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
341 }
342
343
344
345 func (client ProtectionPoliciesClient) ListResponder(resp *http.Response) (result ProtectionPolicyResourceList, 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
View as plain text